analytics-rails 0.1.1 → 0.2.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: a0df059c391f3d05a2e26b2ffafe9ac94bbf308b
4
- data.tar.gz: cdb2a198bbafc36f53837322b1369b8a57e82e1d
3
+ metadata.gz: 85b7455b778150eeb651014c18755febbd09e7a1
4
+ data.tar.gz: 2cd193d945a371f2d6827da599b7f57b69bb3df7
5
5
  SHA512:
6
- metadata.gz: 3c280bcd117515017639656a17fb0ca07127725e5c61735cb5519c9a4dfab24b411f17e5cbcde555773dd6b7cfc4067603a74cfc0aeab825a0774948e24dcb6f
7
- data.tar.gz: 06ca665da521ac9fa4e701ed86009c3ea8c7860a4fe97257255b915cb4afbef500c67e4bb16939d8ec30ba8a07ba5c1924b8925b404bc2bd4c553a5f2e793578
6
+ metadata.gz: aedd14aa56d3130fd3e815395d3a557c8d149ac2eaa3010a61dfd4c043d875200536dd20f37cfc0470e53b29f8cb0dc81c8fec8f0135ba47eda12ea01a40619a
7
+ data.tar.gz: 3f07a2a70f252aa63792307c90451848eca4a0bc568c12926d3083975f378cc147439c629f5e3706bb3d33e3851b9e59d39468731d45b230efb38294ea859382
data/README.md CHANGED
@@ -23,6 +23,16 @@ In your layout add a line like this in your head:
23
23
  <%= google_analytics_include_tag 'your-id' %>
