mixpanel 4.0.5 → 4.0.6
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +1 -0
- data/lib/mixpanel/person.rb +4 -0
- data/lib/mixpanel/tracker.rb +3 -1
- data/mixpanel.gemspec +1 -1
- data/spec/mixpanel/tracker_spec.rb +28 -2
- data/spec/spec_helper.rb +5 -5
- metadata +18 -18
data/README.md
CHANGED
data/lib/mixpanel/person.rb
CHANGED
@@ -51,6 +51,10 @@ module Mixpanel::Person
|
|
51
51
|
append 'people.increment', property, increment
|
52
52
|
end
|
53
53
|
|
54
|
+
def append_track_charge(amount)
|
55
|
+
append 'people.track_charge', amount
|
56
|
+
end
|
57
|
+
|
54
58
|
def append_register(properties={})
|
55
59
|
append 'register', properties_hash(properties, PERSON_PROPERTIES)
|
56
60
|
end
|
data/lib/mixpanel/tracker.rb
CHANGED
@@ -43,10 +43,12 @@ module Mixpanel
|
|
43
43
|
(@env['HTTP_X_FORWARDED_FOR'] || @env['REMOTE_ADDR'] || '').split(',').last
|
44
44
|
end
|
45
45
|
|
46
|
-
# Walk through each property and see if it is in the special_properties.
|
46
|
+
# Walk through each property and see if it is in the special_properties.
|
47
|
+
# If so, change the key to have a $ in front of it.
|
47
48
|
def properties_hash(properties, special_properties)
|
48
49
|
properties.inject({}) do |props, (key, value)|
|
49
50
|
key = "$#{key}" if special_properties.include?(key.to_s)
|
51
|
+
value = value.to_i if value.class == Time
|
50
52
|
props[key.to_sym] = value
|
51
53
|
props
|
52
54
|
end
|
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.6"
|
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"
|
@@ -127,14 +127,18 @@ describe Mixpanel::Tracker do
|
|
127
127
|
end
|
128
128
|
|
129
129
|
it "should append simple events" do
|
130
|
-
|
130
|
+
time = Time.now
|
131
|
+
props = { :time => time, :ip => 'ASDF' }
|
131
132
|
@mixpanel.append_track "Sign up", props
|
133
|
+
props[:time] = time.to_i
|
132
134
|
mixpanel_queue_should_include(@mixpanel, "track", "Sign up", props)
|
133
135
|
end
|
134
136
|
|
135
137
|
it "should append events with properties" do
|
136
|
-
|
138
|
+
time = Time.now
|
139
|
+
props = { :referer => 'http://example.com', :time => time, :ip => 'ASDF' }
|
137
140
|
@mixpanel.append_track "Sign up", props
|
141
|
+
props[:time] = time.to_i
|
138
142
|
mixpanel_queue_should_include(@mixpanel, "track", "Sign up", props)
|
139
143
|
end
|
140
144
|
|
@@ -154,6 +158,11 @@ describe Mixpanel::Tracker do
|
|
154
158
|
mixpanel_queue_should_include(@mixpanel, 'register', props)
|
155
159
|
end
|
156
160
|
|
161
|
+
it "should allow the tracking of charges in JS" do
|
162
|
+
@mixpanel.append_track_charge 40
|
163
|
+
mixpanel_queue_should_include(@mixpanel, 'people.track_charge', 40)
|
164
|
+
end
|
165
|
+
|
157
166
|
it "should allow alias to be called through the JS api" do
|
158
167
|
@mixpanel.append_alias "new_id"
|
159
168
|
mixpanel_queue_should_include(@mixpanel, "alias", "new_id")
|
@@ -194,4 +203,21 @@ describe Mixpanel::Tracker do
|
|
194
203
|
w2.should_not == w
|
195
204
|
end
|
196
205
|
end
|
206
|
+
|
207
|
+
describe '#properties_hash' do
|
208
|
+
it "base64encodes json formatted data" do
|
209
|
+
properties = { :a => 4, :b => "foo"}
|
210
|
+
special_properties = ["a"]
|
211
|
+
hash = @mixpanel.send(:properties_hash, properties, special_properties)
|
212
|
+
hash.should eq({ :'$a' => 4, :b => "foo"})
|
213
|
+
end
|
214
|
+
|
215
|
+
it "converts Time objects into integers" do
|
216
|
+
time = Time.new
|
217
|
+
properties = { :a => time, :b => "foo"}
|
218
|
+
special_properties = []
|
219
|
+
hash = @mixpanel.send(:properties_hash, properties, special_properties)
|
220
|
+
hash.should eq({ :a => time.to_i, :b => "foo"})
|
221
|
+
end
|
222
|
+
end
|
197
223
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -8,12 +8,12 @@ Dir[File.expand_path(File.join(File.dirname(__FILE__),'support','**','*.rb'))].e
|
|
8
8
|
|
9
9
|
MIX_PANEL_TOKEN = "e2d8b0bea559147844ffab3d607d26a6"
|
10
10
|
|
11
|
-
|
11
|
+
# json hashes have string keys, convert to json and back to compare hashes
|
12
12
|
def mixpanel_queue_should_include(mixpanel, type, *arguments)
|
13
|
-
mixpanel.queue.
|
14
|
-
|
15
|
-
|
16
|
-
|
13
|
+
event = mixpanel.queue.detect { |event| event[0] == type }
|
14
|
+
event.should_not be_nil
|
15
|
+
event_arguments = event[1]
|
16
|
+
unjsonify(event_arguments).should == json_and_back(arguments)
|
17
17
|
end
|
18
18
|
|
19
19
|
def json_and_back array
|
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.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: 2013-
|
12
|
+
date: 2013-09-05 00:00:00.000000000Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: json
|
16
|
-
requirement: &
|
16
|
+
requirement: &2153726180 !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: *2153726180
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: rack
|
27
|
-
requirement: &
|
27
|
+
requirement: &2153725740 !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: *2153725740
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: escape
|
38
|
-
requirement: &
|
38
|
+
requirement: &2153725320 !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: *2153725320
|
47
47
|
- !ruby/object:Gem::Dependency
|
48
48
|
name: rspec
|
49
|
-
requirement: &
|
49
|
+
requirement: &2153724900 !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: *2153724900
|
58
58
|
- !ruby/object:Gem::Dependency
|
59
59
|
name: rack-test
|
60
|
-
requirement: &
|
60
|
+
requirement: &2153724480 !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: *2153724480
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: fakeweb
|
71
|
-
requirement: &
|
71
|
+
requirement: &2153724060 !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: *2153724060
|
80
80
|
- !ruby/object:Gem::Dependency
|
81
81
|
name: nokogiri
|
82
|
-
requirement: &
|
82
|
+
requirement: &2153723640 !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: *2153723640
|
91
91
|
- !ruby/object:Gem::Dependency
|
92
92
|
name: rake
|
93
|
-
requirement: &
|
93
|
+
requirement: &2153723220 !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: *2153723220
|
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
|