The JavaScript API enables you to pass data from your website to Fresh Relevance. You can implement this yourself or request our team to add it as part of our services.
Common use cases include:
Raising custom signals to trigger personalized programs
Capturing customer actions on your site (such as brochure requests or page views)
Passing visitor data when customers log in to enable personalization
Sending customer information for use in triggered messages
Data passed through signals is available through the entire process, including at email send time for personalized content.
Core JavaScript functions
Use these functions in your website code to send data to Fresh Relevance servers.
Name | Description |
| Set the email address for this person, for example, when they've logged in.
You need to call |
| Set the mobile number (and optional mobile code) for this person.
You need to call |
| Set details for this person, for example, when they've logged in. Any parameters passed as null are ignored. Set
You don't need to call |
| Set data for this person; where
Example (gender). $TB.setData({'e': emailAddress, 'fn': firstName, 'ln': lastName}, {'gender': customerGender}
You don't need to call |
| Learn more in Raising custom signals from your site. |
JavaScript hooks
These hooks allow you to run custom code at specific points in the personalization lifecycle.
You can create functions within these hooks and the code is called at the appropriate time, such as, when a slot has loaded.
Function name | Called | Description |
| Once for each Slot, after the data has been retrieved, before the page is updated. | Parameters:
{
Return value: true | false. If true, the slot is added to the page as normal. If false, the slot is not added to the page.
This hook can also be used to alter the html before it is added to the document by replacing the html attribute. |
| Once for each slot, after the page has updated. | Parameters:
{ Return value: None |
A wider range of hooks are available.
Learn more in In-page JavaScript API for single page applications.
Popover reporting functions
Before you start
Popover reporting only works in SmartBlocks displayed on web pages containing our script.
These functions report key popover events back to Fresh Relevance for analytics:
Function | Purpose | Example |
$TB.popoverShown | Reports that a popover was displayed | $TB.popoverShown('{{ slotid }}') |
$TB.popoverDismissed | Reports that a popover was closed | $TB.popoverDismissed('{{ slotid }}') |
$TB.popoverSubmitted | Reports that a popover form was submitted | $TB.popoverSubmitted('{{ slotid }}', emailAddress) |
You can include additional data with the popover submission using the extended format:
javascript
$TB.popoverSubmitted('{{ slotid }}', emailAddress, rootData, extendData)
Person fields
The rootData object can contain these core person fields:
Parameter | Description |
e | Plain email address |
b64e | Base64-encoded email address |
rc4e | RC4-encrypted email address |
cid | Customer ID, usually a username or user ID used on your website |
curr | Currency |
eid | External ID, usually to identify users in an ESP |
fn | First name |
lang | Site language |
ln | Last name |
mobile | Mobile/Cell/SMS number |
perm | Permission to send emails to the person |
sbr | Site brand |
extendData
contains any other data that you want to submit with this popover.
Example with extended data
This example shows how to submit a popover with the customer's name and gender:
$TB.popoverSubmitted({{ slotid }}, emailAddress, {'fn': firstName, 'ln': lastName}, {'gender': customerGender})