analytics-rails 0.3.3 → 0.3.4

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 2563146a9f29dfdccb49f44b3c63c9ba619574e9
4
- data.tar.gz: 871add710bc594de772fbcbcef93fde0cd526f7c
3
+ metadata.gz: 4c9c5ff2a82ba6b5ac6710f3ddc9182b16422e79
4
+ data.tar.gz: aff5d90f8e35aae72b24adfdbeb7ddecdecb8d48
5
5
  SHA512:
6
- metadata.gz: 22fa215df53421ea806854ff8ca92f0224a336a41130907589483a114dae995851f396dda5d7a51d1c1fdba0bf6324df8278c31e9f4ac53f622d7e34da4bb929
7
- data.tar.gz: 7b86f73cac06c5e65f101c130fbd5641e7535c0a2f53efb61554b1eabb728ad1868d3d38c03cd246222b1a3f0546bf98a01d21edaf8b47f0660864660e529bb5
6
+ metadata.gz: c6960cd38d01777676e103380aaead46a7215d2e5bcf9e25606d9d6f104914c23601029230780879823435e4c841dac4f2f9358a4e391f3eba699bf1fcea5d93
7
+ data.tar.gz: 3e260ba74f22108697407de4355076f428bde4645231fb61eb1f1105596c2c515f8401dcef433d1f73f9260395973f34c72becac784404bb239d9a145e76e2dd
data/README.md CHANGED
@@ -27,22 +27,31 @@ $ bundle
27
27
 
28
28
  ## Usage
29
29
 
30
- In your layout add a line like this in your head or before close body:
30
+ Include tag must be added before any other tag in order to work and only will be shown in production.
31
+
32
+ ### Include
33
+
34
+ In your layout add a line like this in your head:
31
35
  ```erb
32
- <%= google_analytics_include_tag 'your-id' %>
36
+ <%= google_analytics_include_tag 'id' %>
33
37
  ```
34
38
 
35
- You can add variables:
39
+ You can add metrics if you want:
36
40
  ```erb
37
- <%= google_analytics_include_tag 'your-id', user: 1 %>
41
+ <%= google_analytics_include_tag 'id', metric: 'value' %>
38
42
  ```
39
43
 
40
- And custom events after the include tag:
44
+ ### Events
45
+
46
+ To send events add a line like this with the category and action:
41
47
  ```erb
42
- <%= google_analytics_event_tag 'popup', 'click' %>
48
+ <%= google_analytics_event_tag 'Video', 'play' %>
43
49
  ```
44
50
 
45
- NOTE: Will only show the tags in production environment.
51
+ You can add label, value and other options too if you want:
52
+ ```erb
53
+ <%= google_analytics_event_tag 'Video', 'play', 'Fall Campaign', 42, metric: 'value' %>
54
+ ```
46
55
 
47
56
  ## Credits
48
57
 
@@ -6,31 +6,35 @@ module Analytics
6
6
 
7
7
  def google_analytics_include_tag(*args)
8
8
  if ::Rails.env.production?
9
- options = args.extract_options!
9
+ options = extract_google_analytics_options(args)
10
10
  id = args.first
11
- variables = options.to_json
12
11
  content_tag :script, <<-SCRIPT.html_safe, type: 'text/javascript'
13
12
  (function(i,s,o,g,r,a,m){i["GoogleAnalyticsObject"]=r;i[r]=i[r]||function(){
14
13
  (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
15
14
  m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
16
15
  })(window,document,"script","https://www.google-analytics.com/analytics.js","ga");
17
16
  ga("create", "#{id}", "auto");
18
- ga("send", "pageview", #{variables});
17
+ ga("send", "pageview", #{options});
19
18
  SCRIPT
20
19
  end
21
20
  end
22
21
 
23
22
  def google_analytics_event_tag(*args)
24
23
  if ::Rails.env.production?
25
- options = args.extract_options!
24
+ options = extract_google_analytics_options(args)
26
25
  args = args.map(&:to_json).join(', ')
27
- variables = options.to_json
28
26
  content_tag :script, <<-SCRIPT.html_safe, type: 'text/javascript'
29
- ga("send", "event", #{args}, #{variables});
27
+ ga("send", "event", #{args}, #{options});
30
28
  SCRIPT
31
29
  end
32
30
  end
33
31
 
32
+ private
33
+
34
+ def extract_google_analytics_options(args)
35
+ args.extract_options!.transform_keys{ |key| key.to_s.camelize(:lower) }.to_json
36
+ end
37
+
34
38
  end
35
39
  end
36
40
  end
@@ -1,7 +1,7 @@
1
1
  module Analytics
2
2
  module Rails
3
3
 
4
- VERSION = '0.3.3'
4
+ VERSION = '0.3.4'
5
5
 
6
6
  end
7
7
  end
File without changes
@@ -118,3 +118,42 @@ TagTest: test_event
118
118
  ---------------------
119
119
  TagTest: test_include
120
120
  ---------------------
121
+ -------------------
122
+ TagTest: test_event
123
+ -------------------
124
+ ---------------------
125
+ TagTest: test_include
126
+ ---------------------
127
+ -------------------
128
+ TagTest: test_event
129
+ -------------------
130
+ ---------------------
131
+ TagTest: test_include
132
+ ---------------------
133
+ -------------------
134
+ TagTest: test_event
135
+ -------------------
136
+ -------------------
137
+ TagTest: test_event
138
+ -------------------
139
+ ---------------------
140
+ TagTest: test_include
141
+ ---------------------
142
+ -------------------
143
+ TagTest: test_event
144
+ -------------------
145
+ ---------------------
146
+ TagTest: test_include
147
+ ---------------------
148
+ -------------------
149
+ TagTest: test_event
150
+ -------------------
151
+ ---------------------
152
+ TagTest: test_include
153
+ ---------------------
154
+ -------------------
155
+ TagTest: test_event
156
+ -------------------
157
+ ---------------------
158
+ TagTest: test_include
159
+ ---------------------
data/test/tag_test.rb CHANGED
@@ -25,8 +25,8 @@ class TagTest < ActionView::TestCase
25
25
  'ga("send", "event", "Popup", "click", {});'
26
26
  )
27
27
  assert_includes(
28
- google_analytics_event_tag('Video', 'play', 'ad.mp4', 10, other: 'value'),
29
- 'ga("send", "event", "Video", "play", "ad.mp4", 10, {"other":"value"});'
28
+ google_analytics_event_tag('Video', 'play', 'ad.mp4', 10, non_interactive: 'value'),
29
+ 'ga("send", "event", "Video", "play", "ad.mp4", 10, {"nonInteractive":"value"});'
30
30
  )
31
31
  end
32
32
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: analytics-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.3
4
+ version: 0.3.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - mmontossi
@@ -73,6 +73,7 @@ files:
73
73
  - test/dummy/config/locales/en.yml
74
74
  - test/dummy/config/routes.rb
75
75
  - test/dummy/config/secrets.yml
76
+ - test/dummy/log/development.log
76
77
  - test/dummy/log/test.log
77
78
  - test/dummy/public/404.html
78
79
  - test/dummy/public/422.html
@@ -132,6 +133,7 @@ test_files:
132
133
  - test/dummy/config/routes.rb
133
134
  - test/dummy/config/secrets.yml
134
135
  - test/dummy/config.ru
136
+ - test/dummy/log/development.log
135
137
  - test/dummy/log/test.log
136
138
  - test/dummy/public/404.html
137
139
  - test/dummy/public/422.html