mixpanel 4.0.2 → 4.0.3

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -12,6 +12,7 @@
12
12
  - [Initialize Mixpanel] (#initialize-mixpanel)
13
13
  - [Track Events Directly](#track-events-directly)
14
14
  - [Pixel Based Event Tracking](#pixel-based-event-tracking)
15
+ - [Redirect Based Event Tracking](#redirect-based-event-tracking)
15
16
  - [Import Events](#import-events)
16
17
  - [Set Person Attributes Directly](#set-person-attributes-directly)
17
18
  - [Increment Person Attributes Directly](#increment-person-attributes-directly)
@@ -193,6 +194,12 @@ it will automatically be converted to the correct form (e.g., `{ :os => 'Mac' }`
193
194
 
194
195
  This can be used to proxy Mixpanel API requests.
195
196
 
197
+ * **test**: boolean
198
+
199
+ *Default: false*
200
+
201
+ Send data to a high priority rate limited queue to make testing easier
202
+
196
203
  Example:
197
204
 
198
205
  ```ruby
@@ -222,7 +229,13 @@ image_tag @mixpanel.tracking_pixel("Opened Email", { :distinct_id => "bob@email.
222
229
 
223
230
  Mixpanel docs: https://mixpanel.com/docs/api-documentation/pixel-based-event-tracking
224
231
 
232
+ ### Redirect Based Event Tracking
233
+
234
+ ```ruby
235
+ @mixpanel.redirect_url "Opened Email", 'http://www.example.com/' { :distinct_id => "bob@email.com", :campaign => "Retarget" }
236
+ ```
225
237
 
238
+ This allows to track events just when a user clicks a link. It's usually useful for tracking opened emails.
226
239
 
227
240
  ### Import Events
228
241
 
@@ -533,3 +546,4 @@ MixPanel.track("Front Page Load", {
533
546
  * [Marko Vasiljevic] (https://github.com/marmarko)
534
547
  * [Joel] (https://github.com/jclay)
535
548
  * [adimichele] (https://github.com/adimichele)
549
+ * [Francis Gulotta] (https://github.com/reconbot)
@@ -11,6 +11,10 @@ module Mixpanel::Event
11
11
  build_url event, properties, options.merge(:url => TRACK_URL, :img => true)
12
12
  end
13
13
 
14
+ def redirect_url(event, redirect, properties={}, options={})
15
+ build_url event, properties, options.merge(:url => TRACK_URL, :redirect => CGI::escape(redirect))
16
+ end
17
+
14
18
  def import(event, properties={}, options={})
15
19
  track_event event, properties, options, IMPORT_URL
16
20
  end
@@ -52,6 +56,8 @@ module Mixpanel::Event
52
56
  url = "#{options[:url]}?data=#{encoded_data(data)}"
53
57
  url << "&api_key=#{options[:api_key]}" if options.fetch(:api_key, nil)
54
58
  url << "&img=1" if options[:img]
59
+ url << "&test=1" if options[:test]
60
+ url << "&redirect=#{options[:redirect]}" if options[:redirect]
55
61
  url
56
62
  end
57
63
  end
@@ -89,7 +89,7 @@ module Mixpanel
89
89
  end
90
90
 
91
91
  def is_trackable_response?
92
- return false if @status == 302
92
+ return false if (300..399).include?(@status.to_i)
93
93
  return false if @env.has_key?("HTTP_SKIP_MIXPANEL_MIDDLEWARE")
94
94
  is_html_response? || is_javascript_response?
95
95
  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 = "4.0.2"
5
+ s.version = "4.0.3"
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"
@@ -48,6 +48,12 @@ describe Mixpanel::Middleware do
48
48
  Nokogiri::HTML(last_response.body).search('script').size.should == 1
49
49
  end
50
50
 
51
+ it "should skip requests in the 3xx range" do
52
+ setup_rack_application(DummyApp, :body => html_document, :headers => {"Content-Type" => "text/html"}, :status => 350)
53
+ get "/"
54
+ Nokogiri::HTML(last_response.body).search('script').should be_empty
55
+ end
56
+
51
57
  context "when disabling with #skip_this_request" do
52
58
  before{ Mixpanel::Middleware.skip_this_request }
53
59
 
@@ -41,6 +41,20 @@ describe Mixpanel::Tracker do
41
41
  end
42
42
  end
43
43
 
44
+ context "Redirect url" do
45
+ let(:url) { "http://example.com?foo=bar&bar=foo" }
46
+
47
+ it "should return a URL" do
48
+ @mixpanel.redirect_url("Click Email", url).should be_a(String)
49
+ end
50
+
51
+ it "should include a redirect" do
52
+ encoded_url = CGI::escape(url)
53
+ @mixpanel.redirect_url("Click Email", url).should include('&redirect=' + encoded_url)
54
+ end
55
+
56
+ end
57
+
44
58
  context "Importing events" do
45
59
  it "should import simple events" do
46
60
  @mixpanel.import('Sign up').should == true
@@ -2,6 +2,7 @@ require File.join(File.dirname(__FILE__), "../lib", "mixpanel")
2
2
  require 'rack/test'
3
3
  require 'fakeweb'
4
4
  require 'nokogiri'
5
+ require 'cgi'
5
6
 
6
7
  Dir[File.expand_path(File.join(File.dirname(__FILE__),'support','**','*.rb'))].each {|f| require f}
7
8
 
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: 4.0.2
4
+ version: 4.0.3
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-05-23 00:00:00.000000000Z
12
+ date: 2013-08-01 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: json
16
- requirement: &2153678160 !ruby/object:Gem::Requirement
16
+ requirement: &2153703060 !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: *2153678160
24
+ version_requirements: *2153703060
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: rack
27
- requirement: &2153677720 !ruby/object:Gem::Requirement
27
+ requirement: &2153702620 !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: *2153677720
35
+ version_requirements: *2153702620
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: escape
38
- requirement: &2153677300 !ruby/object:Gem::Requirement
38
+ requirement: &2153702200 !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: *2153677300
46
+ version_requirements: *2153702200
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: rspec
49
- requirement: &2153676880 !ruby/object:Gem::Requirement
49
+ requirement: &2153701780 !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: *2153676880
57
+ version_requirements: *2153701780
58
58
  - !ruby/object:Gem::Dependency
59
59
  name: rack-test
60
- requirement: &2153676460 !ruby/object:Gem::Requirement
60
+ requirement: &2153701360 !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: *2153676460
68
+ version_requirements: *2153701360
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: fakeweb
71
- requirement: &2153676040 !ruby/object:Gem::Requirement
71
+ requirement: &2153700940 !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: *2153676040
79
+ version_requirements: *2153700940
80
80
  - !ruby/object:Gem::Dependency
81
81
  name: nokogiri
82
- requirement: &2153675620 !ruby/object:Gem::Requirement
82
+ requirement: &2153700520 !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: *2153675620
90
+ version_requirements: *2153700520
91
91
  - !ruby/object:Gem::Dependency
92
92
  name: rake
93
- requirement: &2153701540 !ruby/object:Gem::Requirement
93
+ requirement: &2153700100 !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: *2153701540
101
+ version_requirements: *2153700100
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