event_tracker 0.2.0 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -17,4 +17,5 @@ Gem::Specification.new do |gem|
17
17
 
18
18
  gem.add_dependency 'rails', '>= 3.0'
19
19
  gem.add_development_dependency 'steak'
20
+ gem.add_development_dependency 'capybara', '~> 2.0.3'
20
21
  end
data/lib/event_tracker.rb CHANGED
@@ -12,10 +12,22 @@ module EventTracker
12
12
  (session[:registered_properties] ||= {}).merge!(args)
13
13
  end
14
14
 
15
+ def mixpanel_set_config(args)
16
+ (session[:mixpanel_set_config] ||= {}).merge!(args)
17
+ end
18
+
15
19
  def mixpanel_people_set(args)
16
20
  (session[:mixpanel_people_set] ||= {}).merge!(args)
17
21
  end
18
22
 
23
+ def mixpanel_people_set_once(args)
24
+ (session[:mixpanel_people_set_once] ||= {}).merge!(args)
25
+ end
26
+
27
+ def mixpanel_people_increment(event_name)
28
+ (session[:mixpanel_people_increment] ||= []) << event_name
29
+ end
30
+
19
31
  def mixpanel_alias(identity)
20
32
  session[:mixpanel_alias] = identity
21
33
  end
@@ -52,24 +64,42 @@ module EventTracker
52
64
  body = response.body
53
65
  head_insert_at = body.index('</head')
54
66
  return unless head_insert_at
67
+
55
68
  body.insert head_insert_at, view_context.javascript_tag(event_trackers.map {|t| t.init }.join("\n"))
56
69
  body_insert_at = body.index('</body')
57
70
  return unless body_insert_at
71
+
58
72
  a = []
59
73
  if mixpanel_alias = session.delete(:mixpanel_alias)
60
74
  a << mixpanel_tracker.alias(mixpanel_alias)
61
75
  elsif distinct_id = respond_to?(:mixpanel_distinct_id, true) && mixpanel_distinct_id
62
76
  a << mixpanel_tracker.identify(distinct_id)
63
77
  end
78
+
64
79
  if name_tag = respond_to?(:mixpanel_name_tag, true) && mixpanel_name_tag
65
80
  a << mixpanel_tracker.name_tag(name_tag)
66
81
  end
82
+
83
+ if (config = session.delete(:mixpanel_set_config)).present?
84
+ a << mixpanel_tracker.set_config(config)
85
+ end
86
+
67
87
  if (people = session.delete(:mixpanel_people_set)).present?
68
88
  a << mixpanel_tracker.people_set(people)
69
89
  end
90
+
91
+ if (people = session.delete(:mixpanel_people_set_once)).present?
92
+ a << mixpanel_tracker.people_set_once(people)
93
+ end
94
+
95
+ if (people = session.delete(:mixpanel_people_increment)).present?
96
+ a << mixpanel_tracker.people_increment(people)
97
+ end
98
+
70
99
  if identity = respond_to?(:kissmetrics_identity, true) && kissmetrics_identity
71
100
  a << kissmetrics_tracker.identify(identity)
72
101
  end
102
+
73
103
  registered_properties = session.delete(:registered_properties)
74
104
  event_tracker_queue = session.delete(:event_tracker_queue)
75
105
 
@@ -82,6 +112,7 @@ module EventTracker
82
112
  end
83
113
  end
84
114
  end
115
+
85
116
  body.insert body_insert_at, view_context.javascript_tag(a.join("\n"))
86
117
  response.body = body
87
118
  end
@@ -13,8 +13,8 @@ class EventTracker::Mixpanel
13
13
  Array.prototype.slice.call(arguments,0)))}}var c=b;"undefined"!==typeof d?c=b[d]=[]:
