rack-ga-track 0.1.0 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/VERSION +1 -1
- data/lib/rack-ga-track.rb +20 -16
- data/rack-ga-track.gemspec +3 -3
- data/spec/rack_ga_track_spec.rb +22 -2
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3b0ed4ea180cfa25dd248781cc7459bcae7c345f
|
4
|
+
data.tar.gz: 1d889d05d11b45f55423cc3960fab27b1e11710a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 187b3ecd7893659001e2e300c32faf75e275a890adb6742dcb905c3e5763da09b1e1d30c6a7c727b1107bce0602e3d80a9cbac990a817016b8922bacd828e0f0
|
7
|
+
data.tar.gz: b522ab8d2657afd04126800ea4307508904dccf948bc5da7c2e9f0e7facd1866b4a86fc74d50d1c545aedef88f0181a877ce5d2be2886f513810431dbc1032d0
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.2.0
|
data/lib/rack-ga-track.rb
CHANGED
@@ -9,26 +9,30 @@ module Rack
|
|
9
9
|
|
10
10
|
def call(env)
|
11
11
|
req = Rack::Request.new(env)
|
12
|
-
status, headers, body = @app.call(env)
|
13
12
|
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
args = params_hash(req.cookies)
|
18
|
-
elsif req.params['utm_source']
|
19
|
-
args = params_hash(req.params)
|
20
|
-
create_cookies(headers, args)
|
13
|
+
params = set_params(req)
|
14
|
+
if params
|
15
|
+
create_env_vars(env, params)
|
21
16
|
end
|
22
17
|
|
23
|
-
|
24
|
-
|
18
|
+
response = @app.call(env)
|
19
|
+
if params && req.params['utm_source']
|
20
|
+
create_cookies(response[1], params)
|
25
21
|
end
|
26
|
-
|
27
|
-
[status, headers, body]
|
22
|
+
response
|
28
23
|
end
|
29
24
|
|
30
25
|
private
|
31
26
|
|
27
|
+
def set_params(req)
|
28
|
+
if req.params['utm_source']
|
29
|
+
return params_hash(req.params)
|
30
|
+
elsif req.cookies['utm_source']
|
31
|
+
return params_hash(req.cookies)
|
32
|
+
end
|
33
|
+
false
|
34
|
+
end
|
35
|
+
|
32
36
|
def params_hash(params)
|
33
37
|
params['utm_time'] ||= Time.now
|
34
38
|
|
@@ -42,9 +46,9 @@ module Rack
|
|
42
46
|
}
|
43
47
|
end
|
44
48
|
|
45
|
-
def create_cookies(headers,
|
49
|
+
def create_cookies(headers, params)
|
46
50
|
expires = Time.now + @cookie_ttl
|
47
|
-
|
51
|
+
params.each do |key, value|
|
48
52
|
cookie_hash = {:value => value, :expires => expires}
|
49
53
|
cookie_hash[:domain] = @cookie_domain if @cookie_domain
|
50
54
|
cookie_key = 'utm_' + key.to_s
|
@@ -52,8 +56,8 @@ module Rack
|
|
52
56
|
end
|
53
57
|
end
|
54
58
|
|
55
|
-
def create_env_vars(env,
|
56
|
-
|
59
|
+
def create_env_vars(env, params)
|
60
|
+
params.each do |key, value|
|
57
61
|
env["ga_track.#{key.to_s}"] = value
|
58
62
|
end
|
59
63
|
end
|
data/rack-ga-track.gemspec
CHANGED
@@ -2,16 +2,16 @@
|
|
2
2
|
# DO NOT EDIT THIS FILE DIRECTLY
|
3
3
|
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
4
4
|
# -*- encoding: utf-8 -*-
|
5
|
-
# stub: rack-ga-track 0.
|
5
|
+
# stub: rack-ga-track 0.2.0 ruby lib
|
6
6
|
|
7
7
|
Gem::Specification.new do |s|
|
8
8
|
s.name = "rack-ga-track"
|
9
|
-
s.version = "0.
|
9
|
+
s.version = "0.2.0"
|
10
10
|
|
11
11
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
12
12
|
s.require_paths = ["lib"]
|
13
13
|
s.authors = ["Daniel Nolan"]
|
14
|
-
s.date = "2014-07-
|
14
|
+
s.date = "2014-07-17"
|
15
15
|
s.description = "If the user visits via a Google Analytics Campaign link,\n this middleware will track utm_source, utm_content, utm_term, utm_medium, utm_campaign, and time."
|
16
16
|
s.email = "dnolan@t1dexchange.org"
|
17
17
|
s.extra_rdoc_files = [
|
data/spec/rack_ga_track_spec.rb
CHANGED
@@ -19,7 +19,11 @@ describe "RackGaTrack" do
|
|
19
19
|
it "should set ga_track env vars from params" do
|
20
20
|
Timecop.freeze do
|
21
21
|
@time = Time.now
|
22
|
-
|
22
|
+
params = { utm_source: 'testing',
|
23
|
+
utm_campaign: 'email',
|
24
|
+
utm_content: 'test_content' }
|
25
|
+
|
26
|
+
get '/', params
|
23
27
|
end
|
24
28
|
|
25
29
|
last_request.env['ga_track.source'].must_equal "testing"
|
@@ -31,7 +35,11 @@ describe "RackGaTrack" do
|
|
31
35
|
it "should save GA Campaign params in a cookie" do
|
32
36
|
Timecop.freeze do
|
33
37
|
@time = Time.now
|
34
|
-
|
38
|
+
params = { utm_source: 'testing',
|
39
|
+
utm_campaign: 'email',
|
40
|
+
utm_content: 'test_content' }
|
41
|
+
|
42
|
+
get '/', params
|
35
43
|
end
|
36
44
|
|
37
45
|
rack_mock_session.cookie_jar["utm_source"].must_equal "testing"
|
@@ -76,5 +84,17 @@ describe "RackGaTrack" do
|
|
76
84
|
rack_mock_session.cookie_jar["utm_content"].must_equal "test_content"
|
77
85
|
rack_mock_session.cookie_jar["utm_time"].must_equal "#{@time.to_i}"
|
78
86
|
end
|
87
|
+
|
88
|
+
it 'should update existing cookie if utm_source is present in url params' do
|
89
|
+
Timecop.freeze(60*60*24) do
|
90
|
+
params = { utm_source: 'cool_source',
|
91
|
+
utm_campaign: 'email',
|
92
|
+
utm_content: 'test_content' }
|
93
|
+
|
94
|
+
get '/', params
|
95
|
+
end
|
96
|
+
|
97
|
+
rack_mock_session.cookie_jar["utm_source"].must_equal "cool_source"
|
98
|
+
end
|
79
99
|
end
|
80
100
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rack-ga-track
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Daniel Nolan
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-07-
|
11
|
+
date: 2014-07-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rack
|