24
24
  ```
25
25
 
26
+ You can add custom events:
27
+ ```erb
28
+ <%= google_analytics_include_tag 'your-id', events: [['Popup', 'Click']] %>
29
+ ```
30
+
31
+ And custom variables:
32
+ ```erb
33
+ <%= google_analytics_include_tag 'your-id', variables: [[1, 'Member', 'Yes', 1]] %>
34
+ ```
35
+
26
36
  NOTE: Will only show the include tag in production environment.
27
37
 
28
38
  ## Credits
@@ -3,17 +3,35 @@ module Analytics
3
3
  module ActionView
4
4
  module Base
5
5
 
6
- def google_analytics_include_tag(account)
6
+ def google_analytics_include_tag(*args)
7
+ options = args.extract_options!
7
8
  if ::Rails.env.production?
9
+ [:variables, :events].each do |name|
10
+ if options.has_key? name
11
+ options[name].map! do |values|
12
+ values.map(&:inspect).join(', ').gsub('"',"'")
13
+ end
14
+ else
15
+ options[name] = []
16
+ end
17
+ end
18
+ variables = options[:variables].map do |values|
19
+ "_gaq.push(['_setCustomVar', #{values}]);"
20
+ end
21
+ events = options[:events].map do |values|
22
+ "ga('send', 'event', #{values});"
23
+ end
8
24
  script = <<-SCRIPT
9
25
  var _gaq = _gaq || [];
10
- _gaq.push(['_setAccount', '#{account}']);
26
+ _gaq.push(['_setAccount', '#{args.first}']);
27
+ #{variables.join("\n")}
11
28
  _gaq.push(['_trackPageview']);
12
29
  (function(){
13
30
  var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
14
31
  ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
15
32
  var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
16
33
  })();
34
+ #{events.join("\n")}
17
35
  SCRIPT
18
36
  content_tag :script, script.html_safe, type: 'text/javascript'
19
37
  end
@@ -1,7 +1,7 @@
1
1
  module Analytics
2
2
  module Rails
3
3
 
4
- VERSION = '0.1.1'
4
+ VERSION = '0.2.0'
5
5
 
6
6
  end
7
7
  end
@@ -121,3 +121,93 @@ IncludeTagTest: test_should_return_include_tag_with_id
121
121
  IncludeTagTest: test_tag_id
122
122
  ---------------------------
123
123
   (0.0ms) rollback transaction
124
+  (0.2ms) CREATE TABLE "schema_migrations" ("version" varchar NOT NULL) 
125
+  (0.1ms) select sqlite_version(*)
126
+  (0.1ms) CREATE UNIQUE INDEX "unique_schema_migrations" ON "schema_migrations" ("version")
127
+  (0.0ms) SELECT version FROM "schema_migrations"
128
+  (0.0ms) INSERT INTO "schema_migrations" (version) VALUES ('0')
129
+  (0.2ms) CREATE TABLE "schema_migrations" ("version" varchar NOT NULL) 
130
+  (0.0ms) select sqlite_version(*)
131
+  (0.1ms) CREATE UNIQUE INDEX "unique_schema_migrations" ON "schema_migrations" ("version")
132
+  (0.0ms) SELECT version FROM "schema_migrations"
133
+  (0.0ms) INSERT INTO "schema_migrations" (version) VALUES ('0')
134
+  (0.1ms) begin transaction
135
+ ---------------------------
136
+ IncludeTagTest: test_tag_id
137
+ ---------------------------
138
+  (0.0ms) rollback transaction
139
+  (0.2ms) CREATE TABLE "schema_migrations" ("version" varchar NOT NULL) 
140
+  (0.0ms) select sqlite_version(*)
141
+  (0.1ms) CREATE UNIQUE INDEX "unique_schema_migrations" ON "schema_migrations" ("version")
142
+  (0.0ms) SELECT version FROM "schema_migrations"
143
+  (0.0ms) INSERT INTO "schema_migrations" (version) VALUES ('0')
144
+  (0.2ms) CREATE TABLE "schema_migrations" ("version" varchar NOT NULL) 
145
+  (0.1ms) select sqlite_version(*)
146
+  (0.1ms) CREATE UNIQUE INDEX "unique_schema_migrations" ON "schema_migrations" ("version")
147
+  (0.1ms) SELECT version FROM "schema_migrations"
148
+  (0.0ms) INSERT INTO "schema_migrations" (version) VALUES ('0')
149
+  (0.1ms) begin transaction
150
+ ---------------------------
151
+ IncludeTagTest: test_tag_id
152
+ ---------------------------
153
+  (0.0ms) rollback transaction
154
+  (0.2ms) CREATE TABLE "schema_migrations" ("version" varchar NOT NULL) 
155
+  (0.0ms) select sqlite_version(*)
156
+  (0.1ms) CREATE UNIQUE INDEX "unique_schema_migrations" ON "schema_migrations" ("version")
157
+  (0.0ms) SELECT version FROM "schema_migrations"
158
+  (0.0ms) INSERT INTO "schema_migrations" (version) VALUES ('0')
159
+  (0.2ms) CREATE TABLE "schema_migrations" ("version" varchar NOT NULL) 
160
+  (0.0ms) select sqlite_version(*)
161
+  (0.1ms) CREATE UNIQUE INDEX "unique_schema_migrations" ON "schema_migrations" ("version")
162
+  (0.0ms) SELECT version FROM "schema_migrations"
163
+  (0.0ms) INSERT INTO "schema_migrations" (version) VALUES ('0')
164
+  (0.1ms) begin transaction
165
+ ---------------------------
166
+ IncludeTagTest: test_tag_id
167
+ ---------------------------
168
+  (0.0ms) rollback transaction
169
+  (0.2ms) CREATE TABLE "schema_migrations" ("version" varchar NOT NULL) 
170
+  (0.0ms) select sqlite_version(*)
171
+  (0.1ms) CREATE UNIQUE INDEX "unique_schema_migrations" ON "schema_migrations" ("version")
172
+  (0.0ms) SELECT version FROM "schema_migrations"
173
+  (0.2ms) INSERT INTO "schema_migrations" (version) VALUES ('0')
174
+  (0.3ms) CREATE TABLE "schema_migrations" ("version" varchar NOT NULL) 
175
+  (0.1ms) select sqlite_version(*)
176
+  (0.1ms) CREATE UNIQUE INDEX "unique_schema_migrations" ON "schema_migrations" ("version")
177
+  (0.1ms) SELECT version FROM "schema_migrations"
178
+  (0.1ms) INSERT INTO "schema_migrations" (version) VALUES ('0')
179
+  (0.1ms) begin transaction
180
+ ---------------------------
181
+ IncludeTagTest: test_tag_id
182
+ ---------------------------
183
+  (0.0ms) rollback transaction
184
+  (0.2ms) CREATE TABLE "schema_migrations" ("version" varchar NOT NULL) 
185
+  (0.0ms) select sqlite_version(*)
186
+  (0.1ms) CREATE UNIQUE INDEX "unique_schema_migrations" ON "schema_migrations" ("version")
187
+  (0.0ms) SELECT version FROM "schema_migrations"
188
+  (0.0ms) INSERT INTO "schema_migrations" (version) VALUES ('0')
189
+  (0.2ms) CREATE TABLE "schema_migrations" ("version" varchar NOT NULL) 
190
+  (0.0ms) select sqlite_version(*)
191
+  (0.1ms) CREATE UNIQUE INDEX "unique_schema_migrations" ON "schema_migrations" ("version")
192
+  (0.1ms) SELECT version FROM "schema_migrations"
193
+  (0.0ms) INSERT INTO "schema_migrations" (version) VALUES ('0')
194
+  (0.1ms) begin transaction
195
+ ---------------------------
196
+ IncludeTagTest: test_tag_id
197
+ ---------------------------
198
+  (0.0ms) rollback transaction
199
+  (0.2ms) CREATE TABLE "schema_migrations" ("version" varchar NOT NULL) 
200
+  (0.0ms) select sqlite_version(*)
201
+  (0.1ms) CREATE UNIQUE INDEX "unique_schema_migrations" ON "schema_migrations" ("version")
202
+  (0.0ms) SELECT version FROM "schema_migrations"
203
+  (0.0ms) INSERT INTO "schema_migrations" (version) VALUES ('0')
204
+  (0.2ms) CREATE TABLE "schema_migrations" ("version" varchar NOT NULL) 
205
+  (0.0ms) select sqlite_version(*)
206
+  (0.1ms) CREATE UNIQUE INDEX "unique_schema_migrations" ON "schema_migrations" ("version")
207
+  (0.0ms) SELECT version FROM "schema_migrations"
208
+  (0.0ms) INSERT INTO "schema_migrations" (version) VALUES ('0')
209
+  (0.1ms) begin transaction
210
+ ---------------------------
211
+ IncludeTagTest: test_tag_id
212
+ ---------------------------
213
+  (0.1ms) rollback transaction
@@ -5,6 +5,14 @@ class IncludeTagTest < ActionView::TestCase
5
5
  test 'tag id' do
6
6
  with_env 'production' do
7
7
  assert google_analytics_include_tag('id').include?("_gaq.push(['_setAccount', 'id']);")
8
+
9
+ assert google_analytics_include_tag(
10
+ variables: [[1, 'Member', 'Yes', 1]]
11
+ ).include?("_gaq.push(['_setCustomVar', 1, 'Member', 'Yes', 1])")
12
+
13
+ assert google_analytics_include_tag(
14
+ events: [['Popup', 'Click']]
15
+ ).include?("ga('send', 'event', 'Popup', 'Click');")
8
16
  end
9
17
  end
10
18
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: analytics-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Museways
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-02-16 00:00:00.000000000 Z
11
+ date: 2015-07-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -17,9 +17,9 @@ dependencies:
17
17
  - - ">="
18
18
  - !ruby/object:Gem::Version
19
19
  version: 4.0.0
20
- - - "<="
20
+ - - "<"
21
21
  - !ruby/object:Gem::Version
22
- version: 4.2.0
22
+ version: 4.3.0
23
23
  type: :runtime
24
24
  prerelease: false
25
25
  version_requirements: !ruby/object:Gem::Requirement
@@ -27,9 +27,9 @@ dependencies:
27
27
  - - ">="
28
28
  - !ruby/object:Gem::Version
29
29
  version: 4.0.0
30
- - - "<="
30
+ - - "<"
31
31
  - !ruby/object:Gem::Version
32
- version: 4.2.0
32
+ version: 4.3.0
33
33
  - !ruby/object:Gem::Dependency
34
34
  name: sqlite3
35
35
  requirement: !ruby/object:Gem::Requirement