mixpanel-ruby 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
data/lib/mixpanel-ruby/events.rb
CHANGED
@@ -51,7 +51,9 @@ module Mixpanel
|
|
51
51
|
properties = {
|
52
52
|
'distinct_id' => distinct_id,
|
53
53
|
'token' => @token,
|
54
|
-
'time' => Time.now.to_i
|
54
|
+
'time' => Time.now.to_i,
|
55
|
+
'mp_lib' => 'ruby',
|
56
|
+
'$lib_version' => Mixpanel::VERSION
|
55
57
|
}.merge(properties)
|
56
58
|
if ip
|
57
59
|
properties['ip'] = ip
|
@@ -41,10 +41,10 @@ module Mixpanel
|
|
41
41
|
# and Mixpanel::BufferedConsumer#send
|
42
42
|
def initialize(token, &block)
|
43
43
|
super(token, &block)
|
44
|
+
@token = token
|
44
45
|
@people = People.new(token, &block)
|
45
46
|
end
|
46
47
|
|
47
|
-
|
48
48
|
# Creates a distinct_id alias. \Events and updates with an alias
|
49
49
|
# will be considered by mixpanel to have the same source, and
|
50
50
|
# refer to the same profile.
|
@@ -52,10 +52,19 @@ module Mixpanel
|
|
52
52
|
# Multiple aliases can map to the same real_id, once a real_id is
|
53
53
|
# used to track events or send updates, it should never be used as
|
54
54
|
# an alias itself.
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
55
|
+
#
|
56
|
+
# Alias requests are always sent synchronously, directly to
|
57
|
+
# the \Mixpanel service, regardless of how the tracker is configured.
|
58
|
+
def alias(alias_id, real_id, events_endpoint=nil)
|
59
|
+
consumer = Mixpanel::Consumer.new(events_endpoint)
|
60
|
+
message = {
|
61
|
+
'event' => '$create_alias',
|
62
|
+
'properties' => {
|
63
|
+
'distinct_id' => real_id,
|
64
|
+
'token' => @token,
|
65
|
+
}
|
66
|
+
}.to_json
|
67
|
+
consumer.send(:event, message)
|
59
68
|
end
|
60
69
|
end
|
61
70
|
end
|
@@ -9,21 +9,14 @@ describe Mixpanel::Tracker do
|
|
9
9
|
Time.stub!(:now).and_return(@time_now)
|
10
10
|
end
|
11
11
|
|
12
|
-
it 'should send
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
end
|
12
|
+
it 'should send an alias message to mixpanel no matter what the consumer is' do
|
13
|
+
WebMock.reset!
|
14
|
+
stub_request(:any, 'https://api.mixpanel.com/track').to_return({ :body => "1" })
|
15
|
+
mixpanel = Mixpanel::Tracker.new('TEST TOKEN') {|*args| }
|
17
16
|
mixpanel.alias('TEST ALIAS', 'TEST ID')
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
'alias' => 'TEST ALIAS',
|
22
|
-
'distinct_id' => 'TEST ID',
|
23
|
-
'token' => 'TEST TOKEN',
|
24
|
-
'time' => 76695784
|
25
|
-
}
|
26
|
-
}]])
|
17
|
+
|
18
|
+
WebMock.should have_requested(:post, 'https://api.mixpanel.com/track').
|
19
|
+
with(:body => { :data => 'eyJldmVudCI6IiRjcmVhdGVfYWxpYXMiLCJwcm9wZXJ0aWVzIjp7ImRpc3RpbmN0X2lkIjoiVEVTVCBJRCIsInRva2VuIjoiVEVTVCBUT0tFTiJ9fQ==' })
|
27
20
|
end
|
28
21
|
|
29
22
|
it 'should send a request to the track api with the default consumer' do
|