Calls

Calls and functions available in the Fresh Relevance JavaScript API

setEmail

$TB.setEmail(emailAddress)

ParameterTypeDescription
emailAddressstringThe email address of the user

Set the email address for this person, for example, when they've logged in.

You should call sendBeacon directly afterward, to ensure the data is sent to the Fresh Relevance server.


setMobile

$TB.setMobile(mobile, code)

ParameterTypeDescription
mobilestringThe mobile phone number of the user in either E.164 format or local format if you also pass a code value.
codestringThe 2 character country code for the mobile number in ISO 3166-1 alpha-2 format

Set the mobile number (and optional mobile code) for this person. You can pass the mobile number in either international format (E.164 format) or in local format with the country code the number is registered in so that Fresh Relevance can validate and convert to international format.

You should call sendBeacon directly afterward, to ensure the data is sent to the Fresh Relevance server.


setDetails

$TB.setDetails(emailAddress, firstName, lastName, fullName, options)

ParameterTypeDescription
emailAddressstringThe email address of the user
firstNamestringThe first name of the user
lastNamestringThe last name of the user
fullNamestringThe full name of the user
optionsobjectSet options.emailType to one of:

- e for plain email address
- b64e for base64-encoded email address
- rc4e for RC4 encrypted email address

Set details for this person, for example, when they've logged in.

Any parameters passed as null are ignored.

Note, you don't need to call sendBeacon separately, as this is called automatically as part of this call.


setData

$TB.setData(rootData, extraData)

ParameterTypeDescription
rootDataobjectSpecify any Person fields you want to set.
extraDataobjectAny other data that you want to be added to the person's record.

Set data for this person.

Example

Setting a person details with extra gender information passed.

$TB.setData({'e': emailAddress, 'fn': firstName, 'ln': lastName}, {'gender': customerGender}

Note, you don't need to call sendBeacon separately, as this is called automatically as part of this call.


raiseSignal

$TB.raiseSignal(namespace, signal)

ParameterTypeDescription
namespacestringThe namespace for the custom signal. Note: You might have multiple triggers within the same namespace - the first trigger that satisfies its filter criteria is run.
extraDataobjectAny data items that need passing to the custom trigger.

Raise custom signals from your site so Fresh Relevance can respond to the specified triggers / actions of your customer on your site. For example, when a customer orders a brochure or viewed a particular page, you can pass data through to the signal, which is available all the way through to email send time, so it can be merged into an email.

Custom signals have a property namespace that allows multiple custom signals to exist, without interfering with each other.

$TB.raiseSignal('your_namespace', {'exampleitem': 'examplevalue', 'another': 'value'});

The extraData can be accessed in layouts using the prefix extra. and then the field name you want to reference from within the extraData object. e.g.

Example Item: {{ extra.exampleitem }}
Another: {{ extra.another }}

sendBeacon

$TB.sendBeacon()

Syncs all pending data to the Fresh Relevance server. We recommend calling this after and significant data point changes to ensure it is synced, unless you have used a call that does this automatically for you.