rack-ga-track 0.5.0 → 0.6.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 6a00ae792fc16422781a7c668a09218ef5d6ad5b
4
- data.tar.gz: e64ab768ee4ff175ac7daf41e3f46af312361b29
3
+ metadata.gz: 2488735974ca3424b3539254fec3b519e24a0d08
4
+ data.tar.gz: 4477f298dacc26bc2473f4576cc930f35a7f8191
5
5
  SHA512:
6
- metadata.gz: a8de9721f2e5e6dc70b0ba3d30e7f9a1200f95d616abc2c371bdc62cf2a5fca39e4427aa7943231599b7de394f62c3dc94c8722f60b8e6d0147926c57882bcdf
7
- data.tar.gz: 1adf57f727aeabae19a92a29cc41e613be5f8713b2503e34d226121f80fc5c81cf85b6682a8a2bdf50baad19197d8bda238ee2ec108b0c6da85d403f4c8296cc
6
+ metadata.gz: 073a66941beec9d8339481b0a208f69636249a38af0b106cb532a4a2d536b5fd0a6d0b918afd04ab320fcf4482eaf139d78d56bb2c8576ee5e1e3428413c3a70
7
+ data.tar.gz: f8ee3d175f2864b957f7efeaadedb0190a7d16d2a74fe3f2b2134f8cb40cf32fa3e3d5bdbd0b115df5ac6144f8176b8b7abde507903fbcbb0313df2653795ff6
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.5.0
1
+ 0.6.0
data/lib/rack-ga-track.rb CHANGED
@@ -26,20 +26,22 @@ module Rack
26
26
 
27
27
  def set_params(req)
28
28
  if req.params['utm_source']
29
- return params_hash(req.params)
29
+ return params_hash(req)
30
30
  elsif req.cookies['ga_track'] && !req.cookies['ga_track'].empty?
31
31
  return JSON.parse(req.cookies['ga_track'])
32
32
  end
33
33
  false
34
34
  end
35
35
 
36
- def params_hash(params)
36
+ def params_hash(req)
37
37
  {
38
- source: params['utm_source'],
39
- medium: params['utm_medium'],
40
- term: params['utm_term'],
41
- content: params['utm_content'],
42
- campaign: params['utm_campaign'],
38
+ source: req.params['utm_source'],
39
+ medium: req.params['utm_medium'],
40
+ term: req.params['utm_term'],
41
+ content: req.params['utm_content'],
42
+ campaign: req.params['utm_campaign'],
43
+ referer: req.referer,
44
+ landing_page: req.path,
43
45
  time: Time.now.to_i
44
46
  }
45
47
  end
@@ -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.0 ruby lib
5
+ # stub: rack-ga-track 0.6.0 ruby lib
6
6
 
7
7
  Gem::Specification.new do |s|
8
8
  s.name = "rack-ga-track"
9
- s.version = "0.5.0"
9
+ s.version = "0.6.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-23"
14
+ s.date = "2014-08-21"
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 = [
@@ -15,6 +15,8 @@ describe "RackGaTrack" do
15
15
  last_request.env['ga_track.content'].must_equal nil
16
16
  last_request.env['ga_track.medium'].must_equal nil
17
17
  last_request.env['ga_track.time'].must_equal nil
18
+ last_request.env['ga_track.referer'].must_equal nil
19
+ last_request.env['ga_track.landing_page'].must_equal nil
18
20
  end
19
21
 
20
22
  it "should set ga_track env vars from params" do
@@ -24,13 +26,15 @@ describe "RackGaTrack" do
24
26
  utm_campaign: 'email',
25
27
  utm_medium: 'test_medium' }
26
28
 
27
- get '/', params
29
+ get '/testing', params, 'HTTP_REFERER' => "http://www.foo.com"
28
30
  end
29
31
 
30
32
  last_request.env['ga_track.source'].must_equal "testing"
31
33
  last_request.env['ga_track.campaign'].must_equal "email"
32
34
  last_request.env['ga_track.medium'].must_equal "test_medium"
33
35
  last_request.env['ga_track.time'].must_equal @time.to_i
36
+ last_request.env['ga_track.referer'].must_equal 'http://www.foo.com'
37
+ last_request.env['ga_track.landing_page'].must_equal '/testing'
34
38
  end
35
39
 
36
40
  it "should save GA Campaign params in a cookie" do
@@ -40,7 +44,7 @@ describe "RackGaTrack" do
40
44
  utm_campaign: 'email',
41
45
  utm_medium: 'test_medium' }
42
46
 
43
- get '/', params
47
+ get '/testing', params, 'HTTP_REFERER' => "http://www.foo.com"
44
48
  end
45
49
 
46
50
  cookie_params = JSON.parse(rack_mock_session.cookie_jar["ga_track"])
@@ -49,16 +53,22 @@ describe "RackGaTrack" do
49
53
  cookie_params["campaign"].must_equal "email"
50
54
  cookie_params["medium"].must_equal "test_medium"
51
55
  cookie_params["time"].must_equal @time.to_i
56
+ cookie_params["referer"].must_equal 'http://www.foo.com'
57
+ cookie_params["landing_page"].must_equal '/testing'
52
58
  end
53
59
 
54
60
  describe "when cookie exists" do
55
61
  before :each do
56
62
  @time = Time.now
57
63
  clear_cookies
58
- @params = { source: 'testing',
59
- campaign: 'email',
60
- medium: 'test_medium',
61
- time: @time.to_i }
64
+ @params = {
65
+ source: 'testing',
66
+ campaign: 'email',
67
+ medium: 'test_medium',
68
+ time: @time.to_i,
69
+ referer: 'http://www.foo.com',
70
+ landing_page: '/testing'
71
+ }
62
72
  rack_mock_session.cookie_jar["ga_track"] = @params.to_json
63
73
  end
64
74
 
@@ -71,6 +81,8 @@ describe "RackGaTrack" do
71
81
  last_request.env['ga_track.campaign'].must_equal "email"
72
82
  last_request.env['ga_track.medium'].must_equal "test_medium"
73
83
  last_request.env['ga_track.time'].must_equal @time.to_i
84
+ last_request.env['ga_track.referer'].must_equal 'http://www.foo.com'
85
+ last_request.env['ga_track.landing_page'].must_equal '/testing'
74
86
  end
75
87
 
76
88
  it 'should not update existing cookie' do
@@ -82,6 +94,8 @@ describe "RackGaTrack" do
82
94
  last_request.env['ga_track.campaign'].must_equal "email"
83
95
  last_request.env['ga_track.medium'].must_equal "test_medium"
84
96
  last_request.env['ga_track.time'].must_equal @time.to_i
97
+ last_request.env['ga_track.referer'].must_equal 'http://www.foo.com'
98
+ last_request.env['ga_track.landing_page'].must_equal '/testing'
85
99
 
86
100
  rack_mock_session.cookie_jar["ga_track"].must_equal JSON.generate(@params)
87
101
  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.5.0
4
+ version: 0.6.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-23 00:00:00.000000000 Z
11
+ date: 2014-08-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rack