mixpanel 4.0.3 → 4.0.4
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +2 -1
- data/lib/mixpanel/middleware.rb +2 -1
- data/mixpanel.gemspec +1 -1
- data/spec/mixpanel/middleware_spec.rb +20 -6
- data/spec/support/rack_apps.rb +13 -2
- metadata +18 -18
data/README.md
CHANGED
data/lib/mixpanel/middleware.rb
CHANGED
@@ -53,7 +53,8 @@ module Mixpanel
|
|
53
53
|
end
|
54
54
|
end
|
55
55
|
elsif is_turbolink_request? && is_html_response?
|
56
|
-
part.
|
56
|
+
insert_at = part.index('</body')
|
57
|
+
part.insert(insert_at, render_event_tracking_scripts) unless insert_at.nil? or queue.empty?
|
57
58
|
elsif is_ajax_request? && is_html_response?
|
58
59
|
part.insert(0, render_event_tracking_scripts) unless queue.empty?
|
59
60
|
elsif is_ajax_request? && is_javascript_response?
|
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 = "4.0.
|
5
|
+
s.version = "4.0.4"
|
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"
|
@@ -8,7 +8,6 @@ def exec_default_appends_on(mixpanel)
|
|
8
8
|
end
|
9
9
|
|
10
10
|
def check_for_default_appends_on(txt)
|
11
|
-
|
12
11
|
txt.should =~ /mixpanel\.track\("Visit",\s?\{.*"article":1/
|
13
12
|
txt.should =~ /mixpanel\.track\("Sign in",\s?\{.*"time":.*\}/
|
14
13
|
txt.should =~ /mixpanel\.people\.set\(.*\);\nmixpanel.people.increment\(\"sign_in_rate\",\s?1\);/
|
@@ -21,7 +20,7 @@ end
|
|
21
20
|
|
22
21
|
describe Mixpanel::Middleware do
|
23
22
|
include Rack::Test::Methods
|
24
|
-
|
23
|
+
|
25
24
|
describe "Dummy apps, no text/html" do
|
26
25
|
before do
|
27
26
|
setup_rack_application(DummyApp, :body => html_document, :headers => {})
|
@@ -32,17 +31,17 @@ describe Mixpanel::Middleware do
|
|
32
31
|
last_response.body.should == html_document
|
33
32
|
end
|
34
33
|
end
|
35
|
-
|
34
|
+
|
36
35
|
describe "Dummy app, handles skip requests properly" do
|
37
36
|
before do
|
38
37
|
setup_rack_application(DummyApp, {:body => html_document, :headers => {"Content-Type" => "text/html"}})
|
39
38
|
end
|
40
|
-
|
39
|
+
|
41
40
|
it "should not append mixpanel scripts with skip request" do
|
42
41
|
get "/", {}, {"HTTP_SKIP_MIXPANEL_MIDDLEWARE" => true}
|
43
42
|
Nokogiri::HTML(last_response.body).search('script').should be_empty
|
44
43
|
end
|
45
|
-
|
44
|
+
|
46
45
|
it "should append mixpanel scripts without skip request" do
|
47
46
|
get "/"
|
48
47
|
Nokogiri::HTML(last_response.body).search('script').size.should == 1
|
@@ -66,7 +65,7 @@ describe Mixpanel::Middleware do
|
|
66
65
|
|
67
66
|
end
|
68
67
|
end
|
69
|
-
|
68
|
+
|
70
69
|
describe "Appending async mixpanel scripts" do
|
71
70
|
describe "With ajax requests" do
|
72
71
|
before do
|
@@ -293,6 +292,21 @@ describe Mixpanel::Middleware do
|
|
293
292
|
last_request.env.has_key?("mixpanel_events").should == false
|
294
293
|
end
|
295
294
|
end
|
295
|
+
|
296
|
+
describe "With turbolinks" do
|
297
|
+
before do
|
298
|
+
setup_rack_application(DummyApp, {
|
299
|
+
:body => ['',html_document],
|
300
|
+
:headers => {'Content-Type' => 'text/html'}
|
301
|
+
}, {:insert_js_last => true})
|
302
|
+
get '/', {}, {'HTTP_X_XHR_REFERER' => '/', 'mixpanel_events' => @mixpanel.queue}
|
303
|
+
end
|
304
|
+
|
305
|
+
it "should append mixpanel scripts to end of body element" do
|
306
|
+
Nokogiri::HTML(last_response.body).search('head script').should be_empty
|
307
|
+
Nokogiri::HTML(last_response.body).search('body script').should_not be_empty
|
308
|
+
end
|
309
|
+
end
|
296
310
|
end
|
297
311
|
|
298
312
|
describe "Tracking appended events" do
|
data/spec/support/rack_apps.rb
CHANGED
@@ -18,11 +18,22 @@ class DummyApp
|
|
18
18
|
@response_with = {}
|
19
19
|
@response_with[:status] = options[:status] || "200"
|
20
20
|
@response_with[:headers] = options[:headers] || {}
|
21
|
-
@response_with[:body] = options[:body] ||
|
21
|
+
@response_with[:body] = wrap(options[:body] || '')
|
22
22
|
end
|
23
23
|
|
24
24
|
def call(env)
|
25
|
-
[@response_with[:status], @response_with[:headers],
|
25
|
+
[@response_with[:status], @response_with[:headers], @response_with[:body]]
|
26
|
+
end
|
27
|
+
|
28
|
+
private
|
29
|
+
def wrap(object)
|
30
|
+
if object.nil?
|
31
|
+
[]
|
32
|
+
elsif object.respond_to?(:to_ary)
|
33
|
+
object.to_ary || [object]
|
34
|
+
else
|
35
|
+
[object]
|
36
|
+
end
|
26
37
|
end
|
27
38
|
end
|
28
39
|
|
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.
|
4
|
+
version: 4.0.4
|
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-08-
|
12
|
+
date: 2013-08-17 00:00:00.000000000Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: json
|
16
|
-
requirement: &
|
16
|
+
requirement: &2153530540 !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: *
|
24
|
+
version_requirements: *2153530540
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: rack
|
27
|
-
requirement: &
|
27
|
+
requirement: &2153530100 !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: *
|
35
|
+
version_requirements: *2153530100
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: escape
|
38
|
-
requirement: &
|
38
|
+
requirement: &2153529680 !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: *
|
46
|
+
version_requirements: *2153529680
|
47
47
|
- !ruby/object:Gem::Dependency
|
48
48
|
name: rspec
|
49
|
-
requirement: &
|
49
|
+
requirement: &2153529260 !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: *
|
57
|
+
version_requirements: *2153529260
|
58
58
|
- !ruby/object:Gem::Dependency
|
59
59
|
name: rack-test
|
60
|
-
requirement: &
|
60
|
+
requirement: &2153555180 !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: *
|
68
|
+
version_requirements: *2153555180
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: fakeweb
|
71
|
-
requirement: &
|
71
|
+
requirement: &2153554760 !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: *
|
79
|
+
version_requirements: *2153554760
|
80
80
|
- !ruby/object:Gem::Dependency
|
81
81
|
name: nokogiri
|
82
|
-
requirement: &
|
82
|
+
requirement: &2153554340 !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: *
|
90
|
+
version_requirements: *2153554340
|
91
91
|
- !ruby/object:Gem::Dependency
|
92
92
|
name: rake
|
93
|
-
requirement: &
|
93
|
+
requirement: &2153553920 !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: *
|
101
|
+
version_requirements: *2153553920
|
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
|