Common Methods
Rather than constantly making HTTP calls, we provide abstraction with dedicated libraries in several languages. You can use choose to use one (or more) of them to send data.
All of our libraries provide the same basic methods:
Command | Description |
---|---|
record |
Tracks that the current person performed an action. |
set |
Saves additional properties about the person, which you use to segment groups of people into cohorts. |
identify |
Sets the identity of the current person, so we know who to attribute future events to. |
record
The record
method is the most commonly used method. When a record
command is executed, it records a KISSmetric event. It takes two parameters:
- The
name
of the event to record as a string - An (optional) Hash of
properties
for the event
If you do not pass in a name, calling record
is identical to calling set
. See below for examples.
Our JavaScript Library has additional methods to let you record events after a certain trigger: when an element gets clicked, or when a form is submitted.
set
The set
method lets you set properties on a person without recording an event. It takes a Hash of properties to set. See below for examples.
identify
The identify
method allows you to set the identity of the current person using your site. Our JavaScript API will detect anonymous visitors and set up appropriate anonymous identities for them automatically.
identify
only takes a single argument, the identity of the person. This identity can be any string value you want, like a user id, login, e-mail address, or an existing cookie you have already set. Ideally, you want it to be a strong identifier (such as an e-mail address) that will be consistent across sessions, browsers, etc.
We recommend you call identify
in two scenarios:
- When a user successfully signs up
- When a user successfully logs in, either through cookies or through a login page
Here’s an example of an identify
call in a Ruby app that obtains the current visitor’s username. This may not work for your particular site, but should give you an idea of how to structure the API call.
_kmq.push(['identify', '<%= @user.email_address %>']);
For more information on how to handle identities, please refer to this Identity Management guide.
Examples
Below are some examples for the standard API. Please see APIs for supported languages.