Class: EM::Mixpanel
- Inherits:
-
Object
- Object
- EM::Mixpanel
- Defined in:
- lib/em/mixpanel.rb,
lib/em/mixpanel/version.rb
Constant Summary collapse
- TRACK_URI =
'http://api.mixpanel.com/track'
- IMPORT_URI =
'http://api.mixpanel.com/import'
- VERSION =
'0.0.2'
Instance Attribute Summary collapse
-
#default_properties ⇒ Object
readonly
Returns the value of attribute default_properties.
-
#token ⇒ Object
readonly
Returns the value of attribute token.
Instance Method Summary collapse
- #import(event, properties = {}) ⇒ Object
-
#initialize(token, default_properties = {}) ⇒ Mixpanel
constructor
A new instance of Mixpanel.
- #track(event, properties = {}) ⇒ Object
Constructor Details
#initialize(token, default_properties = {}) ⇒ Mixpanel
Returns a new instance of Mixpanel.
13 14 15 |
# File 'lib/em/mixpanel.rb', line 13 def initialize(token, default_properties={}) @token, @default_properties = token, default_properties end |
Instance Attribute Details
#default_properties ⇒ Object (readonly)
Returns the value of attribute default_properties.
11 12 13 |
# File 'lib/em/mixpanel.rb', line 11 def default_properties @default_properties end |
#token ⇒ Object (readonly)
Returns the value of attribute token.
11 12 13 |
# File 'lib/em/mixpanel.rb', line 11 def token @token end |
Instance Method Details
#import(event, properties = {}) ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/em/mixpanel.rb', line 29 def import(event, properties={}) data = self.class.encode_data(event, { token: token }.merge(default_properties).merge(properties)) EM::HttpRequest.new(IMPORT_URI.to_s).get( query: { data: data, api_key: token } ) end |
#track(event, properties = {}) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/em/mixpanel.rb', line 17 def track(event, properties={}) data = self.class.encode_data(event, { token: token, time: Time.now.to_i }.merge(default_properties).merge(properties)) EM::HttpRequest.new(TRACK_URI.to_s).post( body: {data: data}, query: {ip: 0} ) end |