Class: KM

Inherits:
Object
  • Object
show all
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

Constructor Details

#initialize(api_key, options = {}) ⇒ KM

Create a KISSmetrics API client.

Parameters:

  • :api_key (String)

    Your site’s KISSmetrics API key



9
10
11
12
# File 'lib/delayable_km/km.rb', line 9

def initialize(api_key, options = {})
  @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

Parameters:

  • name (String)

    An existing identifier for a user

  • alias_to (String)

    A new identifier to associate with the user

See Also:



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

Parameters:

  • :id (String)

    A unique identifier for a person (email address, user id, or login are common choices)

See Also:



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

Parameters:

  • event (String)
  • params (Hash) (defaults to: {})
  • options (Hash)

    a customizable set of options

See Also:



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

Parameters:

  • params (Hash)

    An arbitrary hash of properties to associate with a person

  • options (Hash)

    a customizable set of options

See Also:



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