mixpanel 4.0.6 → 4.0.7
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/mixpanel/event.rb +12 -2
- data/lib/mixpanel/person.rb +1 -2
- data/lib/mixpanel/subprocess.rb +15 -10
- data/lib/mixpanel/tracker.rb +12 -7
- data/mixpanel.gemspec +1 -1
- data/spec/mixpanel/tracker_spec.rb +1 -1
- metadata +59 -19
data/lib/mixpanel/event.rb
CHANGED
@@ -36,8 +36,8 @@ module Mixpanel::Event
|
|
36
36
|
def track_event(event, properties, options, default_url)
|
37
37
|
default = {:url => default_url, :async => @async, :api_key => @api_key}
|
38
38
|
options = default.merge(options)
|
39
|
-
|
40
|
-
parse_response
|
39
|
+
data = build_data(event, properties, options)
|
40
|
+
parse_response post_request(options[:url], data, options[:async])
|
41
41
|
end
|
42
42
|
|
43
43
|
def track_properties(properties, include_token=true)
|
@@ -52,6 +52,16 @@ module Mixpanel::Event
|
|
52
52
|
{ :event => event, :properties => properties_hash(properties, EVENT_PROPERTIES) }
|
53
53
|
end
|
54
54
|
|
55
|
+
def build_data event, properties, options
|
56
|
+
params = {}
|
57
|
+
data = build_event event, track_properties(properties)
|
58
|
+
params[:data] = encoded_data(data)
|
59
|
+
params[:api_key] = options[:api_key] if options.fetch(:api_key, nil)
|
60
|
+
params[:img] = 1 if options[:img]
|
61
|
+
params[:test] = 1 if options[:test]
|
62
|
+
params
|
63
|
+
end
|
64
|
+
|
55
65
|
def build_url event, properties, options
|
56
66
|
data = build_event event, track_properties(properties)
|
57
67
|
url = "#{options[:url]}?data=#{encoded_data(data)}"
|
data/lib/mixpanel/person.rb
CHANGED
@@ -81,8 +81,7 @@ module Mixpanel::Person
|
|
81
81
|
data = build_person action, request_properties, properties
|
82
82
|
end
|
83
83
|
|
84
|
-
|
85
|
-
parse_response request(url, options[:async])
|
84
|
+
parse_response post_request(options[:url], { data: encoded_data(data) }, options[:async])
|
86
85
|
end
|
87
86
|
|
88
87
|
def person_request_properties(request_properties_or_distinct_id)
|
data/lib/mixpanel/subprocess.rb
CHANGED
@@ -1,5 +1,7 @@
|
|
1
|
-
require 'open-uri'
|
2
1
|
require 'thread'
|
2
|
+
require "uri"
|
3
|
+
require "net/http"
|
4
|
+
require 'json'
|
3
5
|
|
4
6
|
module Mixpanel
|
5
7
|
class Subprocess
|
@@ -7,20 +9,23 @@ module Mixpanel
|
|
7
9
|
ENDMARKER = Object.new
|
8
10
|
|
9
11
|
Thread.abort_on_exception = true
|
10
|
-
producer = Thread.new do
|
11
|
-
STDIN.each_line() do |
|
12
|
-
STDERR.puts("Dropped: #{
|
13
|
-
Q <<
|
12
|
+
producer = Thread.new do
|
13
|
+
STDIN.each_line() do |data|
|
14
|
+
STDERR.puts("Dropped: #{data}") && next if Q.length > 10000
|
15
|
+
Q << data
|
14
16
|
end
|
15
17
|
Q << ENDMARKER
|
16
18
|
end
|
17
19
|
|
18
20
|
loop do
|
19
|
-
|
20
|
-
break if(
|
21
|
-
|
22
|
-
|
23
|
-
|
21
|
+
data = Q.pop
|
22
|
+
break if(data == ENDMARKER)
|
23
|
+
data.chomp!
|
24
|
+
data_hash = JSON.load(data)
|
25
|
+
if data_hash.is_a?(Hash) && data_hash['_mixpanel_url']
|
26
|
+
url = data_hash.delete('_mixpanel_url')
|
27
|
+
Net::HTTP.post_form(URI.parse(url), data_hash)
|
28
|
+
end
|
24
29
|
end
|
25
30
|
producer.join
|
26
31
|
end
|
data/lib/mixpanel/tracker.rb
CHANGED
@@ -1,7 +1,8 @@
|
|
1
|
-
require "
|
2
|
-
require
|
1
|
+
require "uri"
|
2
|
+
require "net/http"
|
3
3
|
require 'json'
|
4
4
|
require 'thread'
|
5
|
+
require 'base64'
|
5
6
|
|
6
7
|
module Mixpanel
|
7
8
|
class Tracker
|
@@ -58,19 +59,23 @@ module Mixpanel
|
|
58
59
|
Base64.encode64(JSON.generate(parameters)).gsub(/\n/,'')
|
59
60
|
end
|
60
61
|
|
61
|
-
def
|
62
|
-
async
|
62
|
+
def post_request(url, data, async)
|
63
|
+
if async
|
64
|
+
send_async(url, data)
|
65
|
+
else
|
66
|
+
Net::HTTP.post_form(URI.parse(url), data)
|
67
|
+
end
|
63
68
|
end
|
64
69
|
|
65
70
|
def parse_response(response)
|
66
|
-
response.to_i == 1
|
71
|
+
response.body.to_i == 1
|
67
72
|
end
|
68
73
|
|
69
|
-
def send_async(url)
|
74
|
+
def send_async(url, data)
|
70
75
|
w = Mixpanel::Tracker.worker
|
71
76
|
begin
|
72
77
|
url << "\n"
|
73
|
-
w.write url
|
78
|
+
w.write JSON.dump(data.merge(_mixpanel_url: url))
|
74
79
|
1
|
75
80
|
rescue Errno::EPIPE => e
|
76
81
|
Mixpanel::Tracker.dispose_worker w
|
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.7"
|
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"
|
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.7
|
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-09-
|
12
|
+
date: 2013-09-06 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: json
|
16
|
-
requirement:
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,10 +21,15 @@ dependencies:
|
|
21
21
|
version: '0'
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements:
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '0'
|
25
30
|
- !ruby/object:Gem::Dependency
|
26
31
|
name: rack
|
27
|
-
requirement:
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
28
33
|
none: false
|
29
34
|
requirements:
|
30
35
|
- - ! '>='
|
@@ -32,10 +37,15 @@ dependencies:
|
|
32
37
|
version: '0'
|
33
38
|
type: :runtime
|
34
39
|
prerelease: false
|
35
|
-
version_requirements:
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0'
|
36
46
|
- !ruby/object:Gem::Dependency
|
37
47
|
name: escape
|
38
|
-
requirement:
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
39
49
|
none: false
|
40
50
|
requirements:
|
41
51
|
- - ! '>='
|
@@ -43,10 +53,15 @@ dependencies:
|
|
43
53
|
version: '0'
|
44
54
|
type: :runtime
|
45
55
|
prerelease: false
|
46
|
-
version_requirements:
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ! '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
47
62
|
- !ruby/object:Gem::Dependency
|
48
63
|
name: rspec
|
49
|
-
requirement:
|
64
|
+
requirement: !ruby/object:Gem::Requirement
|
50
65
|
none: false
|
51
66
|
requirements:
|
52
67
|
- - ! '>='
|
@@ -54,10 +69,15 @@ dependencies:
|
|
54
69
|
version: '0'
|
55
70
|
type: :development
|
56
71
|
prerelease: false
|
57
|
-
version_requirements:
|
72
|
+
version_requirements: !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ! '>='
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '0'
|
58
78
|
- !ruby/object:Gem::Dependency
|
59
79
|
name: rack-test
|
60
|
-
requirement:
|
80
|
+
requirement: !ruby/object:Gem::Requirement
|
61
81
|
none: false
|
62
82
|
requirements:
|
63
83
|
- - ! '>='
|
@@ -65,10 +85,15 @@ dependencies:
|
|
65
85
|
version: '0'
|
66
86
|
type: :development
|
67
87
|
prerelease: false
|
68
|
-
version_requirements:
|
88
|
+
version_requirements: !ruby/object:Gem::Requirement
|
89
|
+
none: false
|
90
|
+
requirements:
|
91
|
+
- - ! '>='
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
version: '0'
|
69
94
|
- !ruby/object:Gem::Dependency
|
70
95
|
name: fakeweb
|
71
|
-
requirement:
|
96
|
+
requirement: !ruby/object:Gem::Requirement
|
72
97
|
none: false
|
73
98
|
requirements:
|
74
99
|
- - ! '>='
|
@@ -76,10 +101,15 @@ dependencies:
|
|
76
101
|
version: '0'
|
77
102
|
type: :development
|
78
103
|
prerelease: false
|
79
|
-
version_requirements:
|
104
|
+
version_requirements: !ruby/object:Gem::Requirement
|
105
|
+
none: false
|
106
|
+
requirements:
|
107
|
+
- - ! '>='
|
108
|
+
- !ruby/object:Gem::Version
|
109
|
+
version: '0'
|
80
110
|
- !ruby/object:Gem::Dependency
|
81
111
|
name: nokogiri
|
82
|
-
requirement:
|
112
|
+
requirement: !ruby/object:Gem::Requirement
|
83
113
|
none: false
|
84
114
|
requirements:
|
85
115
|
- - ! '>='
|
@@ -87,10 +117,15 @@ dependencies:
|
|
87
117
|
version: '0'
|
88
118
|
type: :development
|
89
119
|
prerelease: false
|
90
|
-
version_requirements:
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
none: false
|
122
|
+
requirements:
|
123
|
+
- - ! '>='
|
124
|
+
- !ruby/object:Gem::Version
|
125
|
+
version: '0'
|
91
126
|
- !ruby/object:Gem::Dependency
|
92
127
|
name: rake
|
93
|
-
requirement:
|
128
|
+
requirement: !ruby/object:Gem::Requirement
|
94
129
|
none: false
|
95
130
|
requirements:
|
96
131
|
- - ! '>='
|
@@ -98,7 +133,12 @@ dependencies:
|
|
98
133
|
version: '0'
|
99
134
|
type: :development
|
100
135
|
prerelease: false
|
101
|
-
version_requirements:
|
136
|
+
version_requirements: !ruby/object:Gem::Requirement
|
137
|
+
none: false
|
138
|
+
requirements:
|
139
|
+
- - ! '>='
|
140
|
+
- !ruby/object:Gem::Version
|
141
|
+
version: '0'
|
102
142
|
description: Simple lib to track events in Mixpanel service. It can be used in any
|
103
143
|
rack based framework.
|
104
144
|
email: zevarito@gmail.com
|
@@ -142,7 +182,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
142
182
|
version: '0'
|
143
183
|
requirements: []
|
144
184
|
rubyforge_project: mixpanel
|
145
|
-
rubygems_version: 1.8.
|
185
|
+
rubygems_version: 1.8.21
|
146
186
|
signing_key:
|
147
187
|
specification_version: 3
|
148
188
|
summary: Supports direct request api and javascript requests through a middleware.
|