mixpanel 3.6.2 → 4.0.0

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -315,11 +315,11 @@ If you need to remove accidental charges for a person, you can use:
315
315
 
316
316
  **event_name** and **properties** take the same form as [tracking the event directly](#track-events-directly).
317
317
 
318
- Note that you must call mixpanel.people.identify() in conjunction with People requests like set(). If you make set() requests before
318
+ Note that you must call mixpanel.identify() in conjunction with People requests like set(). If you make set() requests before
319
319
  you identify the user, the change will not be immediately sent to Mixpanel. Mixpanel will wait for you to call identify() and then send the accumulated changes.
320
320
 
321
321
  ```ruby
322
- @mixpanel.append_people_identify distinct_id
322
+ @mixpanel.append_identify distinct_id
323
323
  @mixpanel.append_set properties
324
324
  ```
325
325
 
@@ -98,17 +98,7 @@ module Mixpanel
98
98
  <<-EOT
99
99
  <!-- start Mixpanel -->
100
100
  <script type="text/javascript">
101
- (function(c,a){window.mixpanel=a;var b,d,h,e;b=c.createElement("script");
102
- b.type="text/javascript";b.async=!0;b.src=("https:"===c.location.protocol?"https:":"http:")+
103
- '//cdn.mxpnl.com/libs/mixpanel-2.1.min.js';d=c.getElementsByTagName("script")[0];
104
- d.parentNode.insertBefore(b,d);a._i=[];a.init=function(b,c,f){function d(a,b){
105
- var c=b.split(".");2==c.length&&(a=a[c[0]],b=c[1]);a[b]=function(){a.push([b].concat(
106
- Array.prototype.slice.call(arguments,0)))}}var g=a;"undefined"!==typeof f?g=a[f]=[]:
107
- f="mixpanel";g.people=g.people||[];h=['disable','track','track_pageview','track_links',
108
- 'track_forms','register','register_once','unregister','identify','name_tag',
109
- 'set_config','people.identify','people.set','people.increment'];for(e=0;e<h.length;e++)d(g,h[e]);
110
- a._i.push([b,c,f])};a.__SV=1.1;})(document,window.mixpanel||[]);
111
-
101
+ (function(e,b){if(!b.__SV){var a,f,i,g;window.mixpanel=b;a=e.createElement("script");a.type="text/javascript";a.async=!0;a.src=("https:"===e.location.protocol?"https:":"http:")+'//cdn.mxpnl.com/libs/mixpanel-2.2.min.js';f=e.getElementsByTagName("script")[0];f.parentNode.insertBefore(a,f);b._i=[];b.init=function(a,e,d){function f(b,h){var a=h.split(".");2==a.length&&(b=b[a[0]],h=a[1]);b[h]=function(){b.push([h].concat(Array.prototype.slice.call(arguments,0)))}}var c=b;"undefined"!==typeof d?c=b[d]=[]:d="mixpanel";c.people=c.people||[];c.toString=function(b){var a="mixpanel";"mixpanel"!==d&&(a+="."+d);b||(a+=" (stub)");return a};c.people.toString=function(){return c.toString(1)+".people (stub)"};i="disable track track_pageview track_links track_forms register register_once alias unregister identify name_tag set_config people.set people.increment people.append people.track_charge people.clear_charges people.delete_user".split(" ");for(g=0;g<i.length;g++)f(c,i[g]);b._i.push([a,e,d])};b.__SV=1.2}})(document,window.mixpanel||[]);
112
102
  mixpanel.init("#{@token}");
113
103
  mixpanel.set_config(#{@options[:config].to_json});
114
104
  </script>
@@ -136,7 +126,7 @@ module Mixpanel
136
126
 
137
127
  def merge_queue!
138
128
  present_hash = {}
139
- special_events = ['identify', 'name_tag', 'people.set', 'register']
129
+ special_events = ['alias', 'identify', 'name_tag', 'people.set', 'register']
140
130
  queue.uniq!
141
131
 
142
132
  queue.reverse_each do |item|
@@ -1,5 +1,7 @@
1
1
  module Mixpanel::Person
2
- PERSON_PROPERTIES = %w{email created first_name last_name name last_login username country_code}
2
+ #from https://mixpanel.com/docs/people-analytics/special-properties
3
+ PERSON_PROPERTIES = %w{email created first_name last_name name last_login username country_code region city}
4
+ #from https://mixpanel.com/docs/people-analytics/people-http-specification-insert-data
3
5
  PERSON_REQUEST_PROPERTIES = %w{token distinct_id ip ignore_time}
4
6
  PERSON_URL = 'http://api.mixpanel.com/engage/'
5
7
 
@@ -11,6 +13,10 @@ module Mixpanel::Person
11
13
  engage :unset, distinct_id, property, options
12
14
  end
13
15
 
16
+ def set_once(distinct_id, properties={}, options={})
17
+ engage :set_once, distinct_id, properties, options
18
+ end
19
+
14
20
  def increment(distinct_id, properties={}, options={})
15
21
  engage :add, distinct_id, properties, options
16
22
  end
@@ -25,6 +31,10 @@ module Mixpanel::Person
25
31
  engage :append, distinct_id, charge_properties, options
26
32
  end
27
33
 
34
+ def delete(distinct_id)
35
+ engage 'delete', distinct_id, {}, {}
36
+ end
37
+
28
38
  def reset_charges(distinct_id, options={})
29
39
  engage :set, distinct_id, { '$transactions' => [] }, options
30
40
  end
@@ -33,6 +43,10 @@ module Mixpanel::Person
33
43
  append 'people.set', properties_hash(properties, PERSON_PROPERTIES)
34
44
  end
35
45
 
46
+ def append_set_once(properties = {})
47
+ append 'people.set_once', properties_hash(properties, PERSON_PROPERTIES)
48
+ end
49
+
36
50
  def append_increment(property, increment=1)
37
51
  append 'people.increment', property, increment
38
52
  end
@@ -49,12 +63,8 @@ module Mixpanel::Person
49
63
  append 'identify', distinct_id
50
64
  end
51
65
 
52
- def append_people_identify(distinct_id)
53
- append 'people.identify', distinct_id
54
- end
55
-
56
- def delete(distinct_id)
57
- engage 'delete', distinct_id, {}, {}
66
+ def append_alias(aliased_id)
67
+ append 'alias', aliased_id
58
68
  end
59
69
 
60
70
  protected
@@ -2,7 +2,7 @@ files = ['README.md', 'LICENSE', 'Rakefile', 'mixpanel.gemspec', '{spec,lib}/**/
2
2
 
3
3
  spec = Gem::Specification.new do |s|
4
4
  s.name = "mixpanel"
5
- s.version = "3.6.2"
5
+ s.version = "4.0.0"
6
6
  s.rubyforge_project = "mixpanel"
7
7
  s.description = "Simple lib to track events in Mixpanel service. It can be used in any rack based framework."
8
8
  s.author = "Alvaro Gil"
@@ -84,7 +84,7 @@ describe Mixpanel::Middleware do
84
84
  end
85
85
 
86
86
  it "should not append mixpanel scripts to head element" do
87
- last_response.body.index('var mp_protocol').should be_nil
87
+ last_response.body.index('window.mixpanel').should be_nil
88
88
  end
89
89
 
90
90
  it "should pass through if the document is not text/html content type" do
@@ -158,7 +158,7 @@ describe Mixpanel::Middleware do
158
158
  end
159
159
 
160
160
  it "should not append mixpanel scripts to head element" do
161
- last_response.body.index('var mp_protocol').should be_nil
161
+ last_response.body.index('window.mixpanel').should be_nil
162
162
  end
163
163
 
164
164
  it "should pass through if the document is not text/html content type" do
@@ -56,6 +56,10 @@ describe Mixpanel::Tracker do
56
56
  @mixpanel.set('person-a', { :email => 'me@domain.com', :likeable => false }).should == true
57
57
  end
58
58
 
59
+ it "should set an attribute once" do
60
+ @mixpanel.set_once('person-a', { :email => 'me@domain.com', :likeable => false }).should == true
61
+ end
62
+
59
63
  it "should set attributes with request properties" do
60
64
  @mixpanel.set({ :distinct_id => 'person-a', :ignore_time => true }, { :email => 'me@domain.com', :likeable => false }).should == true
61
65
  end
@@ -114,17 +118,17 @@ describe Mixpanel::Tracker do
114
118
  mixpanel_queue_should_include(@mixpanel, "identify", "some@one.com")
115
119
  end
116
120
 
117
- it "should allow people.identify to be called through the JS api" do
118
- @mixpanel.append_people_identify "an_identity"
119
- mixpanel_queue_should_include(@mixpanel, "people.identify", "an_identity")
120
- end
121
-
122
121
  it "should allow the tracking of super properties in JS" do
123
122
  props = {:user_id => 12345, :gender => 'male'}
124
123
  @mixpanel.append_register props
125
124
  mixpanel_queue_should_include(@mixpanel, 'register', props)
126
125
  end
127
126
 
127
+ it "should allow alias to be called through the JS api" do
128
+ @mixpanel.append_alias "new_id"
129
+ mixpanel_queue_should_include(@mixpanel, "alias", "new_id")
130
+ end
131
+
128
132
  it "should allow the one-time tracking of super properties in JS" do
129
133
  props = {:user_id => 12345, :gender => 'male'}
130
134
  @mixpanel.append_register_once props
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mixpanel
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.6.2
4
+ version: 4.0.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-04-16 00:00:00.000000000Z
12
+ date: 2013-04-18 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: json
16
- requirement: &2153447520 !ruby/object:Gem::Requirement
16
+ requirement: &2156195040 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '0'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *2153447520
24
+ version_requirements: *2156195040
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: rack
27
- requirement: &2153447080 !ruby/object:Gem::Requirement
27
+ requirement: &2156194600 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: '0'
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *2153447080
35
+ version_requirements: *2156194600
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: escape
38
- requirement: &2153446660 !ruby/object:Gem::Requirement
38
+ requirement: &2156194180 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ! '>='
@@ -43,10 +43,10 @@ dependencies:
43
43
  version: '0'
44
44
  type: :runtime
45
45
  prerelease: false
46
- version_requirements: *2153446660
46
+ version_requirements: *2156194180
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: rspec
49
- requirement: &2153446240 !ruby/object:Gem::Requirement
49
+ requirement: &2156193760 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ! '>='
@@ -54,10 +54,10 @@ dependencies:
54
54
  version: '0'
55
55
  type: :development
56
56
  prerelease: false
57
- version_requirements: *2153446240
57
+ version_requirements: *2156193760
58
58
  - !ruby/object:Gem::Dependency
59
59
  name: rack-test
60
- requirement: &2153445820 !ruby/object:Gem::Requirement
60
+ requirement: &2156193340 !ruby/object:Gem::Requirement
61
61
  none: false
62
62
  requirements:
63
63
  - - ! '>='
@@ -65,10 +65,10 @@ dependencies:
65
65
  version: '0'
66
66
  type: :development
67
67
  prerelease: false
68
- version_requirements: *2153445820
68
+ version_requirements: *2156193340
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: fakeweb
71
- requirement: &2153445400 !ruby/object:Gem::Requirement
71
+ requirement: &2156192920 !ruby/object:Gem::Requirement
72
72
  none: false
73
73
  requirements:
74
74
  - - ! '>='
@@ -76,10 +76,10 @@ dependencies:
76
76
  version: '0'
77
77
  type: :development
78
78
  prerelease: false
79
- version_requirements: *2153445400
79
+ version_requirements: *2156192920
80
80
  - !ruby/object:Gem::Dependency
81
81
  name: nokogiri
82
- requirement: &2153444980 !ruby/object:Gem::Requirement
82
+ requirement: &2156192500 !ruby/object:Gem::Requirement
83
83
  none: false
84
84
  requirements:
85
85
  - - ! '>='
@@ -87,10 +87,10 @@ dependencies:
87
87
  version: '0'
88
88
  type: :development
89
89
  prerelease: false
90
- version_requirements: *2153444980
90
+ version_requirements: *2156192500
91
91
  - !ruby/object:Gem::Dependency
92
92
  name: rake
93
- requirement: &2153470900 !ruby/object:Gem::Requirement
93
+ requirement: &2156218440 !ruby/object:Gem::Requirement
94
94
  none: false
95
95
  requirements:
96
96
  - - ! '>='
@@ -98,7 +98,7 @@ dependencies:
98
98
  version: '0'
99
99
  type: :development
100
100
  prerelease: false
101
- version_requirements: *2153470900
101
+ version_requirements: *2156218440
102
102
  description: Simple lib to track events in Mixpanel service. It can be used in any
103
103
  rack based framework.
104
104
  email: zevarito@gmail.com