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 CHANGED
@@ -511,10 +511,11 @@ MixPanel.track("Front Page Load", {
511
511
 
512
512
  ## Supported Ruby Platforms
513
513
 
514
- - 1.8.7
514
+ - 1.8.7 [Not supported anymore]
515
515
  - 1.9.2
516
516
  - 1.9.3
517
517
  - JRuby 1.8 Mode
518
+ - JRuby 1.9 Mode
518
519
 
519
520
  ## Deprecation Notes
520
521
 
@@ -53,7 +53,8 @@ module Mixpanel
53
53
  end
54
54
  end
55
55
  elsif is_turbolink_request? && is_html_response?
56
- part.insert(part.index('</body'), render_event_tracking_scripts) unless queue.empty?
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.3"
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
@@ -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], [@response_with[:body]]]
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.3
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-01 00:00:00.000000000Z
12
+ date: 2013-08-17 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: json
16
- requirement: &2153703060 !ruby/object:Gem::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: *2153703060
24
+ version_requirements: *2153530540
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: rack
27
- requirement: &2153702620 !ruby/object:Gem::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: *2153702620
35
+ version_requirements: *2153530100
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: escape
38
- requirement: &2153702200 !ruby/object:Gem::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: *2153702200
46
+ version_requirements: *2153529680
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: rspec
49
- requirement: &2153701780 !ruby/object:Gem::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: *2153701780
57
+ version_requirements: *2153529260
58
58
  - !ruby/object:Gem::Dependency
59
59
  name: rack-test
60
- requirement: &2153701360 !ruby/object:Gem::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: *2153701360
68
+ version_requirements: *2153555180
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: fakeweb
71
- requirement: &2153700940 !ruby/object:Gem::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: *2153700940
79
+ version_requirements: *2153554760
80
80
  - !ruby/object:Gem::Dependency
81
81
  name: nokogiri
82
- requirement: &2153700520 !ruby/object:Gem::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: *2153700520
90
+ version_requirements: *2153554340
91
91
  - !ruby/object:Gem::Dependency
92
92
  name: rake
93
- requirement: &2153700100 !ruby/object:Gem::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: *2153700100
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