em-mixpanel 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/em-mixpanel.gemspec +18 -0
- data/lib/em/mixpanel/tracker.rb +44 -0
- data/lib/em/mixpanel/version.rb +5 -0
- data/lib/em/mixpanel.rb +2 -0
- metadata +59 -0
data/em-mixpanel.gemspec
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
$:.push('lib')
|
2
|
+
require "em/mixpanel/version"
|
3
|
+
|
4
|
+
Gem::Specification.new do |s|
|
5
|
+
s.name = 'em-mixpanel'
|
6
|
+
s.version = EM::Mixpanel::VERSION.dup
|
7
|
+
s.email = "dave@minefold.com"
|
8
|
+
s.author = 'Dave Newman'
|
9
|
+
|
10
|
+
s.summary = 'Non-blocking Mixpanel tracker'
|
11
|
+
|
12
|
+
s.add_dependency 'em-http-request'
|
13
|
+
|
14
|
+
s.files = Dir['**/*']
|
15
|
+
s.test_files = Dir['test/**/*'] + Dir['spec/**/*']
|
16
|
+
s.executables = Dir['bin/*'].map { |f| File.basename(f) }
|
17
|
+
s.require_paths = ["lib"]
|
18
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
require 'base64'
|
2
|
+
require 'json'
|
3
|
+
|
4
|
+
module EM
|
5
|
+
module Mixpanel
|
6
|
+
class Tracker
|
7
|
+
attr_reader :env, :token
|
8
|
+
|
9
|
+
def initialize(token, env)
|
10
|
+
@token, @env = token, env
|
11
|
+
end
|
12
|
+
|
13
|
+
def track(event, properties={})
|
14
|
+
if token and Rails.env.production?
|
15
|
+
http = EventMachine::HttpRequest.new('http://api.mixpanel.com/track/').post body: { data: encoded_data(event, properties) }
|
16
|
+
else
|
17
|
+
Rails.logger.info "[Mixpanel] #{event} #{properties.to_json}"
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
def ip
|
22
|
+
env.has_key?("REMOTE_ADDR") ? @env["REMOTE_ADDR"] : '1'
|
23
|
+
end
|
24
|
+
|
25
|
+
def default_properties
|
26
|
+
{
|
27
|
+
ip: ip,
|
28
|
+
time: Time.now.to_i,
|
29
|
+
token: token
|
30
|
+
}
|
31
|
+
end
|
32
|
+
|
33
|
+
def encoded_data(event, properties)
|
34
|
+
params = {
|
35
|
+
event: event,
|
36
|
+
properties: default_properties.merge(properties)
|
37
|
+
}
|
38
|
+
|
39
|
+
ActiveSupport::Base64.encode64s(JSON.generate(params))
|
40
|
+
end
|
41
|
+
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
data/lib/em/mixpanel.rb
ADDED
metadata
ADDED
@@ -0,0 +1,59 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: em-mixpanel
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Dave Newman
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2011-12-13 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: em-http-request
|
16
|
+
requirement: &70232352198300 !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: *70232352198300
|
25
|
+
description:
|
26
|
+
email: dave@minefold.com
|
27
|
+
executables: []
|
28
|
+
extensions: []
|
29
|
+
extra_rdoc_files: []
|
30
|
+
files:
|
31
|
+
- em-mixpanel.gemspec
|
32
|
+
- lib/em/mixpanel/tracker.rb
|
33
|
+
- lib/em/mixpanel/version.rb
|
34
|
+
- lib/em/mixpanel.rb
|
35
|
+
homepage:
|
36
|
+
licenses: []
|
37
|
+
post_install_message:
|
38
|
+
rdoc_options: []
|
39
|
+
require_paths:
|
40
|
+
- lib
|
41
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
42
|
+
none: false
|
43
|
+
requirements:
|
44
|
+
- - ! '>='
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: '0'
|
47
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
48
|
+
none: false
|
49
|
+
requirements:
|
50
|
+
- - ! '>='
|
51
|
+
- !ruby/object:Gem::Version
|
52
|
+
version: '0'
|
53
|
+
requirements: []
|
54
|
+
rubyforge_project:
|
55
|
+
rubygems_version: 1.8.12
|
56
|
+
signing_key:
|
57
|
+
specification_version: 3
|
58
|
+
summary: Non-blocking Mixpanel tracker
|
59
|
+
test_files: []
|