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:
Key | Type | Description |
---|---|---|
eventName | string required | The name of the event. |
eventValue | number optional | Used in case of a goal achievement to store the value of the goal conversion. |
data | array optional | Record additional traits to the visitor, see the updateProfile function for a description of the data format. |
callback | function 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)