mixpanel 2.0.2 → 2.1.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.
- data/README.md +6 -0
- data/lib/mixpanel/tracker.rb +4 -2
- data/lib/mixpanel/tracker/middleware.rb +2 -1
- data/mixpanel.gemspec +1 -1
- data/spec/mixpanel/tracker/middleware_spec.rb +17 -1
- data/spec/mixpanel/tracker_spec.rb +15 -8
- metadata +3 -3
data/README.md
CHANGED
@@ -67,6 +67,7 @@ Where **options** is a Hash that accepts the following keys:
|
|
67
67
|
* **config** : a Hash
|
68
68
|
|
69
69
|
*Default: {}*.
|
70
|
+
|
70
71
|
You can also pass Mixpanel configuration details as seen here
|
71
72
|
(https://mixpanel.com/docs/integration-libraries/javascript-full-api#set_config)
|
72
73
|
|
@@ -106,6 +107,10 @@ Where **options** is a Hash that accepts the following keys:
|
|
106
107
|
once.
|
107
108
|
*To enable persistence*, you must set it in both places, Middleware and when you initialize Mixpanel class.
|
108
109
|
|
110
|
+
*To enable import mode* you must set both :import => true and :api_key => YOUR_KEY (not to be confused with the project token.)
|
111
|
+
You can get more information about import mode here
|
112
|
+
(https://mixpanel.com/docs/api-documentation/importing-events-older-than-31-days)
|
113
|
+
|
109
114
|
### Track events directly.
|
110
115
|
|
111
116
|
```ruby
|
@@ -212,3 +217,4 @@ Use this instead:
|
|
212
217
|
* [Jamie Quint](https://github.com/jamiequint)
|
213
218
|
* [Ryan Schmukler](https://github.com/rschmukler)
|
214
219
|
* [Travis Pew](https://github.com/travisp)
|
220
|
+
* [Sylvain Niles](https://github.com/sylvainsf)
|
data/lib/mixpanel/tracker.rb
CHANGED
@@ -8,9 +8,11 @@ module Mixpanel
|
|
8
8
|
class Tracker
|
9
9
|
def initialize(token, env, options={})
|
10
10
|
@token = token
|
11
|
+
@api_key = options.fetch(:api_key, "")
|
11
12
|
@env = env
|
12
13
|
@async = options.fetch(:async, false)
|
13
|
-
@
|
14
|
+
@import = options.fetch(:import, false)
|
15
|
+
@url = @import ? 'http://api.mixpanel.com/import/?data' : options.fetch(:url, 'http://api.mixpanel.com/track/?data=')
|
14
16
|
@persist = options.fetch(:persist, false)
|
15
17
|
|
16
18
|
if @persist
|
@@ -116,7 +118,7 @@ module Mixpanel
|
|
116
118
|
|
117
119
|
def request(params)
|
118
120
|
data = Base64.encode64(JSON.generate(params)).gsub(/\n/,'')
|
119
|
-
url = @url + data
|
121
|
+
url = @import ? @url + "=" + data + '&api_key=' + @api_key : @url + data
|
120
122
|
|
121
123
|
if(@async)
|
122
124
|
w = Tracker.worker
|
@@ -18,7 +18,7 @@ module Mixpanel
|
|
18
18
|
@env = env
|
19
19
|
|
20
20
|
@status, @headers, @response = @app.call(env)
|
21
|
-
|
21
|
+
|
22
22
|
if is_trackable_response?
|
23
23
|
merge_queue! if @options[:persist]
|
24
24
|
update_response!
|
@@ -71,6 +71,7 @@ module Mixpanel
|
|
71
71
|
|
72
72
|
def is_trackable_response?
|
73
73
|
return false if @status == 302
|
74
|
+
return false if @env.has_key?("HTTP_SKIP_MIXPANEL_MIDDLEWARE")
|
74
75
|
is_html_response? || is_javascript_response?
|
75
76
|
end
|
76
77
|
|
data/mixpanel.gemspec
CHANGED
@@ -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 = "2.0
|
5
|
+
s.version = "2.1.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"
|
@@ -31,7 +31,23 @@ describe Mixpanel::Tracker::Middleware do
|
|
31
31
|
last_response.body.should == html_document
|
32
32
|
end
|
33
33
|
end
|
34
|
-
|
34
|
+
|
35
|
+
describe "Dummy app, handles skip requests properly" do
|
36
|
+
before do
|
37
|
+
setup_rack_application(DummyApp, {:body => html_document, :headers => {"Content-Type" => "text/html"}})
|
38
|
+
end
|
39
|
+
|
40
|
+
it "should not append mixpanel scripts with skip request" do
|
41
|
+
get "/", {}, {"HTTP_SKIP_MIXPANEL_MIDDLEWARE" => true}
|
42
|
+
Nokogiri::HTML(last_response.body).search('script').should be_empty
|
43
|
+
end
|
44
|
+
|
45
|
+
it "should append mixpanel scripts without skip request" do
|
46
|
+
get "/"
|
47
|
+
Nokogiri::HTML(last_response.body).search('script').size.should == 1
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
35
51
|
describe "Appending async mixpanel scripts" do
|
36
52
|
describe "With ajax requests" do
|
37
53
|
before do
|
@@ -69,12 +69,12 @@ describe Mixpanel::Tracker do
|
|
69
69
|
@mixpanel.append_event("Sign up", {:referer => 'http://example.com'})
|
70
70
|
@mixpanel.queue.size.should == 1
|
71
71
|
end
|
72
|
-
|
72
|
+
|
73
73
|
it "should provide direct access to the JS api" do
|
74
74
|
@mixpanel.append_api('track', "Sign up", {:referer => 'http://example.com'})
|
75
75
|
mixpanel_queue_should_include(@mixpanel, "track", "Sign up", {:referer => 'http://example.com'})
|
76
76
|
end
|
77
|
-
|
77
|
+
|
78
78
|
it "should allow identify to be called through the JS api" do
|
79
79
|
@mixpanel.append_api('identify', "some@one.com")
|
80
80
|
mixpanel_queue_should_include(@mixpanel, "identify", "some@one.com")
|
@@ -84,32 +84,32 @@ describe Mixpanel::Tracker do
|
|
84
84
|
@mixpanel.append_api('identify', "some@one.com")
|
85
85
|
mixpanel_queue_should_include(@mixpanel, "identify", "some@one.com")
|
86
86
|
end
|
87
|
-
|
87
|
+
|
88
88
|
it "should allow the tracking of super properties in JS" do
|
89
89
|
@mixpanel.append_api('register', {:user_id => 12345, :email => "some@one.com"})
|
90
90
|
mixpanel_queue_should_include(@mixpanel, 'register', {:user_id => 12345, :email => "some@one.com"})
|
91
91
|
end
|
92
92
|
end
|
93
93
|
end
|
94
|
-
|
94
|
+
|
95
95
|
context "Accessing Mixpanel asynchronously" do
|
96
96
|
it "should open a subprocess successfully" do
|
97
97
|
w = Mixpanel::Tracker.worker
|
98
98
|
w.should == Mixpanel::Tracker.worker
|
99
99
|
end
|
100
|
-
|
100
|
+
|
101
101
|
it "should be able to write lines to the worker" do
|
102
102
|
w = Mixpanel::Tracker.worker
|
103
|
-
|
103
|
+
|
104
104
|
#On most systems this will exceed the pipe buffer size
|
105
105
|
8.times do
|
106
|
-
9000.times do
|
106
|
+
9000.times do
|
107
107
|
w.write("\n")
|
108
108
|
end
|
109
109
|
sleep 0.1
|
110
110
|
end
|
111
111
|
end
|
112
|
-
|
112
|
+
|
113
113
|
it "should dispose of a worker" do
|
114
114
|
w = Mixpanel::Tracker.worker
|
115
115
|
Mixpanel::Tracker.dispose_worker(w)
|
@@ -119,4 +119,11 @@ describe Mixpanel::Tracker do
|
|
119
119
|
w2.should_not == w
|
120
120
|
end
|
121
121
|
end
|
122
|
+
|
123
|
+
context "Import mode" do
|
124
|
+
it "should use the import URL" do
|
125
|
+
@mixpanel = Mixpanel::Tracker.new(MIX_PANEL_TOKEN, @env = {"REMOTE_ADDR" => "127.0.0.1"}, { :import => true, :api_key => "ABCDEFG" })
|
126
|
+
@mixpanel.inspect.to_s.include?("import/?data").should == true
|
127
|
+
end
|
128
|
+
end
|
122
129
|
end
|
metadata
CHANGED
@@ -5,9 +5,9 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 2
|
8
|
+
- 1
|
8
9
|
- 0
|
9
|
-
|
10
|
-
version: 2.0.2
|
10
|
+
version: 2.1.0
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Alvaro Gil
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2012-09-
|
18
|
+
date: 2012-09-17 00:00:00 -03:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|