mixpanel 3.4.0 → 3.5.0

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -259,7 +259,7 @@ Example using `distinct_id` to identify the user:
259
259
  Example using request properties, telling mixpanel to [ignore the time](https://groups.google.com/forum/#!msg/mp-dev/Ao4f8D0IKms/6MVhQqFDzL8J):
260
260
 
261
261
  ```ruby
262
- @mixpanel.set { :distinct_id => 'john-doe', :ignore_time => true }, { :age => 31, :email => 'john@doe.com' }
262
+ @mixpanel.set({ :distinct_id => 'john-doe', :ignore_time => true }, { :age => 31, :email => 'john@doe.com' })
263
263
  ```
264
264
 
265
265
  ### Increment Person Attributes Directly
@@ -277,6 +277,26 @@ Example:
277
277
  @mixpanel.increment 'john-doe', { :tokens => 5, :coins => -4 }
278
278
  ```
279
279
 
280
+ ### Track Charges for Revenue Directly
281
+
282
+ ```ruby
283
+ @mixpanel.track_charge distinct_id, amount, time, options
284
+ ```
285
+
286
+ This allows you to use the Revenue tab in your mixpanel dashboard.
287
+
288
+ Example:
289
+
290
+ ```ruby
291
+ @mixpanel.track_charge 'john-doe', 20.00
292
+ ```
293
+
294
+ If you need to remove accidental charges for a person, you can use:
295
+
296
+ ```ruby
297
+ @mixpanel.reset_charges distinct_id
298
+ ```
299
+
280
300
  ### Append Events To Be Tracked With Javascript
281
301
 
282
302
  *Note*: You should setup the [Rack Middleware](#rack-middleware).
@@ -413,3 +433,5 @@ end
413
433
  * [Ahmed Belal](https://github.com/AhmedBelal)
414
434
  * [Esteban Pastorino](https://github.com/kitop)
415
435
  * [Jeffrey Chu](https://github.com/jochu)
436
+ * [Jon Pospischil] (https://github.com/pospischil)
437
+ * [Tom Brown] (https://github.com/nottombrown)
@@ -38,6 +38,8 @@ module Mixpanel
38
38
  part.insert(insert_at, render_event_tracking_scripts) unless queue.empty?
39
39
  part.insert(insert_at, render_mixpanel_scripts) #This will insert the mixpanel initialization code before the queue of tracking events.
40
40
  end
41
+ elsif is_turbolink_request? && is_html_response?
42
+ part.insert(part.index('</body'), render_event_tracking_scripts) unless queue.empty?
41
43
  elsif is_ajax_request? && is_html_response?
42
44
  part.insert(0, render_event_tracking_scripts) unless queue.empty?
43
45
  elsif is_ajax_request? && is_javascript_response?
@@ -53,7 +55,11 @@ module Mixpanel
53
55
  end
54
56
 
55
57
  def is_regular_request?
56
- !is_ajax_request?
58
+ !is_ajax_request? && !is_turbolink_request?
59
+ end
60
+
61
+ def is_turbolink_request?
62
+ @env.has_key?("HTTP_X_XHR_REFERER")
57
63
  end
58
64
 
59
65
  def is_ajax_request?
@@ -133,7 +139,7 @@ module Mixpanel
133
139
  return "" if queue.empty?
134
140
 
135
141
  output = queue.map {|type, arguments| %(mixpanel.#{type}(#{arguments.join(', ')});) }.join("\n")
136
- output = "try {#{output}} catch(err) {}"
142
+ output = "try {#{output}} catch(err) {};"
137
143
 
138
144
  include_script_tag ? "<script type='text/javascript'>#{output}</script>" : output
139
145
  end
@@ -11,6 +11,20 @@ module Mixpanel::Person
11
11
  engage :add, distinct_id, properties, options
12
12
  end
13
13
 
14
+ def track_charge(distinct_id, amount, time=Time.now, options={})
15
+ charge_properties = {
16
+ '$transactions' => {
17
+ '$amount' => amount,
18
+ '$time' => time,
19
+ }
20
+ }
21
+ engage :append, distinct_id, charge_properties, options
22
+ end
23
+
24
+ def reset_charges(distinct_id, options={})
25
+ engage :set, distinct_id, { '$transactions' => [] }, options
26
+ end
27
+
14
28
  def append_set(properties={})
15
29
  append 'people.set', properties_hash(properties, PERSON_PROPERTIES)
16
30
  end
@@ -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.4.0"
5
+ s.version = "3.5.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"
@@ -63,6 +63,14 @@ describe Mixpanel::Tracker do
63
63
  it "should increment attributes" do
64
64
  @mixpanel.increment('person-a', { :tokens => 3, :money => -1 }).should == true
65
65
  end
66
+
67
+ it "should track charges" do
68
+ @mixpanel.track_charge('person-a', 20.0).should == true
69
+ end
70
+
71
+ it "should reset charges" do
72
+ @mixpanel.reset_charges('person-a').should == true
73
+ end
66
74
  end
67
75
  end
68
76
 
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.4.0
4
+ version: 3.5.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: 2012-12-23 00:00:00.000000000Z
12
+ date: 2013-01-18 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: json
16
- requirement: &2153080840 !ruby/object:Gem::Requirement
16
+ requirement: &2153110960 !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: *2153080840
24
+ version_requirements: *2153110960
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: rack
27
- requirement: &2153080400 !ruby/object:Gem::Requirement
27
+ requirement: &2153110520 !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: *2153080400
35
+ version_requirements: *2153110520
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: escape
38
- requirement: &2153079980 !ruby/object:Gem::Requirement
38
+ requirement: &2153110100 !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: *2153079980
46
+ version_requirements: *2153110100
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: rspec
49
- requirement: &2153079560 !ruby/object:Gem::Requirement
49
+ requirement: &2153109680 !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: *2153079560
57
+ version_requirements: *2153109680
58
58
  - !ruby/object:Gem::Dependency
59
59
  name: rack-test
60
- requirement: &2153079140 !ruby/object:Gem::Requirement
60
+ requirement: &2153109260 !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: *2153079140
68
+ version_requirements: *2153109260
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: fakeweb
71
- requirement: &2153078720 !ruby/object:Gem::Requirement
71
+ requirement: &2153108840 !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: *2153078720
79
+ version_requirements: *2153108840
80
80
  - !ruby/object:Gem::Dependency
81
81
  name: nokogiri
82
- requirement: &2153078300 !ruby/object:Gem::Requirement
82
+ requirement: &2153108420 !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: *2153078300
90
+ version_requirements: *2153108420
91
91
  - !ruby/object:Gem::Dependency
92
92
  name: rake
93
- requirement: &2153104240 !ruby/object:Gem::Requirement
93
+ requirement: &2153108000 !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: *2153104240
101
+ version_requirements: *2153108000
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