Sample code
// the event name used here will automatically
// appear in the goal and audience builders
Txt.track({
  eventName: 'purchase',
  eventValue: 29.99
})

The track function sends an event to Unless' system. The event can be connected in the dashboard to an audience (to join the audience) or a goal (to achieve the goal).

Txt.track(options)

The options object is required and should be structured as follows:

KeyTypeDescription
eventNamestring
required
The name of the event.
eventValuenumber
optional
Used in case of a goal achievement to store the value of the goal conversion.
dataarray
optional
Record additional traits to the visitor, see the updateProfile function for a description of the data format.
callbackfunction
optional
callback function that will be executed after sending the event to our server.

Joining or leaving an audience using a specified audience ID

Using an event to join an audience like described above is usually the preferred method because you don't have to know the exact audience ID. Alternatively, you can also join an audience directly using the audience ID by using the following API call.

Txt.joinAudience(audienceId)

You can also force a visitor to leave a specific audience. Remember, the visitor can re-join the audience at any time.

Txt.leaveAudience(audienceId)