trackable-click 0.0.6

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: db63ab65ae91f2e397c995ead12090c8ef22a10a
4
+ data.tar.gz: 41ea76fb8895490a38eb2416504e12f04015f60f
5
+ SHA512:
6
+ metadata.gz: d3b7bc8454912ecc04e54963390e32e67c9ce1f98cb4730b87f1b9565922a6067373235e866d380eb0b7d3eb3acadf54cb9fb6c99b2298c464ce79b8e669e374
7
+ data.tar.gz: 351cd89dfe0ff5a7f1ed444717f621db88a5bcb4e4bb43113d6111635a6dc5df09024adbc08d19fb82e8010b512ce528eea5ae9d925df94fcd983a4304af02c8
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright 2014 YOURNAME
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.rdoc ADDED
@@ -0,0 +1,57 @@
1
+ # TrackableClick
2
+
3
+ TrackableClick provides submit and link view helpers in ROR that can be tracked via Google analytic event, Google analytic e-commerce transaction, and Facebook pixel.
4
+ It is implemented using unobtrusive Javascript and integrates via Railties.
5
+
6
+ ## Installation
7
+
8
+ Add this line to your application's Gemfile:
9
+
10
+ gem 'trackable-click'
11
+
12
+ And then execute:
13
+
14
+ $ bundle
15
+
16
+ Or install it yourself as:
17
+
18
+ $ gem install trackable-click
19
+
20
+ Add trackable click to your javascript manifest:
21
+
22
+ #= require trackable-click
23
+
24
+ Add GA snippit to your layout file (exmaple in HAML):
25
+
26
+ - should_perform_tracking do
27
+ :javascript
28
+ (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
29
+ (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
30
+ m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
31
+ })(window,document,'script','//www.google-analytics.com/analytics.js','ga');
32
+
33
+ ga('create', 'UA-4JJHHJL9-1', {'cookieDomain':'none'});
34
+ ga('send', 'pageview');
35
+
36
+ Enable trackable click via rails config:
37
+
38
+ Application.configure do
39
+ config.tracking_clicks = true
40
+ end
41
+
42
+ ## Usage
43
+
44
+ 1. submit example GA e-commerce
45
+ = trackable_submit 'Place Order', google_commerce: {id:'1', affiliation: 'test product', revenue: '10.00', shipping:'0.00', tax:'0.00'}
46
+ 2. submit example GA Event
47
+ = trackable_submit 'Place Order', google_event: {action: 'click', label: 'User Placed Order'}, fp_pixel: {id: '6014085521316', value: '10.00', currency: 'USD'}
48
+ 3. submit example Facebook Pixel
49
+ = trackable_submit 'Place Order', fp_pixel: {id: '6014085521316', value: '10.00', currency: 'USD'}
50
+
51
+ ## Contributing
52
+
53
+ 1. Fork it
54
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
55
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
56
+ 4. Push to the branch (`git push origin my-new-feature`)
57
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,27 @@
1
+ #!/usr/bin/env rake
2
+ begin
3
+ require 'bundler/setup'
4
+ rescue LoadError
5
+ puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
6
+ end
7
+ begin
8
+ require 'rdoc/task'
9
+ rescue LoadError
10
+ require 'rdoc/rdoc'
11
+ require 'rake/rdoctask'
12
+ RDoc::Task = Rake::RDocTask
13
+ end
14
+
15
+ RDoc::Task.new(:rdoc) do |rdoc|
16
+ rdoc.rdoc_dir = 'rdoc'
17
+ rdoc.title = 'TrackableClick'
18
+ rdoc.options << '--line-numbers'
19
+ rdoc.rdoc_files.include('README.rdoc')
20
+ rdoc.rdoc_files.include('lib/**/*.rb')
21
+ end
22
+
23
+
24
+
25
+
26
+ Bundler::GemHelper.install_tasks
27
+
@@ -0,0 +1,78 @@
1
+ $(document).ready(function() {
2
+ function trackableClickOnlyIf(element, prefix) {
3
+ var trackable = ($(element).data(prefix + '-only-if') &&
4
+ eval($(element).data(prefix + '-only-if'))) ||
5
+ !$(element).data(prefix + '-only-if');
6
+ return trackable;
7
+ }
8
+
9
+ function trackableClickEvalAttr(element, dataAttr) {
10
+ var attr = '';
11
+
12
+ try {
13
+ attr = eval($(element).data(dataAttr));
14
+ } catch (e) {
15
+ attr = $(element).data(dataAttr);
16
+ }
17
+
18
+ return attr;
19
+ }
20
+
21
+ $('body').delegate( ".trackable-click", "click", function() {
22
+ if($(this).data('tc-fb-pixel-id') &&
23
+ $(this).data('tc-fb-pixel-value') &&
24
+ $(this).data('tc-fb-pixel-currency')) {
25
+
26
+ if(trackableClickOnlyIf(this, 'tc-fb-pixel')) {
27
+ window.fb_param = {}; // must be global by adding `window.`
28
+ fb_param.pixel_id = $(this).data('tc-fb-pixel-id');
29
+ fb_param.value = trackableClickEvalAttr(this, 'tc-fb-pixel-value');
30
+ fb_param.currency = trackableClickEvalAttr(this,'tc-fb-pixel-currency');
31
+
32
+ (function(){
33
+ var fpw = document.createElement('script'); fpw.async = true; fpw.src = '//connect.facebook.net/en_US/fp.js';
34
+ var ref = document.getElementsByTagName('script')[0];
35
+ ref.parentNode.insertBefore(fpw, ref);
36
+ })();
37
+ }
38
+ }
39
+
40
+ if($(this).data('tc-google-event-action') &&
41
+ $(this).data('tc-google-event-label')){
42
+ var action = trackableClickEvalAttr(this,'tc-google-event-action');
43
+ var label = trackableClickEvalAttr(this,'tc-google-event-label');
44
+
45
+ if(trackableClickOnlyIf(this, 'tc-google-event')) {
46
+ if($(this).data('tc-google-button-event-value')) {
47
+ ga('send', 'event', 'button', action , label, $(this).data('tc-google-button-event-value'));
48
+ } else {
49
+ ga('send', 'event', 'button', action , label);
50
+ }
51
+ }
52
+ }
53
+
54
+ if($(this).data('tc-google-commerce-id') &&
55
+ $(this).data('tc-google-commerce-affiliation') &&
56
+ $(this).data('tc-google-commerce-revenue') &&
57
+ $(this).data('tc-google-commerce-shipping') &&
58
+ $(this).data('tc-google-commerce-tax')){
59
+
60
+ var id = trackableClickEvalAttr(this,'tc-google-commerce-id');
61
+ var affiliation = trackableClickEvalAttr(this,'tc-google-commerce-affiliation');
62
+ var revenue = trackableClickEvalAttr(this,'tc-google-commerce-revenue');
63
+ var shipping = trackableClickEvalAttr(this,'tc-google-commerce-shipping');
64
+ var tax = trackableClickEvalAttr(this,'tc-google-commerce-tax');
65
+
66
+ if(trackableClickOnlyIf(this, 'tc-google-commerce')) {
67
+ ga('ecommerce:addTransaction', {
68
+ 'id': id,
69
+ 'affiliation': affiliation,
70
+ 'revenue': revenue,
71
+ 'shipping': shipping,
72
+ 'tax': tax
73
+ });
74
+ ga('ecommerce:send');
75
+ }
76
+ }
77
+ });
78
+ });
@@ -0,0 +1,4 @@
1
+ # desc "Explaining what the task does"
2
+ # task :trackable-click do
3
+ # # Task goes here
4
+ # end
@@ -0,0 +1,5 @@
1
+ require "trackable-click/view_helpers"
2
+ require "trackable-click/engine"
3
+
4
+ module TrackableClick
5
+ end
@@ -0,0 +1,14 @@
1
+ module TrackableClick
2
+ class Engine < ::Rails::Engine
3
+ isolate_namespace TrackableClick
4
+
5
+ config.generators do |g|
6
+ g.test_framework :rspec
7
+ g.integration_tool :rspec
8
+ end
9
+
10
+ initializer "trackable-click.view_helpers" do |app|
11
+ ::ActionView::Base.send :include, ::TrackableClick::ViewHelpers
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,3 @@
1
+ module TrackableClick
2
+ VERSION = "0.0.6"
3
+ end
@@ -0,0 +1,93 @@
1
+ module TrackableClick
2
+ module ViewHelpers
3
+ def tracking_clicks?
4
+ Rails.configuration.tracking_clicks
5
+ end
6
+
7
+ def should_perform_tracking
8
+ if block_given? && tracking_clicks?
9
+ yield
10
+ end
11
+ end
12
+
13
+ def trackable_submit(value, options = {})
14
+ expand_options!(options) if tracking_clicks?
15
+ submit_tag(value, options)
16
+ end
17
+
18
+ def trackable_link_to(name = nil, options = nil, html_options = nil, &block)
19
+ expand_options!(options) if tracking_clicks?
20
+ link_to(name, options, html_options, block)
21
+ end
22
+
23
+ private
24
+
25
+ def expand_options!(options)
26
+ options[:class] = make_trackable_class_from_options(options)
27
+ fp_pixel_data_attrs = make_fp_pixel_data_attrs_from_options!(options)
28
+ google_event_attrs = make_google_event_data_attrs_from_options!(options)
29
+ google_commerce_attrs = make_google_commerce_data_attrs_from_options!(options)
30
+
31
+ options[:data] ||= {}
32
+ options[:data].merge!(fp_pixel_data_attrs)
33
+ options[:data].merge!(google_event_attrs)
34
+ options[:data].merge!(google_commerce_attrs)
35
+ end
36
+
37
+ def make_trackable_class_from_options(options)
38
+ css_class = options[:class] || ""
39
+ css_class << " trackable-click"
40
+ css_class
41
+ end
42
+
43
+ def make_fp_pixel_data_attrs_from_options!(options)
44
+ data_attrs = {}
45
+ fp_pixel_options = options[:fp_pixel]
46
+
47
+ unless fp_pixel_options.nil?
48
+ data_attrs[:tc_fb_pixel_only_if] = fp_pixel_options[:only_if]
49
+ data_attrs[:tc_fb_pixel_id] = fp_pixel_options[:id]
50
+ data_attrs[:tc_fb_pixel_value] = fp_pixel_options[:value]
51
+ data_attrs[:tc_fb_pixel_currency] = fp_pixel_options[:currency]
52
+ end
53
+
54
+ options.delete(:fp_pixel)
55
+ data_attrs
56
+ end
57
+
58
+ def make_google_event_data_attrs_from_options!(options)
59
+ data_attrs = {}
60
+ google_event_options = options[:google_event]
61
+
62
+ unless google_event_options.nil?
63
+ data_attrs[:tc_google_event_only_if] = google_event_options[:only_if]
64
+ data_attrs[:tc_google_event_action] = google_event_options[:action]
65
+ data_attrs[:tc_google_event_label] = google_event_options[:label]
66
+
67
+ if google_event_options[:value]
68
+ data_attrs[:google_event_value] = google_event_options[:value]
69
+ end
70
+ end
71
+
72
+ options.delete(:google_event)
73
+ data_attrs
74
+ end
75
+
76
+ def make_google_commerce_data_attrs_from_options!(options)
77
+ data_attrs = {}
78
+ google_commerce_options = options[:google_commerce]
79
+
80
+ unless google_commerce_options.nil?
81
+ data_attrs[:tc_google_commerce_only_if] = google_commerce_options[:only_if]
82
+ data_attrs[:tc_google_commerce_id] = google_commerce_options[:id]
83
+ data_attrs[:tc_google_commerce_affiliation] =google_commerce_options[:affiliation]
84
+ data_attrs[:tc_google_commerce_revenue] = google_commerce_options[:revenue]
85
+ data_attrs[:tc_google_commerce_shipping] = google_commerce_options[:shipping]
86
+ data_attrs[:tc_google_commerce_tax] = google_commerce_options[:tax]
87
+ end
88
+
89
+ options.delete(:google_commerce)
90
+ data_attrs
91
+ end
92
+ end
93
+ end
metadata ADDED
@@ -0,0 +1,109 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: trackable-click
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.6
5
+ platform: ruby
6
+ authors:
7
+ - Christopher Parratto
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-03-12 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rails
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 3.2.16
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 3.2.16
27
+ - !ruby/object:Gem::Dependency
28
+ name: jquery-rails
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec-rails
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: mocha
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ description: Currently only provides a form helper for submit tags.
70
+ email:
71
+ - cparratto@gmail.com
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - MIT-LICENSE
77
+ - README.rdoc
78
+ - Rakefile
79
+ - app/assets/javascripts/trackable-click.js
80
+ - lib/tasks/trackable-click_tasks.rake
81
+ - lib/trackable-click.rb
82
+ - lib/trackable-click/engine.rb
83
+ - lib/trackable-click/version.rb
84
+ - lib/trackable-click/view_helpers.rb
85
+ homepage: https://www.github.com/cparratto/trackable-click
86
+ licenses: []
87
+ metadata: {}
88
+ post_install_message:
89
+ rdoc_options: []
90
+ require_paths:
91
+ - lib
92
+ required_ruby_version: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ required_rubygems_version: !ruby/object:Gem::Requirement
98
+ requirements:
99
+ - - ">="
100
+ - !ruby/object:Gem::Version
101
+ version: '0'
102
+ requirements: []
103
+ rubyforge_project:
104
+ rubygems_version: 2.2.2
105
+ signing_key:
106
+ specification_version: 4
107
+ summary: Trackable click allows you to attach fb pixels and google events as clickable
108
+ items in rails
109
+ test_files: []