Class: KM
- Inherits:
-
Object
- Object
- KM
- Defined in:
- lib/delayable_km/km.rb
Overview
The main delayable_km class, containing methods for initializing a KISSmetrics API client and making API calls
Constant Summary collapse
- DEFAULT_API_ENDPOINT =
The default KISSmetrics API endpoint that all requests are sent to
'http://trk.kissmetrics.com'
Instance Method Summary collapse
-
#alias(name, alias_to) ⇒ Object
Associate one KISSmetrics identity with another.
-
#identify(id) ⇒ Object
Set the identity of a person using your site.
-
#initialize(api_key, options = {}) ⇒ KM
constructor
Create a KISSmetrics API client.
-
#record(event, params = {}) ⇒ Object
Record a KISSmetrics event.
-
#set(params) ⇒ Object
Set properties on a person without recording a named event.
Constructor Details
#initialize(api_key, options = {}) ⇒ KM
Create a KISSmetrics API client.
9 10 11 12 |
# File 'lib/delayable_km/km.rb', line 9 def initialize(api_key, = {}) @api_key = api_key @api_endpoint = DEFAULT_API_ENDPOINT end |
Instance Method Details
#alias(name, alias_to) ⇒ Object
Note:
The order of arguments to this method doesn’t actually matter. You can call it with the existing identifier first or second.
Associate one KISSmetrics identity with another
40 41 42 43 |
# File 'lib/delayable_km/km.rb', line 40 def alias(name, alias_to) params = { :_n => alias_to, :_p => name } request('a', params) end |
#identify(id) ⇒ Object
Set the identity of a person using your site
18 19 20 |
# File 'lib/delayable_km/km.rb', line 18 def identify(id) @id = id end |
#record(event, params = {}) ⇒ Object
Record a KISSmetrics event
28 29 30 31 32 |
# File 'lib/delayable_km/km.rb', line 28 def record(event, params = {}) defaults = { :_n => event, :_p => @id } params = defaults.merge(params) request('e', params) end |
#set(params) ⇒ Object
Set properties on a person without recording a named event
50 51 52 53 54 |
# File 'lib/delayable_km/km.rb', line 50 def set(params) defaults = { :_p => @id } params = defaults.merge(params) request('s', params) end |