the_tracker 1.2.3

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,16 @@
1
+ *.rbc
2
+ *.sassc
3
+ .sass-cache
4
+ capybara-*.html
5
+ .rspec
6
+ /.bundle
7
+ /vendor/bundle
8
+ /log/*
9
+ /tmp/*
10
+ /db/*.sqlite3
11
+ /public/system/*
12
+ /coverage/
13
+ /spec/tmp/*
14
+ **.orig
15
+ rerun.txt
16
+ pickle-email-*.html
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in the_tracker.gemspec
4
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,138 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ the_tracker (1.2.3)
5
+ rails
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ actionmailer (3.2.13)
11
+ actionpack (= 3.2.13)
12
+ mail (~> 2.5.3)
13
+ actionpack (3.2.13)
14
+ activemodel (= 3.2.13)
15
+ activesupport (= 3.2.13)
16
+ builder (~> 3.0.0)
17
+ erubis (~> 2.7.0)
18
+ journey (~> 1.0.4)
19
+ rack (~> 1.4.5)
20
+ rack-cache (~> 1.2)
21
+ rack-test (~> 0.6.1)
22
+ sprockets (~> 2.2.1)
23
+ activemodel (3.2.13)
24
+ activesupport (= 3.2.13)
25
+ builder (~> 3.0.0)
26
+ activerecord (3.2.13)
27
+ activemodel (= 3.2.13)
28
+ activesupport (= 3.2.13)
29
+ arel (~> 3.0.2)
30
+ tzinfo (~> 0.3.29)
31
+ activeresource (3.2.13)
32
+ activemodel (= 3.2.13)
33
+ activesupport (= 3.2.13)
34
+ activesupport (3.2.13)
35
+ i18n (= 0.6.1)
36
+ multi_json (~> 1.0)
37
+ arel (3.0.3)
38
+ builder (3.0.4)
39
+ coderay (1.0.9)
40
+ diff-lcs (1.2.4)
41
+ erubis (2.7.0)
42
+ ffi (1.8.1)
43
+ formatador (0.2.4)
44
+ guard (1.8.0)
45
+ formatador (>= 0.2.4)
46
+ listen (>= 1.0.0)
47
+ lumberjack (>= 1.0.2)
48
+ pry (>= 0.9.10)
49
+ thor (>= 0.14.6)
50
+ guard-rspec (2.5.4)
51
+ guard (>= 1.1)
52
+ rspec (~> 2.11)
53
+ hike (1.2.3)
54
+ i18n (0.6.1)
55
+ journey (1.0.4)
56
+ json (1.8.0)
57
+ listen (1.0.3)
58
+ rb-fsevent (>= 0.9.3)
59
+ rb-inotify (>= 0.9)
60
+ rb-kqueue (>= 0.2)
61
+ lumberjack (1.0.3)
62
+ mail (2.5.4)
63
+ mime-types (~> 1.16)
64
+ treetop (~> 1.4.8)
65
+ method_source (0.8.1)
66
+ mime-types (1.25.1)
67
+ multi_json (1.7.6)
68
+ polyglot (0.3.4)
69
+ pry (0.9.12.1)
70
+ coderay (~> 1.0.5)
71
+ method_source (~> 0.8)
72
+ slop (~> 3.4)
73
+ rack (1.4.5)
74
+ rack-cache (1.2)
75
+ rack (>= 0.4)
76
+ rack-ssl (1.3.3)
77
+ rack
78
+ rack-test (0.6.2)
79
+ rack (>= 1.0)
80
+ rails (3.2.13)
81
+ actionmailer (= 3.2.13)
82
+ actionpack (= 3.2.13)
83
+ activerecord (= 3.2.13)
84
+ activeresource (= 3.2.13)
85
+ activesupport (= 3.2.13)
86
+ bundler (~> 1.0)
87
+ railties (= 3.2.13)
88
+ railties (3.2.13)
89
+ actionpack (= 3.2.13)
90
+ activesupport (= 3.2.13)
91
+ rack-ssl (~> 1.3.2)
92
+ rake (>= 0.8.7)
93
+ rdoc (~> 3.4)
94
+ thor (>= 0.14.6, < 2.0)
95
+ rake (10.0.4)
96
+ rb-fsevent (0.9.3)
97
+ rb-inotify (0.9.0)
98
+ ffi (>= 0.5.0)
99
+ rb-kqueue (0.2.0)
100
+ ffi (>= 0.5.0)
101
+ rdoc (3.12.2)
102
+ json (~> 1.4)
103
+ rspec (2.13.0)
104
+ rspec-core (~> 2.13.0)
105
+ rspec-expectations (~> 2.13.0)
106
+ rspec-mocks (~> 2.13.0)
107
+ rspec-core (2.13.1)
108
+ rspec-expectations (2.13.0)
109
+ diff-lcs (>= 1.1.3, < 2.0)
110
+ rspec-mocks (2.13.1)
111
+ rspec-rails (2.13.2)
112
+ actionpack (>= 3.0)
113
+ activesupport (>= 3.0)
114
+ railties (>= 3.0)
115
+ rspec-core (~> 2.13.0)
116
+ rspec-expectations (~> 2.13.0)
117
+ rspec-mocks (~> 2.13.0)
118
+ slop (3.4.4)
119
+ sprockets (2.2.2)
120
+ hike (~> 1.2)
121
+ multi_json (~> 1.0)
122
+ rack (~> 1.0)
123
+ tilt (~> 1.1, != 1.3.0)
124
+ thor (0.18.1)
125
+ tilt (1.4.1)
126
+ treetop (1.4.15)
127
+ polyglot
128
+ polyglot (>= 0.3.1)
129
+ tzinfo (0.3.39)
130
+
131
+ PLATFORMS
132
+ ruby
133
+
134
+ DEPENDENCIES
135
+ guard-rspec
136
+ pry
137
+ rspec-rails
138
+ the_tracker!
data/Guardfile ADDED
@@ -0,0 +1,8 @@
1
+ guard 'rspec', :version => 2 do
2
+ watch(%r{^spec/.+_spec\.rb$})
3
+ watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
4
+ watch('spec/spec_helper.rb') { "spec" }
5
+
6
+ # Rails example
7
+ watch(%r{^spec/support/(.+)\.rb$}) { "spec" }
8
+ end
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Jorge Alvarez
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,272 @@
1
+ # TheTracker
2
+
3
+ A Gem to help you add tracker components to your application. Instead of having to write javascript code to add this trackers you can use plain pure ruby.
4
+
5
+ Currently this components are supported:
6
+
7
+ Google Analytics
8
+
9
+ Google Universal Analytics
10
+
11
+ Google Tag Mangaer
12
+
13
+ Uservoice
14
+
15
+ Ad Form
16
+
17
+ Google Ad Services
18
+
19
+ Kenshoo Conversion Pixel
20
+
21
+ Relevant Traffic Conversion Pixel
22
+
23
+ ## Installation
24
+
25
+ Add this line to your application's Gemfile:
26
+
27
+ gem 'the_tracker'
28
+
29
+ And then execute:
30
+
31
+ $ bundle
32
+
33
+ Or install it yourself as:
34
+
35
+ $ gem install the_tracker
36
+
37
+ ## Usage
38
+
39
+ Create a file in config/initializers/tracker.rb
40
+
41
+ Add all the trackers you need
42
+
43
+ TheTracker::Tracker.config do |tmf|
44
+ tmf.add TheTracker::Trackers::Uservoice.new('YOUR_KEY', {:forum_id => 123, :tab_label => 'Say Hi!'})
45
+ tmf.add TheTracker::Trackers::GAnalytics.new(:id => 'UA-1234123-99')
46
+ end
47
+
48
+ In your views add
49
+
50
+ <header>
51
+ <%= header_tracking_code.html_safe %>
52
+ </header>
53
+
54
+ If the tracker needs to add code into the body:
55
+
56
+ <body>
57
+ <%= body_top_tracking_code.html_safe %>
58
+
59
+ ... your page html ...
60
+
61
+ <%= body_bottom_tracking_code.html_safe %>
62
+ </body>
63
+
64
+ And that's all, the tracking code will be added automatically
65
+
66
+ Sometimes you only want to track certain pages:
67
+
68
+ For instance, this example will not show the Google Analytics code if `some_condition` evaluates to true
69
+
70
+ <header>
71
+ <% TheTracker::Tracker.instance.trackers[:ganalytics].active = some_condition %>
72
+ <%= header_tracking_code.html_safe %>
73
+ </header>
74
+
75
+ You can add a tracking code on a single page:
76
+
77
+ TheTracker::Tracker.config do |tmf|
78
+ tmf.add_once TheTracker::Trackers::Uservoice.new('YOUR_KEY', {:forum_id => 123, :tab_label => 'Say Hi and disappear!'})
79
+ end
80
+
81
+
82
+ ## Available Trackers
83
+
84
+ ### AdFrom
85
+
86
+ TheTracker::Trackers::AdForm.new(:pm => 123, :id => 444)
87
+
88
+ ### Uservoice
89
+
90
+ TheTracker::Trackers::Uservoice.new(
91
+ 'THE_KEY',
92
+ {
93
+ mode: 'full',
94
+ primary_color: '#ff0000',
95
+ link_color: '#007dbf',
96
+ default_mode: 'support',
97
+ forum_id: 111,
98
+ tab_label: 'Say Hi!',
99
+ tab_color: '#cc0000',
100
+ tab_position: 'middle-left',
101
+ tab_inverted: true
102
+ }
103
+ )
104
+
105
+ ### Google Analytics
106
+
107
+ #### Regular tracking code
108
+ TheTracker::Trackers::GAnalytics.new(:id => 'UA-111111-11')
109
+
110
+ You can optionally set domain name and allow linker
111
+
112
+ TheTracker::Trackers::GAnalytics.new(:id => 'UA-111111-11', :domain_name => 'mydomain.com', :allow_linker => true)
113
+
114
+ #### Add an e-commerce transaction
115
+ TheTracker::Tracker.instance.trackers[:ganalytics].add_transaction(tid=0, store='', total=0, tax=0, shipping=0, city='', state='', country='')
116
+
117
+ Yo don't need to specify an id. If id is zero the transaction id will be the current timestamp
118
+
119
+ To add items to the transaction:
120
+
121
+ TheTracker::Tracker.instance.trackers[:ganalytics].add_transaction_item(sku='', product='', category='', price=0, quantity=0)
122
+
123
+ #### Add custom vars
124
+
125
+ TheTracker::Tracker.instance.trackers[:ganalytics].add_custom_var(index, name, value, scope)
126
+
127
+ #### Track an event
128
+
129
+ TheTracker::Tracker.instance.trackers[:ganalytics].track_event(category, action, label='', value=0, non_interactive=false)
130
+
131
+ ### Google Universal Analytics
132
+
133
+ #### Regular tracking code
134
+ TheTracker::Trackers::GUniversal.new(:id => 'UA-111111-11')
135
+
136
+ You can optionally set an array of domains and allow linker
137
+
138
+ TheTracker::Trackers::GUniversal.new(:id => 'UA-111111-11', :domain_name => ['onedomain.com', 'anotherdomain.com'], :allow_linker => true)
139
+
140
+ #### Track multiple analytics accounts
141
+
142
+ All tracking codes are namespaced to avoid conflicts with other existant Universal analytics accounts or to allow you to use more than one account.
143
+
144
+ If you create an account without specifiying a name the default name will be 'guniversal':
145
+ TheTracker::Trackers::GUniversal.new(:id => 'UA-111111-11')
146
+
147
+ the code that will be injected on the page will be like this:
148
+ ga('guniversal.send', 'pageview');
149
+
150
+ If you want to add another universal analytics account you should define a name when creating it:
151
+ TheTracker::Trackers::GUniversal.new(id: 'UA-111111-11', name: 'second_account')
152
+
153
+ and the code generated will be like this:
154
+ ga('second_account.send', 'pageview');
155
+
156
+ To add information to a specific account just use the appropiate tracker
157
+ TheTracker::Tracker.instance.trackers[:second_account].add_custom_var(:dimension, 1, 'I am second to none')
158
+
159
+ #### Add an e-commerce transaction
160
+ TheTracker::Tracker.instance.trackers[:guniversal].add_transaction(tid=0, store='', total=0, tax=0, shipping=0)
161
+
162
+ Yo don't need to specify an id. If id is zero the transaction id will be the current timestamp
163
+
164
+ To add items to the transaction:
165
+
166
+ TheTracker::Tracker.instance.trackers[:guniversal].add_transaction_item(sku='', product='', category='', price=0, quantity=0)
167
+
168
+ #### Add custom dimensions and metrics
169
+
170
+ TheTracker::Tracker.instance.trackers[:guniversal].add_custom_var(:dimension, index, value)
171
+ TheTracker::Tracker.instance.trackers[:guniversal].add_custom_var(:metric, index, value)
172
+
173
+ #### Add User Id
174
+
175
+ TheTracker::Tracker.instance.trackers[:guniversal].add_user_id(id)
176
+
177
+ ### Google Tag Manager
178
+
179
+ TheTracker::Trackers::Gtm.new(:gtmid => 'GTM-111111')
180
+
181
+ To add [dataLayer variables to GTM](https://developers.google.com/tag-manager/devguide)
182
+
183
+ TheTracker::Tracker.instance.trackers[:gtm].add_data_layer(name, value)
184
+
185
+ ### Google AdServices
186
+
187
+ TheTracker::Trackers::GAdServices.new(
188
+ id: 'UA-111111-11'
189
+ language: 'en',
190
+ format: '1',
191
+ color: 'ffffff',
192
+ label: 'qwerty',
193
+ value: '0'
194
+ )
195
+
196
+ ### Kenshoo Conversion Pixel
197
+
198
+ TheTracker::Trackers::Kenshoo.new(
199
+ token: '999'
200
+ type: 'conv',
201
+ val: '0',
202
+ orderId: '88988',
203
+ promoCode: 'easter',
204
+ valueCurrency: 'EUR',
205
+ trackEvent: '1234'
206
+ )
207
+
208
+ ### Relevant Traffic Conversion Pixel
209
+
210
+ TheTracker::Trackers::Relevant.new(
211
+ token: '4329847'
212
+ seg: '289347',
213
+ orderId: '88AB988'
214
+ )
215
+
216
+ ## Author
217
+
218
+ Created by Jorge Alvarez
219
+
220
+ @jorgealvarez
221
+
222
+ http://www.alvareznavarro.es
223
+
224
+ I would like to thanks to the [Sage One](http://www.sageone.es) team for their support in the development of this gem
225
+
226
+ ## Contributing
227
+
228
+ 1. Fork it
229
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
230
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
231
+ 4. Push to the branch (`git push origin my-new-feature`)
232
+ 5. Create new Pull Request
233
+
234
+ ## License
235
+
236
+ The Tracker is released under the [MIT License](http://www.opensource.org/licenses/MIT).
237
+
238
+ ## Log
239
+
240
+ ### Version 1.2.3
241
+
242
+ Fixed bug with namespace
243
+
244
+ ### Version 1.2.2
245
+
246
+ Support for more than one Universal analytics account
247
+
248
+ ### Version 1.2.1
249
+
250
+ Support for userId in Universal analytics
251
+
252
+ ### Version 1.2.0
253
+
254
+ Added Universal analytics
255
+
256
+ ### Version 1.1.2
257
+
258
+ Added Relevant Traffic conversion pixel support
259
+
260
+ ### Version 1.0.0
261
+
262
+ Everything is stable so time to bump version to 1.0.0
263
+
264
+ Added Kenshoo conversion pixel support
265
+
266
+ ### Version 0.5.0
267
+
268
+ Now you can add a tracker that will be displayed only once and removed from subsequent requests.
269
+
270
+ ### Version 0.4.6
271
+
272
+ Fixed bug that keeped information about transactions on each page load. Now transaction information is displayed only once.
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,9 @@
1
+ require 'the_tracker/view_helpers'
2
+
3
+ module TheTracker
4
+ class Railtie < Rails::Railtie
5
+ initializer "the_tracker.view_helpers" do |app|
6
+ ActionView::Base.send :include, ViewHelpers
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,64 @@
1
+ require 'singleton'
2
+
3
+ module TheTracker
4
+ # Common tracker behaviour
5
+ class Tracker
6
+ include Singleton
7
+
8
+ def self.config
9
+ yield self.instance if block_given?
10
+ end
11
+
12
+ # register a new tracker
13
+ def add(tracker)
14
+ regular_trackers[tracker.name] = tracker
15
+ end
16
+
17
+ # register a new one time only tracker
18
+ def add_once(tracker)
19
+ one_time_trackers[tracker.name] = tracker
20
+ end
21
+
22
+ # registered trackers
23
+ def trackers
24
+ one_time_trackers.empty? ? regular_trackers : regular_trackers.merge(one_time_trackers)
25
+ end
26
+
27
+ # Return header content for all registered trackers
28
+ def header
29
+ show_trackers_for(:header)
30
+ end
31
+
32
+ # Return body top content for all registered trackers
33
+ def body_top
34
+ show_trackers_for(:body_top)
35
+ end
36
+
37
+ # Return body bottom content for all registered trackers
38
+ def body_bottom
39
+ trk_result = show_trackers_for(:body_bottom)
40
+ remove_one_time_trackers
41
+ return trk_result
42
+ end
43
+
44
+ private
45
+
46
+ def show_trackers_for(position)
47
+ trackers.map do | id, tracker |
48
+ tracker.send(position)
49
+ end.compact.join("\n")
50
+ end
51
+
52
+ def regular_trackers
53
+ @regular_trackers ||= {}
54
+ end
55
+
56
+ def one_time_trackers
57
+ @one_time_trackers ||= {}
58
+ end
59
+
60
+ def remove_one_time_trackers
61
+ @one_time_trackers = {}
62
+ end
63
+ end
64
+ end
@@ -0,0 +1,37 @@
1
+ module TheTracker
2
+ module Trackers
3
+ class AdForm < Base
4
+
5
+ # AdForm info pm and id
6
+ def initialize(options)
7
+ @pm = options[:pm]
8
+ @id = options[:id]
9
+ super()
10
+ end
11
+
12
+ def name
13
+ :adform
14
+ end
15
+
16
+ def header
17
+ return if !active
18
+ <<-EOF
19
+ <!-- Adform Tracking Code BEGIN -->
20
+ <script type="text/javascript">
21
+ var _adftrack = {
22
+ pm: #{@pm},
23
+ id: #{@id}
24
+ };
25
+ (function(){var s=document.createElement('script');s.type='text/javascript';s.async=true;s.src='https://track.adform.net/serving/scripts/trackpoint/async/';var x = document.getElementsByTagName('script')[0];x.parentNode.insertBefore(s, x);})();
26
+ </script>
27
+ <noscript>
28
+ <p style="margin:0;padding:0;border:0;">
29
+ <img src="https://track.adform.net/Serving/TrackPoint/?pm=#{@pm}&amp;lid=#{@id}" width="1" height="1" alt="" />
30
+ </p>
31
+ </noscript>
32
+ <!-- Adform Tracking Code END -->
33
+ EOF
34
+ end
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,32 @@
1
+ module TheTracker
2
+ module Trackers
3
+ # Base class for trackers
4
+ class Base
5
+ attr_accessor :active
6
+
7
+ def initialize
8
+ @active = true
9
+ end
10
+
11
+ # public name
12
+ def name
13
+ raise NotImplementedError
14
+ end
15
+
16
+ # code that should appear on the header section
17
+ def header
18
+ []
19
+ end
20
+
21
+ # code that should appear on the body top section
22
+ def body_top
23
+ []
24
+ end
25
+
26
+ # code that should appear on the body bottom section
27
+ def body_bottom
28
+ []
29
+ end
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,46 @@
1
+ module TheTracker
2
+ module Trackers
3
+ class GAdServices < Base
4
+
5
+ # GAdService info id, language, format, color, label and value
6
+ def initialize(options)
7
+ @id = options[:id]
8
+ @language = options[:language]
9
+ @format = options[:format]
10
+ @color = options[:color]
11
+ @label = options[:label]
12
+ @value = options[:value]
13
+ super()
14
+ end
15
+
16
+ def name
17
+ :gadservices
18
+ end
19
+
20
+ def body_bottom
21
+ return if !active
22
+ <<-EOF
23
+ <!-- Google Code for Cliente Potencial Conversion Page BEGIN -->
24
+ <script type="text/javascript">
25
+ /* <![CDATA[ */
26
+ var google_conversion_id = #{@id};
27
+ var google_conversion_language = \"#{@language}\";
28
+ var google_conversion_format = \"#{@format}\";
29
+ var google_conversion_color = \"#{@color}\";
30
+ var google_conversion_label = \"#{@label}\";
31
+ var google_conversion_value = #{@value};
32
+ /* ]]> */
33
+ </script>
34
+ <script type=\"text/javascript\" src=\"//www.googleadservices.com/pagead/conversion.js\">
35
+ </script>
36
+ <noscript>
37
+ <div style=\"display:inline;\">
38
+ <img height=\"1\" width=\"1\" style=\"border-style:none;\" alt=\"\" src=\"//www.googleadservices.com/pagead/conversion/#{@id}/?value=#{@value}&label=#{@label}&guid=ON&script=0\"/>
39
+ </div>
40
+ </noscript>
41
+ <!-- Google Code for Cliente Potencial Conversion Page END -->
42
+ EOF
43
+ end
44
+ end
45
+ end
46
+ end