event_tracker 0.1.2 → 0.2.0
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 +4 -4
- data/.gitignore +2 -0
- data/README.md +1 -1
- data/lib/event_tracker.rb +15 -1
- data/lib/event_tracker/mixpanel.rb +18 -10
- data/lib/event_tracker/version.rb +1 -1
- data/spec/event_tracker_spec.rb +54 -6
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a1ebbed11b5b9e591c51936b8ea6525e568c81fb
|
4
|
+
data.tar.gz: 14529c86a7e8e55d6f8b9ae7497b0f704403bf67
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 631a3f261b419775696bf840e77b2e1d11a6169e8f0695b6dd94fe247f43be90e67bd400d5d1dcf84f87fec0bb3f74f7a6973b6a9d6d0689e57c2fa79ed7d56d
|
7
|
+
data.tar.gz: 23d8b6b4be2043c4518142b60bc478b63cc663cee31dcd7c01fd021e70f9a27ec23b435d050c5d8c62a07556629377cfd2d126818b43655269dfbf216651cd19
|
data/.gitignore
CHANGED
data/README.md
CHANGED
@@ -26,7 +26,7 @@ config.event_tracker.mixpanel_key = "YOUR_KEY"
|
|
26
26
|
config.event_tracker.kissmetrics_key = "YOUR_KEY"
|
27
27
|
|
28
28
|
class ApplicationController < ActionController::Base
|
29
|
-
|
29
|
+
around_filter :append_event_tracking_tags
|
30
30
|
|
31
31
|
# optionally identify users
|
32
32
|
def mixpanel_distinct_id
|
data/lib/event_tracker.rb
CHANGED
@@ -11,6 +11,14 @@ module EventTracker
|
|
11
11
|
def register_properties(args)
|
12
12
|
(session[:registered_properties] ||= {}).merge!(args)
|
13
13
|
end
|
14
|
+
|
15
|
+
def mixpanel_people_set(args)
|
16
|
+
(session[:mixpanel_people_set] ||= {}).merge!(args)
|
17
|
+
end
|
18
|
+
|
19
|
+
def mixpanel_alias(identity)
|
20
|
+
session[:mixpanel_alias] = identity
|
21
|
+
end
|
14
22
|
end
|
15
23
|
|
16
24
|
module ActionControllerExtension
|
@@ -38,6 +46,7 @@ module EventTracker
|
|
38
46
|
end
|
39
47
|
|
40
48
|
def append_event_tracking_tags
|
49
|
+
yield
|
41
50
|
return if event_trackers.empty?
|
42
51
|
|
43
52
|
body = response.body
|
@@ -47,12 +56,17 @@ module EventTracker
|
|
47
56
|
body_insert_at = body.index('</body')
|
48
57
|
return unless body_insert_at
|
49
58
|
a = []
|
50
|
-
if
|
59
|
+
if mixpanel_alias = session.delete(:mixpanel_alias)
|
60
|
+
a << mixpanel_tracker.alias(mixpanel_alias)
|
61
|
+
elsif distinct_id = respond_to?(:mixpanel_distinct_id, true) && mixpanel_distinct_id
|
51
62
|
a << mixpanel_tracker.identify(distinct_id)
|
52
63
|
end
|
53
64
|
if name_tag = respond_to?(:mixpanel_name_tag, true) && mixpanel_name_tag
|
54
65
|
a << mixpanel_tracker.name_tag(name_tag)
|
55
66
|
end
|
67
|
+
if (people = session.delete(:mixpanel_people_set)).present?
|
68
|
+
a << mixpanel_tracker.people_set(people)
|
69
|
+
end
|
56
70
|
if identity = respond_to?(:kissmetrics_identity, true) && kissmetrics_identity
|
57
71
|
a << kissmetrics_tracker.identify(identity)
|
58
72
|
end
|
@@ -5,16 +5,16 @@ class EventTracker::Mixpanel
|
|
5
5
|
|
6
6
|
def init
|
7
7
|
s = <<-EOD
|
8
|
-
(function(
|
9
|
-
|
10
|
-
'//cdn.mxpnl.com/libs/mixpanel-2.
|
11
|
-
|
12
|
-
var
|
13
|
-
Array.prototype.slice.call(arguments,0)))}}var
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
8
|
+
(function(e,b){if(!b.__SV){var a,f,i,g;window.mixpanel=b;a=e.createElement("script");
|
9
|
+
a.type="text/javascript";a.async=!0;a.src=("https:"===e.location.protocol?"https:":"http:")+
|
10
|
+
'//cdn.mxpnl.com/libs/mixpanel-2.2.min.js';f=e.getElementsByTagName("script")[0];
|
11
|
+
f.parentNode.insertBefore(a,f);b._i=[];b.init=function(a,e,d){function f(b,h){
|
12
|
+
var a=h.split(".");2==a.length&&(b=b[a[0]],h=a[1]);b[h]=function(){b.push([h].concat(
|
13
|
+
Array.prototype.slice.call(arguments,0)))}}var c=b;"undefined"!==typeof d?c=b[d]=[]:
|
14
|
+
d="mixpanel";c.people=c.people||[];c.toString=function(b){var a="mixpanel";"mixpanel"!==d&&(a+="."+d);
|
15
|
+
b||(a+=" (stub)");return a};c.people.toString=function(){return c.toString(1)+".people (stub)"};
|
16
|
+
i="disable track track_pageview track_links track_forms register register_once alias unregister identify name_tag set_config people.set people.increment".split(" ");
|
17
|
+
for(g=0;g<i.length;g++)f(c,i[g]);b._i.push([a,e,d])};b.__SV=1.2}})(document,window.mixpanel||[]);
|
18
18
|
mixpanel.init("#{@key}");
|
19
19
|
EOD
|
20
20
|
end
|
@@ -35,4 +35,12 @@ class EventTracker::Mixpanel
|
|
35
35
|
def identify(distinct_id)
|
36
36
|
%Q{mixpanel.identify("#{distinct_id}");}
|
37
37
|
end
|
38
|
+
|
39
|
+
def people_set(properties)
|
40
|
+
%Q{mixpanel.people.set(#{properties.to_json});}
|
41
|
+
end
|
42
|
+
|
43
|
+
def alias(identity)
|
44
|
+
%Q{mixpanel.alias(#{identity.to_json});}
|
45
|
+
end
|
38
46
|
end
|
data/spec/event_tracker_spec.rb
CHANGED
@@ -29,7 +29,7 @@ feature 'basic integration' do
|
|
29
29
|
subject { page.find("body script").native.content }
|
30
30
|
|
31
31
|
class BasicController < ApplicationController
|
32
|
-
|
32
|
+
around_filter :append_event_tracking_tags
|
33
33
|
def no_tracking
|
34
34
|
render inline: "OK", layout: true
|
35
35
|
end
|
@@ -68,7 +68,7 @@ feature 'basic integration' do
|
|
68
68
|
end
|
69
69
|
|
70
70
|
class RedirectsController < ApplicationController
|
71
|
-
|
71
|
+
around_filter :append_event_tracking_tags
|
72
72
|
|
73
73
|
def index
|
74
74
|
track_event "Register for site"
|
@@ -86,7 +86,7 @@ feature 'basic integration' do
|
|
86
86
|
end
|
87
87
|
|
88
88
|
class WithPropertiesController < ApplicationController
|
89
|
-
|
89
|
+
around_filter :append_event_tracking_tags
|
90
90
|
|
91
91
|
def index
|
92
92
|
register_properties age: 19
|
@@ -105,7 +105,7 @@ feature 'basic integration' do
|
|
105
105
|
end
|
106
106
|
|
107
107
|
class IdentityController < ApplicationController
|
108
|
-
|
108
|
+
around_filter :append_event_tracking_tags
|
109
109
|
def mixpanel_distinct_id
|
110
110
|
"distinct_id"
|
111
111
|
end
|
@@ -125,7 +125,7 @@ feature 'basic integration' do
|
|
125
125
|
end
|
126
126
|
|
127
127
|
class NameTagController < ApplicationController
|
128
|
-
|
128
|
+
around_filter :append_event_tracking_tags
|
129
129
|
def mixpanel_name_tag
|
130
130
|
"foo@example.org"
|
131
131
|
end
|
@@ -141,7 +141,7 @@ feature 'basic integration' do
|
|
141
141
|
end
|
142
142
|
|
143
143
|
class PrivateController < ApplicationController
|
144
|
-
|
144
|
+
around_filter :append_event_tracking_tags
|
145
145
|
def index; render inline: "OK", layout: true; end
|
146
146
|
private
|
147
147
|
def mixpanel_distinct_id; "distinct_id"; end
|
@@ -152,4 +152,52 @@ feature 'basic integration' do
|
|
152
152
|
background { visit "/private" }
|
153
153
|
it_should_behave_like "with distinct id"
|
154
154
|
end
|
155
|
+
|
156
|
+
class PeopleSetController < ApplicationController
|
157
|
+
around_filter :append_event_tracking_tags
|
158
|
+
|
159
|
+
def index
|
160
|
+
mixpanel_people_set "$email" => "jsmith@example.com"
|
161
|
+
render inline: "OK", layout: true
|
162
|
+
end
|
163
|
+
end
|
164
|
+
|
165
|
+
context "track event with properties" do
|
166
|
+
background { visit "/people_set" }
|
167
|
+
it { should include %Q{mixpanel.people.set({"$email":"jsmith@example.com"})} }
|
168
|
+
end
|
169
|
+
|
170
|
+
class AliasController < ApplicationController
|
171
|
+
around_filter :append_event_tracking_tags
|
172
|
+
|
173
|
+
def index
|
174
|
+
mixpanel_alias "jsmith@example.com"
|
175
|
+
render inline: "OK", layout: true
|
176
|
+
end
|
177
|
+
end
|
178
|
+
|
179
|
+
context "track event with properties" do
|
180
|
+
background { visit "/alias" }
|
181
|
+
it { should include %Q{mixpanel.alias("jsmith@example.com")} }
|
182
|
+
end
|
183
|
+
|
184
|
+
context "halting filter chain in a before_filter" do
|
185
|
+
background { visit "/before_filter" }
|
186
|
+
it_should_behave_like "init"
|
187
|
+
end
|
188
|
+
|
189
|
+
class BeforeFilterController < ApplicationController
|
190
|
+
around_filter :append_event_tracking_tags
|
191
|
+
before_filter :halt_the_chain_and_render
|
192
|
+
|
193
|
+
def index
|
194
|
+
render inline: "OK", layout: true
|
195
|
+
end
|
196
|
+
|
197
|
+
def halt_the_chain_and_render
|
198
|
+
render inline: "OK", layout: true and return
|
199
|
+
end
|
200
|
+
|
201
|
+
end
|
202
|
+
|
155
203
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: event_tracker
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Paul McMahon
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-
|
11
|
+
date: 2013-05-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|