mix_tape 0.0.2 → 0.0.3
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 +8 -0
- data/lib/mix_tape/client.rb +13 -3
- data/lib/mix_tape/version.rb +1 -1
- data/spec/lib/mix_tape/config_spec.rb +18 -1
- metadata +1 -1
data/README.md
CHANGED
@@ -72,6 +72,14 @@ If you are in a dev or test environment and don't want to send events to MixPane
|
|
72
72
|
config.console_logging = true
|
73
73
|
end
|
74
74
|
|
75
|
+
If you want Mixpanel to use your request variables to track user's location etc, then add this to your application controller:
|
76
|
+
|
77
|
+
before_filter :update_mixtape_request
|
78
|
+
|
79
|
+
def update_mixtape_request
|
80
|
+
MixTape.request = request
|
81
|
+
end
|
82
|
+
|
75
83
|
And then execute:
|
76
84
|
|
77
85
|
$ bundle
|
data/lib/mix_tape/client.rb
CHANGED
@@ -1,10 +1,10 @@
|
|
1
1
|
module MixTape
|
2
2
|
|
3
3
|
class << self
|
4
|
-
attr_accessor :token, :fake, :console_logging
|
4
|
+
attr_accessor :token, :fake, :console_logging, :request
|
5
5
|
|
6
6
|
def client
|
7
|
-
raise(ArgumentError, %{MixPanel token is undefined.}) if token.empty? && !fake
|
7
|
+
raise(ArgumentError, %{MixPanel token is undefined.}) if (token.nil? || token.empty?) && !fake
|
8
8
|
@client = mix_client
|
9
9
|
end
|
10
10
|
|
@@ -18,8 +18,18 @@ module MixTape
|
|
18
18
|
if !!fake
|
19
19
|
FakeTracker.new(console_logging)
|
20
20
|
else
|
21
|
-
Mixpanel::Tracker.new(token, async: true)
|
21
|
+
Mixpanel::Tracker.new(token, async: true, env: @request ? env : {})
|
22
22
|
end
|
23
23
|
end
|
24
|
+
|
25
|
+
def env
|
26
|
+
e = @request.is_a?(Hash) ? @request : @request.env
|
27
|
+
{
|
28
|
+
'REMOTE_ADDR' => e['REMOTE_ADDR'],
|
29
|
+
'HTTP_X_FORWARDED_FOR' => e['HTTP_X_FORWARDED_FOR'],
|
30
|
+
'rack.session' => e['rack.session'],
|
31
|
+
'mixpanel_events' => e['mixpanel_events']
|
32
|
+
}
|
33
|
+
end
|
24
34
|
end
|
25
35
|
end
|
data/lib/mix_tape/version.rb
CHANGED
@@ -24,8 +24,25 @@ describe 'Configuraton' do
|
|
24
24
|
end
|
25
25
|
|
26
26
|
it "uses FakeTracker if we set it up" do
|
27
|
-
MixTape.config{ |config| config.fake = true }
|
27
|
+
MixTape.config{ |config| config.fake = true; config.token = nil }
|
28
28
|
|
29
29
|
expect(MixTape.client).to be_a MixTape::FakeTracker
|
30
30
|
end
|
31
|
+
|
32
|
+
it "can use request.env information" do
|
33
|
+
MixTape.config{ |config| config.token = '1234'; config.fake = false }
|
34
|
+
MixTape.request = double(:http_request, env: { 'REMOTE_ADDR' => '127.0.0.1' })
|
35
|
+
|
36
|
+
Mixpanel::Tracker.should_receive(:new).with('1234', {
|
37
|
+
async: true,
|
38
|
+
env: {
|
39
|
+
'REMOTE_ADDR' => '127.0.0.1',
|
40
|
+
'HTTP_X_FORWARDED_FOR' => nil,
|
41
|
+
'rack.session' => nil,
|
42
|
+
'mixpanel_events' => nil
|
43
|
+
}
|
44
|
+
})
|
45
|
+
|
46
|
+
MixTape.client
|
47
|
+
end
|
31
48
|
end
|