Unless API - Documentation

Using Unless' API your developers can send additional data about visitors, audiences, and goals into Unless. Learn more.

This reference documentation for the Unless API makes it possible for our customers to send additional data into Unless. This data allows for more granular audience targeting, enriched visitor data, advanced goal measurement, and more.

Please bear in mind that this API documentation is targeted at your developers. Unless can not assist with the setup.

Here is a list of all available functions.

Track - Audiences & Goals

The Txt.track(options) 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). The options object is required and should be structured as follows:  

Argument 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 object 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.

Example:

Txt.track({   eventName: 'purchase',   eventValue: 29.99 })

Identify - Visitors

The Txt.identify(email, data) function sends an event to Unless' system. The event can be connected in the dashboard to a visitor. The email and data objects are required and should be structured as follows:  

Argument Type Description
email string required: identify a visitor by email address. Use this for example when a visitor logs into your system. The email will be used to integrate Unless enriched data to other systems.
data object optional: store additional traits to the visitor, see the updateProfile function for a description of the data format.

Example:

Txt.identify('marcel@unless.com')

Update Profile

The Txt.updateProfile(data) function enriches an existing visitor profile with additional data points. The data property is required and should be an array of objects. The object is structured like this:  

Key Type Description
key string required: the key to store as a trait.
value string required: the value to store.
type string required: the type of the data that you are sending, options are text, number, bool, date.
custom boolean optional: set this to true if it is not a default trait - see list below.

Default traits: firstName, lastName, email, employmentTitle, employmentRole, employmentSeniority, companyName, companyWebsite  

Example:

Txt.updateProfile([     {key: 'firstName', value: 'John', type: 'string'},     {key: 'accountId', value: '123abc', type: 'string', custom: true} ])

Get Visitor ID

Txt.getVisitorId() returns the current visitor ID.

Example:

var visitorId = Txt.getVisitorId()

Dynamic Content Insertion

Set Key

Txt.set(key, value) sets a key/value pair that can later be used for dynamic content insertion. Here's how to set up dynamic content using Javascript.  

Argument Type Description
key string required: The key to store.
value string required: The value to store.

Example:

Txt.set('my-custom-key', 'my value')

Get Key

Txt.get(key) returns the value from the visitors data specified by a key. Here's a full list of all possible keys.  

Argument Type Description
key string required: The key to store.

Example:

var myCustomKeyValue = Txt.get('my-custom-key') var city = Txt.get('geo.city')

Cookies for Audience Segmentation

Set Cookies

Txt.setCookie(name, value, days) stores a cookie in the visitors browser. Here's how to use cookies for audience segmentation.  

Argument Type Description
name string required: The name of the cookie.
value string required: The value you want to set.
days number required: The number of days after which the cookie should expire.

Example:

Txt.setCookie('my-cookie', 'my value', 30)

Retrieve Cookies

Txt.getCookie(name) retrieves a cookie value from the visitors browser.  

Argument Type Description
name string required: The name of the cookie.

Example:

var myCookieValue = Txt.getCookie('my-cookie')

Launch Add-on

Use Txt.launchAddOn(personalizationId) to programmatically launch an add-on regardless of audience by providing the personalizationId.  

Argument Type Description
personalizationId string required: The personalization ID of the add-on to launch.

Example:

Txt.launchAddOn('abcd1234')