14
14
  d="mixpanel";c.people=c.people||[];c.toString=function(b){var a="mixpanel";"mixpanel"!==d&&(a+="."+d);
15
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||[]);
16
+ i="disable track track_pageview track_links track_forms register register_once alias unregister identify name_tag set_config people.set people.set_once people.increment people.append people.track_charge people.clear_charges people.delete_user".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
@@ -40,6 +40,18 @@ class EventTracker::Mixpanel
40
40
  %Q{mixpanel.people.set(#{properties.to_json});}
41
41
  end
42
42
 
43
+ def people_set_once(properties)
44
+ %Q{mixpanel.people.set_once(#{properties.to_json});}
45
+ end
46
+
47
+ def people_increment(properties)
48
+ %Q{mixpanel.people.increment(#{properties.to_json});}
49
+ end
50
+
51
+ def set_config(properties)
52
+ %Q{mixpanel.set_config(#{properties.to_json});}
53
+ end
54
+
43
55
  def alias(identity)
44
56
  %Q{mixpanel.alias(#{identity.to_json});}
45
57
  end
@@ -1,3 +1,3 @@
1
1
  module EventTracker
2
- VERSION = "0.2.0"
2
+ VERSION = "0.2.1"
3
3
  end
@@ -153,6 +153,20 @@ feature 'basic integration' do
153
153
  it_should_behave_like "with distinct id"
154
154
  end
155
155
 
156
+ class SetConfigController < ApplicationController
157
+ around_filter :append_event_tracking_tags
158
+
159
+ def index
160
+ mixpanel_set_config 'track_pageview' => false
161
+ render inline: "OK", layout: true
162
+ end
163
+ end
164
+
165
+ context 'configure mixpanel' do
166
+ background { visit '/set_config' }
167
+ it { should include %Q{mixpanel.set_config({"track_pageview":false})} }
168
+ end
169
+
156
170
  class PeopleSetController < ApplicationController
157
171
  around_filter :append_event_tracking_tags
158
172
 
@@ -162,11 +176,39 @@ feature 'basic integration' do
162
176
  end
163
177
  end
164
178
 
165
- context "track event with properties" do
179
+ context "people set properties" do
166
180
  background { visit "/people_set" }
167
181
  it { should include %Q{mixpanel.people.set({"$email":"jsmith@example.com"})} }
168
182
  end
169
183
 
184
+ class PeopleSetOnceController < ApplicationController
185
+ around_filter :append_event_tracking_tags
186
+
187
+ def index
188
+ mixpanel_people_set_once "One more time" => "With feeling"
189
+ render inline: "OK", layout: true
190
+ end
191
+ end
192
+
193
+ context 'people set properties once' do
194
+ background { visit '/people_set_once' }
195
+ it { should include %Q{mixpanel.people.set_once({"One more time":"With feeling"})} }
196
+ end
197
+
198
+ class PeopleIncrementController < ApplicationController
199
+ around_filter :append_event_tracking_tags
200
+
201
+ def index
202
+ mixpanel_people_increment "Named Attribute"
203
+ render inline: "OK", layout: true
204
+ end
205
+ end
206
+
207
+ context 'people set properties once' do
208
+ background { visit '/people_increment' }
209
+ it { should include %Q{mixpanel.people.increment(["Named Attribute"])} }
210
+ end
211
+
170
212
  class AliasController < ApplicationController
171
213
  around_filter :append_event_tracking_tags
172
214
 
metadata CHANGED
@@ -1,43 +1,49 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: event_tracker
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.1
5
+ prerelease:
5
6
  platform: ruby
6
7
  authors:
7
8
  - Paul McMahon
8
9
  autorequire:
9
10
  bindir: bin
10
11
  cert_chain: []
11
- date: 2013-05-06 00:00:00.000000000 Z
12
+ date: 2013-07-03 00:00:00.000000000 Z
12
13
  dependencies:
13
14
  - !ruby/object:Gem::Dependency
14
15
  name: rails
15
- requirement: !ruby/object:Gem::Requirement
16
+ requirement: &2160814880 !ruby/object:Gem::Requirement
17
+ none: false
16
18
  requirements:
17
- - - '>='
19
+ - - ! '>='
18
20
  - !ruby/object:Gem::Version
19
21
  version: '3.0'
20
22
  type: :runtime
21
23
  prerelease: false
22
- version_requirements: !ruby/object:Gem::Requirement
23
- requirements:
24
- - - '>='
25
- - !ruby/object:Gem::Version
26
- version: '3.0'
24
+ version_requirements: *2160814880
27
25
  - !ruby/object:Gem::Dependency
28
26
  name: steak
29
- requirement: !ruby/object:Gem::Requirement
27
+ requirement: &2160812460 !ruby/object:Gem::Requirement
28
+ none: false
30
29
  requirements:
31
- - - '>='
30
+ - - ! '>='
32
31
  - !ruby/object:Gem::Version
33
32
  version: '0'
34
33
  type: :development
35
34
  prerelease: false
36
- version_requirements: !ruby/object:Gem::Requirement
35
+ version_requirements: *2160812460
36
+ - !ruby/object:Gem::Dependency
37
+ name: capybara
38
+ requirement: &2160821040 !ruby/object:Gem::Requirement
39
+ none: false
37
40
  requirements:
38
- - - '>='
41
+ - - ~>
39
42
  - !ruby/object:Gem::Version
40
- version: '0'
43
+ version: 2.0.3
44
+ type: :development
45
+ prerelease: false
46
+ version_requirements: *2160821040
41
47
  description: Easy integration with Mixpanel and Kissmetrics for Rails
42
48
  email:
43
49
  - paul@mobalean.com
@@ -61,26 +67,27 @@ files:
61
67
  - spec/spec_helper.rb
62
68
  homepage: http://www.doorkeeperhq.com/developer/event-tracker-mixpanel-kissmetrics
63
69
  licenses: []
64
- metadata: {}
65
70
  post_install_message:
66
71
  rdoc_options: []
67
72
  require_paths:
68
73
  - lib
69
74
  required_ruby_version: !ruby/object:Gem::Requirement
75
+ none: false
70
76
  requirements:
71
- - - '>='
77
+ - - ! '>='
72
78
  - !ruby/object:Gem::Version
73
79
  version: '0'
74
80
  required_rubygems_version: !ruby/object:Gem::Requirement
81
+ none: false
75
82
  requirements:
76
- - - '>='
83
+ - - ! '>='
77
84
  - !ruby/object:Gem::Version
78
85
  version: '0'
79
86
  requirements: []
80
87
  rubyforge_project:
81
- rubygems_version: 2.0.0
88
+ rubygems_version: 1.8.15
82
89
  signing_key:
83
- specification_version: 4
90
+ specification_version: 3
84
91
  summary: Track using javascript from your controllers, even when redirecting
85
92
  test_files:
86
93
  - spec/app/views/basic/in_views.html.erb
checksums.yaml DELETED
@@ -1,7 +0,0 @@
1
- ---
2
- SHA1:
3
- metadata.gz: a1ebbed11b5b9e591c51936b8ea6525e568c81fb
4
- data.tar.gz: 14529c86a7e8e55d6f8b9ae7497b0f704403bf67
5
- SHA512:
6
- metadata.gz: 631a3f261b419775696bf840e77b2e1d11a6169e8f0695b6dd94fe247f43be90e67bd400d5d1dcf84f87fec0bb3f74f7a6973b6a9d6d0689e57c2fa79ed7d56d
7
- data.tar.gz: 23d8b6b4be2043c4518142b60bc478b63cc663cee31dcd7c01fd021e70f9a27ec23b435d050c5d8c62a07556629377cfd2d126818b43655269dfbf216651cd19