the_tracker 1.2.3

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.
@@ -0,0 +1,98 @@
1
+ require 'spec_helper'
2
+
3
+ describe TheTracker::Trackers::GAnalytics do
4
+ subject { described_class.new(:id => 'UA-111-11') }
5
+
6
+ describe :initialize do
7
+ before :each do
8
+ @ga = described_class.new(
9
+ id: 111,
10
+ domain_name: 'test.com',
11
+ allow_linker: true
12
+ )
13
+ end
14
+
15
+ it 'should return domain name content' do
16
+ @ga.header.should include("_gaq.push(['_setDomainName', 'test.com']);")
17
+ end
18
+
19
+ it 'should return allow linker name content' do
20
+ @ga.header.should include("_gaq.push(['_setAllowLinker', true]);")
21
+ end
22
+ end
23
+
24
+ describe :methods do
25
+ describe :add_custom_var do
26
+ it 'should add a custom var' do
27
+ subject.add_custom_var(1, 'user', '111', 1)
28
+ subject.header.should include("_gaq.push(['_setCustomVar', 1, 'user', '111', '1']);")
29
+ end
30
+ end
31
+
32
+ describe :track_event do
33
+ it 'should add the event tag' do
34
+ subject.track_event('Category', 'Action', "label\'s", '99', true).should == "_gaq.push(['_trackEvent', 'Category', 'Action', 'label\'s', 99, true]);"
35
+ end
36
+ end
37
+
38
+ describe :transactions do
39
+ before :each do
40
+ subject.add_transaction('1234', 'Acme Clothing', '11.99', '1.29', '5', 'San Jose', 'California', 'USA')
41
+ subject.add_transaction_item('DD44', 'T-Shirt', 'Green Medium', '11.99', '1')
42
+ end
43
+
44
+ describe :add_transaction do
45
+ it 'should add the transaction tag' do
46
+ subject.header.should include("_gaq.push(['_addTrans'")
47
+ end
48
+
49
+ it 'should add the transaction tag but only once' do
50
+ subject.header
51
+ subject.header.should_not include("_gaq.push(['_addTrans'")
52
+ end
53
+ end
54
+
55
+ describe :add_transaction_item do
56
+ it 'should add the transaction_item tag' do
57
+ subject.header.should include("_gaq.push(['_addItem'")
58
+ end
59
+ end
60
+
61
+ it 'should add the tracker of the transaction' do
62
+ subject.header.should include("_gaq.push(['_trackTrans']);")
63
+ end
64
+
65
+ context 'if transaction id is nil' do
66
+ before :each do
67
+ @default = described_class.new(:id => 'UA-111-11')
68
+ end
69
+
70
+ it 'should add default timestamp as transaction id when zero' do
71
+ @default.add_transaction(0, 'Acme Clothing', '11.99', '1.29', '5', 'San Jose', 'California', 'USA')
72
+ @default.header.should =~ /_gaq.push\(\['_addTrans', '\d{2,}'/
73
+ end
74
+
75
+ it 'should add default timestamp as transaction id when nil' do
76
+ @default.add_transaction(nil, 'Acme Clothing', '11.99', '1.29', '5', 'San Jose', 'California', 'USA')
77
+ @default.header.should =~ /_gaq.push\(\['_addTrans', '\d{2,}'/
78
+ end
79
+ end
80
+ end
81
+
82
+ describe :header do
83
+ it 'should return analytics content' do
84
+ subject.header.should include("_gaq.push(['_trackPageview']);")
85
+ end
86
+
87
+ it 'should include ua information' do
88
+ subject.header.should include("_gaq.push(['_setAccount', 'UA-111-11']);")
89
+ end
90
+ end
91
+
92
+ describe :name do
93
+ it 'should return ganalytics' do
94
+ subject.name.should == :ganalytics
95
+ end
96
+ end
97
+ end
98
+ end
@@ -0,0 +1,141 @@
1
+ require 'spec_helper'
2
+
3
+ describe TheTracker::Trackers::GUniversal do
4
+ subject { described_class.new(:id => 'UA-111-11') }
5
+
6
+ describe :initialize do
7
+ before :each do
8
+ @ga = described_class.new(
9
+ id: 'UA-111-22',
10
+ domain_name: ['source.com', 'destination.com'],
11
+ allow_linker: true
12
+ )
13
+ end
14
+
15
+ it 'should return allow linker name content' do
16
+ @ga.header.should include("ga('create', 'UA-111-22', 'auto', {'name': 'guniversal', 'allowLinker': true});")
17
+ end
18
+
19
+ it 'should return require linker' do
20
+ @ga.header.should include("ga('guniversal.require', 'linker');")
21
+ end
22
+
23
+ it 'should include all domains in autolink' do
24
+ @ga.header.should include("ga('linker:autoLink', [\"source.com\", \"destination.com\"]);")
25
+ end
26
+ end
27
+
28
+ it 'should return User Id' do
29
+ subject.add_custom_var(:metric, 1, 999.99)
30
+ end
31
+
32
+ describe :methods do
33
+ describe :add_custom_dimension do
34
+ it 'should add a custom dimension' do
35
+ subject.add_custom_var(:dimension, 1, 'user')
36
+ subject.header.should include("ga('guniversal.set', 'dimension1', 'user');")
37
+ end
38
+ end
39
+
40
+ describe :add_custom_metric do
41
+ it 'should add a custom metric' do
42
+ subject.add_custom_var(:metric, 1, 999.99)
43
+ subject.header.should include("ga('guniversal.set', 'metric1', '999.99');")
44
+ end
45
+ end
46
+
47
+ describe :transactions do
48
+ before :each do
49
+ subject.add_transaction('1234', 'Acme Clothing', '11.99', '1.29', '5')
50
+ subject.add_transaction_item('DD44', 'T-Shirt', 'Green Medium', '11.99', '1')
51
+ end
52
+
53
+ it 'should add transaction library' do
54
+ subject.header.should include("ga('guniversal.require', 'ecommerce', 'ecommerce.js');")
55
+ end
56
+
57
+ describe :add_transaction do
58
+ it 'should add the transaction tag' do
59
+ subject.header.should include("ga('guniversal.ecommerce:addTransaction'")
60
+ end
61
+
62
+ it 'should add the transaction tag but only once' do
63
+ subject.header
64
+ subject.header.should_not include("ga('guniversal.ecommerce:addTransaction'")
65
+ end
66
+ end
67
+
68
+ describe :add_transaction_item do
69
+ it 'should add the transaction_item tag' do
70
+ subject.header.should include("ga('guniversal.ecommerce:addItem', {")
71
+ end
72
+ end
73
+
74
+ it 'should add the tracker of the transaction' do
75
+ subject.header.should include("ga('guniversal.ecommerce:send');")
76
+ end
77
+
78
+ context 'if transaction id is nil' do
79
+ before :each do
80
+ @default = described_class.new(:id => 'UA-111-11', :name => :second_tracker)
81
+ end
82
+
83
+ it 'should add default timestamp as transaction id when zero' do
84
+ @default.add_transaction(0, 'Acme Clothing', '11.99', '1.29', '5')
85
+ @default.header.should =~ /ga\('second_tracker.ecommerce:addTransaction', { 'id': '\d{2,}'/
86
+ end
87
+
88
+ it 'should add default timestamp as transaction id when nil' do
89
+ @default.add_transaction(nil, 'Acme Clothing', '11.99', '1.29', '5')
90
+ @default.header.should =~ /ga\('second_tracker.ecommerce:addTransaction', { 'id': '\d{2,}'/
91
+ end
92
+ end
93
+
94
+ describe :add_user_id do
95
+ it 'should return User Id' do
96
+ subject.add_user_id('abcde123456')
97
+ subject.header.should include("ga('create', 'UA-111-11', 'auto', {'name': 'guniversal', 'userId': 'abcde123456'});")
98
+ end
99
+ end
100
+ end
101
+
102
+ describe :header do
103
+ it 'should return analytics content' do
104
+ subject.header.should include("ga('guniversal.send', 'pageview');")
105
+ end
106
+
107
+ it 'should include UA information' do
108
+ subject.header.should include("ga('create', 'UA-111-11', 'auto', {'name': 'guniversal'});")
109
+ end
110
+
111
+ it 'should not include linker information by default' do
112
+ subject.header.should_not include("ga('create', 'UA-111-11', 'auto', {'allowLinker': true});")
113
+ end
114
+ end
115
+
116
+ describe :name do
117
+ context 'when name is set in options' do
118
+ before :each do
119
+ @universal = described_class.new(id: 'UA-111-11', name: 'test_track')
120
+ end
121
+ it 'should name the instance as name' do
122
+ @universal.name.should == 'test_track'
123
+ end
124
+
125
+ it 'should track pageviews namespaced' do
126
+ @universal.header.should include("ga('test_track.send', 'pageview');")
127
+ end
128
+ end
129
+
130
+ context 'when no name is provided' do
131
+ it 'should return ganalytics' do
132
+ subject.name.should == :guniversal
133
+ end
134
+
135
+ it 'should track pageviews namespaced' do
136
+ subject.header.should include("ga('guniversal.send', 'pageview');")
137
+ end
138
+ end
139
+ end
140
+ end
141
+ end
@@ -0,0 +1,31 @@
1
+ require 'spec_helper'
2
+
3
+ describe TheTracker::Trackers::Gtm do
4
+ subject { described_class.new(:gtmid => 'GTM-XXXXX') }
5
+ describe :methods do
6
+ describe :body_top do
7
+ it 'should return gtm content' do
8
+ subject.body_top.should include('<iframe src="//www.googletagmanager.com/ns.html?id=')
9
+ end
10
+
11
+ it 'returns nothing if tracker not active' do
12
+ subject.active = false
13
+ subject.body_top.should == nil
14
+ end
15
+ end
16
+
17
+ describe :add_data_layer do
18
+ before :each do
19
+ subject.add_data_layer('client_id', 123)
20
+ end
21
+
22
+ it 'adds a new value to data layer info' do
23
+ subject.body_top.should include("'client_id': '123'")
24
+ end
25
+ it 'adds a new value to data layer info stack' do
26
+ subject.add_data_layer('status', 'big_boss')
27
+ subject.body_top.should include("'client_id': '123','status': 'big_boss'")
28
+ end
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,27 @@
1
+ require 'spec_helper'
2
+
3
+ describe TheTracker::Trackers::Kenshoo do
4
+ subject { described_class.new(:token => 12345678, :type => 'en', :val => '2', :orderId => "ffffff", :promoCode => 'SomeThingReallyCool', :valueCurrency => 'EUR', trackEvent: '6969') }
5
+ describe :methods do
6
+ describe :body_bottom do
7
+ it 'should return ad_form content' do
8
+ subject.body_top.should include('://6969.xg4ken.com/media/getpx.php')
9
+ end
10
+
11
+ it 'should include id, langage, format, color, label and value information' do
12
+ subject.body_top.should include("params[0]='id=12345678'");
13
+ subject.body_top.should include("params[1]='type=en'");
14
+ subject.body_top.should include("params[2]='val=2'");
15
+ subject.body_top.should include("params[3]='orderId=ffffff'");
16
+ subject.body_top.should include("params[4]='promoCode=SomeThingReallyCool'");
17
+ subject.body_top.should include("params[5]='valueCurrency=EUR'");
18
+ subject.body_top.should include("k_trackevent(params,'6969'");
19
+ end
20
+
21
+ it 'returns nothing if tracker not active' do
22
+ subject.active = false
23
+ subject.body_top.should == nil
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,23 @@
1
+ require 'spec_helper'
2
+
3
+ describe TheTracker::Trackers::Relevant do
4
+ subject { described_class.new(:token => 12345678, :seg => '9876543', :orderId => '2') }
5
+ describe :methods do
6
+ describe :body_bottom do
7
+ it 'should return ad_form content' do
8
+ subject.body_bottom.should include('://ib.adnxs.com/px')
9
+ end
10
+
11
+ it 'should include id, seg and orderID' do
12
+ subject.body_bottom.should include("id=12345678");
13
+ subject.body_bottom.should include("seg=9876543");
14
+ subject.body_bottom.should include("orderId=2");
15
+ end
16
+
17
+ it 'returns nothing if tracker not active' do
18
+ subject.active = false
19
+ subject.body_bottom.should == nil
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,29 @@
1
+ require 'spec_helper'
2
+
3
+ describe TheTracker::Trackers::Uservoice do
4
+ subject { described_class.new('abcd', {:forum_id => '111', :tab_label => 'Say Hi!'}) }
5
+ describe :methods do
6
+ describe :header do
7
+ it 'should return uservoice script' do
8
+ subject.header.should include('widget.uservoice.com/abcd.js')
9
+ end
10
+ end
11
+
12
+ describe :name do
13
+ it 'should return uservoice' do
14
+ subject.name.should == :uservoice
15
+ end
16
+ end
17
+
18
+ describe :body_bottom do
19
+ it 'should return uservoice variable' do
20
+ subject.body_bottom.should include('UserVoice = window.UserVoice')
21
+ end
22
+
23
+ it 'should include forum_id and tab_label information' do
24
+ subject.body_bottom.should include('"forum_id":"111"')
25
+ subject.body_bottom.should include('"tab_label":"Say Hi!"')
26
+ end
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,51 @@
1
+ require 'spec_helper'
2
+
3
+ class GAnalitics < TheTracker::Trackers::Base
4
+ def header
5
+ 'header tracking code'
6
+ end
7
+
8
+ def body_top
9
+ 'body top tracking code'
10
+ end
11
+
12
+ def body_bottom
13
+ 'body bottom tracking code'
14
+ end
15
+
16
+ def name
17
+ :ganalytics
18
+ end
19
+ end
20
+
21
+ class ViewClass
22
+ include TheTracker::ViewHelpers
23
+ end
24
+
25
+ describe 'View Helpers' do
26
+ before :each do
27
+ TheTracker::Tracker.reset
28
+ TheTracker::Tracker.config do |tmf|
29
+ tmf.add GAnalitics.new
30
+ end
31
+ @vc = ViewClass.new
32
+ end
33
+
34
+ describe 'Header' do
35
+ it 'display header info' do
36
+ @vc.header_tracking_code.should == 'header tracking code'
37
+ end
38
+ end
39
+
40
+ describe 'Body Top' do
41
+ it 'display top info' do
42
+ @vc.body_top_tracking_code.should == 'body top tracking code'
43
+ end
44
+ end
45
+
46
+ describe 'Body Bottom' do
47
+ it 'display bottom info' do
48
+ @vc.body_bottom_tracking_code.should == 'body bottom tracking code'
49
+ end
50
+ end
51
+ end
@@ -0,0 +1,23 @@
1
+ # -*- encoding: utf-8 -*-
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'the_tracker/version'
5
+
6
+ Gem::Specification.new do |gem|
7
+ gem.name = "the_tracker"
8
+ gem.version = TheTracker::VERSION
9
+ gem.authors = ["Jorge Alvarez"]
10
+ gem.email = ["jorge@alvareznavarro.es"]
11
+ gem.description = %q{Add tracking codes to your rails app}
12
+ gem.summary = %q{Analytics, Website Optimizer, Clicktale...}
13
+ gem.homepage = ""
14
+
15
+ gem.files = `git ls-files`.split($/)
16
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
17
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
18
+ gem.require_paths = ["lib"]
19
+ gem.add_dependency "rails"
20
+ gem.add_development_dependency "rspec-rails"
21
+ gem.add_development_dependency "guard-rspec"
22
+ gem.add_development_dependency "pry"
23
+ end
metadata ADDED
@@ -0,0 +1,156 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: the_tracker
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.2.3
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Jorge Alvarez
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2014-04-08 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rails
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
30
+ - !ruby/object:Gem::Dependency
31
+ name: rspec-rails
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :development
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ - !ruby/object:Gem::Dependency
47
+ name: guard-rspec
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ - !ruby/object:Gem::Dependency
63
+ name: pry
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ! '>='
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ type: :development
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
78
+ description: Add tracking codes to your rails app
79
+ email:
80
+ - jorge@alvareznavarro.es
81
+ executables: []
82
+ extensions: []
83
+ extra_rdoc_files: []
84
+ files:
85
+ - .gitignore
86
+ - Gemfile
87
+ - Gemfile.lock
88
+ - Guardfile
89
+ - LICENSE.txt
90
+ - README.md
91
+ - Rakefile
92
+ - lib/the_tracker.rb
93
+ - lib/the_tracker/railtie.rb
94
+ - lib/the_tracker/tracker.rb
95
+ - lib/the_tracker/trackers/ad_form.rb
96
+ - lib/the_tracker/trackers/base.rb
97
+ - lib/the_tracker/trackers/g_ad_services.rb
98
+ - lib/the_tracker/trackers/g_analytics.rb
99
+ - lib/the_tracker/trackers/g_universal.rb
100
+ - lib/the_tracker/trackers/gtm.rb
101
+ - lib/the_tracker/trackers/kenshoo.rb
102
+ - lib/the_tracker/trackers/relevant.rb
103
+ - lib/the_tracker/trackers/uservoice.rb
104
+ - lib/the_tracker/version.rb
105
+ - lib/the_tracker/view_helpers.rb
106
+ - spec/spec_helper.rb
107
+ - spec/the_tracker/tracker_spec.rb
108
+ - spec/the_tracker/trackers/ad_form_spec.rb
109
+ - spec/the_tracker/trackers/base_spec.rb
110
+ - spec/the_tracker/trackers/g_ad_services_spec.rb
111
+ - spec/the_tracker/trackers/g_analytics_spec.rb
112
+ - spec/the_tracker/trackers/g_universal_spec.rb
113
+ - spec/the_tracker/trackers/gtm_spec.rb
114
+ - spec/the_tracker/trackers/kenshoo_spec.rb
115
+ - spec/the_tracker/trackers/relevant_spec.rb
116
+ - spec/the_tracker/trackers/uservoice_spec.rb
117
+ - spec/the_tracker/view_helpers_spec.rb
118
+ - the_tracker.gemspec
119
+ homepage: ''
120
+ licenses: []
121
+ post_install_message:
122
+ rdoc_options: []
123
+ require_paths:
124
+ - lib
125
+ required_ruby_version: !ruby/object:Gem::Requirement
126
+ none: false
127
+ requirements:
128
+ - - ! '>='
129
+ - !ruby/object:Gem::Version
130
+ version: '0'
131
+ required_rubygems_version: !ruby/object:Gem::Requirement
132
+ none: false
133
+ requirements:
134
+ - - ! '>='
135
+ - !ruby/object:Gem::Version
136
+ version: '0'
137
+ requirements: []
138
+ rubyforge_project:
139
+ rubygems_version: 1.8.24
140
+ signing_key:
141
+ specification_version: 3
142
+ summary: Analytics, Website Optimizer, Clicktale...
143
+ test_files:
144
+ - spec/spec_helper.rb
145
+ - spec/the_tracker/tracker_spec.rb
146
+ - spec/the_tracker/trackers/ad_form_spec.rb
147
+ - spec/the_tracker/trackers/base_spec.rb
148
+ - spec/the_tracker/trackers/g_ad_services_spec.rb
149
+ - spec/the_tracker/trackers/g_analytics_spec.rb
150
+ - spec/the_tracker/trackers/g_universal_spec.rb
151
+ - spec/the_tracker/trackers/gtm_spec.rb
152
+ - spec/the_tracker/trackers/kenshoo_spec.rb
153
+ - spec/the_tracker/trackers/relevant_spec.rb
154
+ - spec/the_tracker/trackers/uservoice_spec.rb
155
+ - spec/the_tracker/view_helpers_spec.rb
156
+ has_rdoc: