mixpanel_rails 0.0.5 → 0.0.6
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/.gitignore +2 -0
- data/lib/mixpanel_rails.rb +3 -1
- data/lib/mixpanel_rails/version.rb +1 -1
- data/mixpanel_rails.gemspec +7 -0
- data/spec/app/app/views/layouts/application.html.erb +9 -0
- data/spec/app/fake.rb +18 -0
- data/spec/mixpanel_rails_spec.rb +79 -0
- data/spec/spec_helper.rb +5 -0
- metadata +80 -6
data/.gitignore
CHANGED
data/lib/mixpanel_rails.rb
CHANGED
@@ -32,7 +32,9 @@ module MixpanelRails
|
|
32
32
|
unless response.redirect_url && request.host == URI.parse(response.redirect_url).host
|
33
33
|
mixpanel = Mixpanel::Tracker.new(MixpanelRails::Railtie.config.mixpanel_rails.token, request.env, true)
|
34
34
|
distinct_id = mixpanel_distinct_id.bind(self).call
|
35
|
-
params = {
|
35
|
+
params = {}
|
36
|
+
params[:distinct_id] = distinct_id if distinct_id
|
37
|
+
params.merge!(register_with_mixpanel)
|
36
38
|
if request.env["Rack-Middleware-PDFKit"] || response.redirect_url
|
37
39
|
mixpanel_queue.each {|s| mixpanel.track_event(s, params) }
|
38
40
|
else
|
data/mixpanel_rails.gemspec
CHANGED
@@ -19,4 +19,11 @@ Gem::Specification.new do |s|
|
|
19
19
|
s.require_paths = ["lib"]
|
20
20
|
|
21
21
|
s.add_dependency 'mixpanel', '~> 1.0.0'
|
22
|
+
s.add_dependency 'rails', '~> 3.0'
|
23
|
+
|
24
|
+
s.add_development_dependency 'rspec', '~> 2.5'
|
25
|
+
s.add_development_dependency 'capybara', '~> 1.1.1'
|
26
|
+
s.add_development_dependency 'steak'
|
27
|
+
s.add_development_dependency 'steak'
|
28
|
+
s.add_development_dependency 'rspec-rails'
|
22
29
|
end
|
data/spec/app/fake.rb
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'bundler/setup'
|
2
|
+
require 'rails'
|
3
|
+
Bundler.require(:default, Rails.env)
|
4
|
+
require 'action_controller/railtie'
|
5
|
+
require 'action_view/railtie'
|
6
|
+
|
7
|
+
app = Class.new(Rails::Application)
|
8
|
+
app.config.root = File.dirname(__FILE__)
|
9
|
+
app.config.secret_token = "3b7cd727ee24e8444053437c36cc66c4"
|
10
|
+
app.config.active_support.deprecation = :log
|
11
|
+
app.config.mixpanel_rails.token = "test_token"
|
12
|
+
app.initialize!
|
13
|
+
|
14
|
+
app.routes.draw do
|
15
|
+
match ':controller(/:action(/:id))'
|
16
|
+
end
|
17
|
+
|
18
|
+
class ApplicationController < ActionController::Base; end
|
@@ -0,0 +1,79 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
2
|
+
|
3
|
+
class ExampleController < ApplicationController
|
4
|
+
uses_mixpanel
|
5
|
+
|
6
|
+
def no_tracking
|
7
|
+
render inline: "OK", layout: true
|
8
|
+
end
|
9
|
+
|
10
|
+
def with_tracking
|
11
|
+
track_with_mixpanel "Register for site"
|
12
|
+
render inline: "OK", layout: true
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
class RedirectsController < ApplicationController
|
17
|
+
uses_mixpanel
|
18
|
+
|
19
|
+
def index
|
20
|
+
track_with_mixpanel "Register for site"
|
21
|
+
redirect_to action: :redirected
|
22
|
+
end
|
23
|
+
|
24
|
+
def redirected
|
25
|
+
render inline: "OK", layout: true
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
class DistinctIdController < ApplicationController
|
30
|
+
uses_mixpanel distinct_id: lambda { 1 }
|
31
|
+
|
32
|
+
def index
|
33
|
+
render inline: "OK", layout: true
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
shared_examples_for "mixpanel init" do
|
38
|
+
it do
|
39
|
+
page.find("script:first").text.should include('mpq.push(["init", "test_token"]);')
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
shared_examples_for "without distinct id" do
|
44
|
+
it { page.find("script:last").text.should_not include('distinct_id') }
|
45
|
+
end
|
46
|
+
|
47
|
+
shared_examples_for "with distinct id" do
|
48
|
+
it { page.find("script:last").text.should include('mpq.push(["register", {"distinct_id":1}]);') }
|
49
|
+
end
|
50
|
+
|
51
|
+
shared_examples_for "with event" do
|
52
|
+
it { page.find("script:last").text.should include('mpq.push(["track", "Register for site"])') }
|
53
|
+
end
|
54
|
+
|
55
|
+
feature 'mixpanel integration' do
|
56
|
+
context 'visit page without tracking' do
|
57
|
+
background { visit '/example/no_tracking' }
|
58
|
+
it_should_behave_like "mixpanel init"
|
59
|
+
it_should_behave_like "without distinct id"
|
60
|
+
end
|
61
|
+
|
62
|
+
context 'visit page with tracking' do
|
63
|
+
background { visit '/example/with_tracking' }
|
64
|
+
it_should_behave_like "mixpanel init"
|
65
|
+
it_should_behave_like "without distinct id"
|
66
|
+
it_should_behave_like "with event"
|
67
|
+
end
|
68
|
+
|
69
|
+
context 'visit page with distinct id' do
|
70
|
+
background { visit '/distinct_id' }
|
71
|
+
it_should_behave_like "mixpanel init"
|
72
|
+
it_should_behave_like "with distinct id"
|
73
|
+
end
|
74
|
+
|
75
|
+
context 'follow redirect' do
|
76
|
+
background { visit '/redirects' }
|
77
|
+
it_should_behave_like "with event"
|
78
|
+
end
|
79
|
+
end
|
data/spec/spec_helper.rb
ADDED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mixpanel_rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.6
|
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-03
|
12
|
+
date: 2012-04-03 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: mixpanel
|
16
|
-
requirement: &
|
16
|
+
requirement: &2152529300 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ~>
|
@@ -21,7 +21,73 @@ dependencies:
|
|
21
21
|
version: 1.0.0
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *2152529300
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: rails
|
27
|
+
requirement: &2152527360 !ruby/object:Gem::Requirement
|
28
|
+
none: false
|
29
|
+
requirements:
|
30
|
+
- - ~>
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '3.0'
|
33
|
+
type: :runtime
|
34
|
+
prerelease: false
|
35
|
+
version_requirements: *2152527360
|
36
|
+
- !ruby/object:Gem::Dependency
|
37
|
+
name: rspec
|
38
|
+
requirement: &2152525920 !ruby/object:Gem::Requirement
|
39
|
+
none: false
|
40
|
+
requirements:
|
41
|
+
- - ~>
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: '2.5'
|
44
|
+
type: :development
|
45
|
+
prerelease: false
|
46
|
+
version_requirements: *2152525920
|
47
|
+
- !ruby/object:Gem::Dependency
|
48
|
+
name: capybara
|
49
|
+
requirement: &2152524860 !ruby/object:Gem::Requirement
|
50
|
+
none: false
|
51
|
+
requirements:
|
52
|
+
- - ~>
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 1.1.1
|
55
|
+
type: :development
|
56
|
+
prerelease: false
|
57
|
+
version_requirements: *2152524860
|
58
|
+
- !ruby/object:Gem::Dependency
|
59
|
+
name: steak
|
60
|
+
requirement: &2152554560 !ruby/object:Gem::Requirement
|
61
|
+
none: false
|
62
|
+
requirements:
|
63
|
+
- - ! '>='
|
64
|
+
- !ruby/object:Gem::Version
|
65
|
+
version: '0'
|
66
|
+
type: :development
|
67
|
+
prerelease: false
|
68
|
+
version_requirements: *2152554560
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: steak
|
71
|
+
requirement: &2152553740 !ruby/object:Gem::Requirement
|
72
|
+
none: false
|
73
|
+
requirements:
|
74
|
+
- - ! '>='
|
75
|
+
- !ruby/object:Gem::Version
|
76
|
+
version: '0'
|
77
|
+
type: :development
|
78
|
+
prerelease: false
|
79
|
+
version_requirements: *2152553740
|
80
|
+
- !ruby/object:Gem::Dependency
|
81
|
+
name: rspec-rails
|
82
|
+
requirement: &2152552080 !ruby/object:Gem::Requirement
|
83
|
+
none: false
|
84
|
+
requirements:
|
85
|
+
- - ! '>='
|
86
|
+
- !ruby/object:Gem::Version
|
87
|
+
version: '0'
|
88
|
+
type: :development
|
89
|
+
prerelease: false
|
90
|
+
version_requirements: *2152552080
|
25
91
|
description: Track stuff using javascript from your controllers, even after redirects
|
26
92
|
email:
|
27
93
|
- paul@mobalean.com
|
@@ -35,6 +101,10 @@ files:
|
|
35
101
|
- lib/mixpanel_rails.rb
|
36
102
|
- lib/mixpanel_rails/version.rb
|
37
103
|
- mixpanel_rails.gemspec
|
104
|
+
- spec/app/app/views/layouts/application.html.erb
|
105
|
+
- spec/app/fake.rb
|
106
|
+
- spec/mixpanel_rails_spec.rb
|
107
|
+
- spec/spec_helper.rb
|
38
108
|
homepage: ''
|
39
109
|
licenses: []
|
40
110
|
post_install_message:
|
@@ -55,8 +125,12 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
55
125
|
version: '0'
|
56
126
|
requirements: []
|
57
127
|
rubyforge_project: mixpanel_rails
|
58
|
-
rubygems_version: 1.8.
|
128
|
+
rubygems_version: 1.8.15
|
59
129
|
signing_key:
|
60
130
|
specification_version: 3
|
61
131
|
summary: Easy mixpanel integration for rails
|
62
|
-
test_files:
|
132
|
+
test_files:
|
133
|
+
- spec/app/app/views/layouts/application.html.erb
|
134
|
+
- spec/app/fake.rb
|
135
|
+
- spec/mixpanel_rails_spec.rb
|
136
|
+
- spec/spec_helper.rb
|