Javascript Tracking

Each Distil Account has its own unique organisational identifier that will be included in their tracking script. This information is included on the Tracking page within the Distil Settings screen, like so:

image14.png

Placement of JS Code

The JavaScript snippet will load the Distil Tracking script onto the page and initialise it. It should be placed in the Head section of the page (recommended) or within the Body for every page on your site.

Using the JS Code

The JS code will automatically create a unique identifier (AnonymousID) for each user visiting the site, and store this information in local storage for re-use over time (i.e. so that the same ID is used for the same user across multiple visits). The code will also automatically capture the page the user is on, their IP address, the referring URL and the time of the event – nothing has to be done by the developer to enable this, it is automatically included on every call to the tracking functions.

These pieces of information are called the ‘Context’ Object – as they provide automatic contextual information about each tracking call made.

Example of the context object information:

  “Context”: {
    “DistilAccountId”: “f1a2df172a8045489d95cf4658bd60ba”,
    “AnonymousUserID”: “598b0746-a073-4ac6-aa68-808ec3f6df68”,
    “Device Information”: “Mozilla/5.0 (Macintosh; Intel Mac OS X 11_2_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/89.0.4389.114 Safari/537.36”,
    “EventTimestampUTC”: “2021-04-13 16:26:12”,
    “EventTimestampLocal”: “2021-04-13 17:26:12”,
    “PageTitle”: “Product 2”,
    “PageUrl”: “http://www.fakesite.com/product-2”,
    “ReferrerUrl”: “http://www.fakesite.com/product-1”,
    “IpAddress”: “86.161.138.123”
  }

Therefore to use the Distil tracking code, once it has been included on the page, it is a matter of calling the correct tracking event functions at the correct time.

Tracking Events

The following events / functions are available in the Distil tracking code to track the following types of interaction that may occur on the website:

Data Types

The following are the data types that are accepted by the Distil Tracking JavaScript – in the JSON object property blocks

TypeDescriptionExample
StringAny combination of characters surrounded by double quotes (double quotes are always recommended rather than a single quote). There should not be any line return characters contained within the string.“Title” : “This is a string”
BooleanA true or false value – without quotes“Available” : true
DecimalA numerical value with a decimal point. “Amount” : 12.34
IntegerA numerical value representing a whole number“Age” : 23
Date (String)A DateTime represented as a string in the following format : yyyy-MM-dd HH:mm:ss“expirydate” : “2021-09-17 10:00:00”

Identify Customer

When a user is browsing the site – their browsing history is tied to their AnonymousID.

When someone identifies themselves explicitly, by either logging in, or filling in a form with personal details, we can then capture this information and tie it to the browsing history. The identifyCustomer event needs to be added to all pages where this type of activity occurs.

In order to do that, we require that the identifyCustomer event is called: 

distil.identifyCustomer(customerProperties);

with the following argument passed to the function:

ArgumentData TypeDescription
customerPropertiesJSON ObjectA JSON Object containing all of the other user properties to record. Any customer property the Distil Account would like to record can be passed in this JSON object. Distil will automatically try to recognise the properties sent based on the name of the property, and so naming is key.

There are some mandatory properties for the identifyCustomer function – which are referenced below.

PropertyTypeDescriptionMandatory
CustomerIdStringID of the CustomerYes
EmailAddressStringEmail Address for the CustomerYes
GDPRStatusJSONGDPRStatus Object – see definition below for object properties belowYes
FirstNameStringThe Customer’s First NameNo
LastNameStringThe Customer’s Last NameNo
FacebookSlugStringThe URI to the customer facebook profile No
TwitterHandleStringThe URI to the customer twitter profile No
InstagramHandleStringThe URI to the customer instagram profile No
PostalAddressJSONPostalAddress Object – see definition below for object properties below No

Customer GDPRStatus Object properties

PropertyTypeDescriptionMandatory
MarketingSubscribedBooleanWhether the user has opted in Yes
RightOfAccessRequestedBooleanWhether the user has been asked to opt in No
DataAnonymizationBooleanWhether the user has asked for their data to be anonymised No

Customer PostalAddress Object properties

PropertyTypeDescriptionMandatory
Line1StringCustomer’s Address Line 1No
Line 2StringCustomer’s Address Line 2No
Line 3StringCustomer’s Address Line 3No
TownStringCustomer’s Address TownNo
RegionStringCustomer’s Address RegionNo
CountryStringCustomer’s Address CountryNo
PostcodeStringCustomer’s Address PostcodeNo

Examples of call with only mandatory fields:

1. With Customer ID

<script>

  let customerProperties = {
  CustomerId: ‘1234’,
  GDPRStatus: {
    MarketingSubscribed: true / false
  }
  }

  distil.identifyCustomer(customerProperties);

</script>

2. With Email Address

<script>

  let customerProperties = {
  EmailAddress: ‘user@yourcompany.com‘,
  GDPRStatus: {
    MarketingSubscribed: true / false
  }
  }

  distil.identifyCustomer(customerProperties);

</script>

3. Or With Both CustomerID and Email Address

<script>

  let customerProperties = {

   CustomerId: ‘1234’,
  EmailAddress: ‘user@yourcompany.com‘,
  GDPRStatus: {
    MarketingSubscribed: true / false
  }
  }

  distil.identifyCustomer(customerProperties);

</script>

Other Custom properties

All other fields included in the customerProperties JSON object will be saved against the Customer and will be available within Distil.

Track Product

When a user views a single product page on the website, this information can be captured using the trackProduct event, which needs to be added to all pages where this type of activity occurs.

In order to do that, we require that the trackProduct event is called:

distil.trackProduct(productProperties, customerProperties);

with the following 2 arguments passed to the function:

ArgumentData TypeDescription
productPropertiesJSON ObjectA JSON Object containing all of the other product properties to record. Any product property the Organisation would like to record can be passed in this JSON object. Distil will automatically try to recognise the properties sent based on the name of the property, and so naming is key.There are some mandatory properties for the trackProduct function – which are referenced below.
customerPropertiesJSON ObjectA JSON Object containing all of the other Customer properties to record for this event. The customerProperties are not mandatory and can be omitted – but if the object is supplied, then at least one of the identifying properties for the customer must be included (i.e. CustomerId or EmailAddress) 

Product Properties

The properties which are automatically recognised by Distil are:

PropertyTypeDescriptionMandatory
ProductIdStringThe Product IDYes
NameStringThe name of the ProductYes
PrecisStringThe description of the productNo
ThumbnailUrlStringThe URI to a thumbnail image for the productNo
FullImageUrlStringThe URI to a full size image for the productNo
ProductShopUrlStringThe URI to the product in the shop / storeNo
CategoriesStringA comma delimited list of the categories the product belongs toNo
AvailableBooleanA boolean indicating whether the product is currently available No
ListPriceExTaxDecimalThe price of the product with no taxNo
ListPriceIncTaxDecimalThe price of the product including taxNo
CurrencyStringThe 3 letter currency codeNo
PriceBreaksDescStringThis is only used in the case of building campaigns directly from this data so can be formatted as you wishNo

All other properties not listed above in the productProperties JSON object will be saved as Custom Properties in Distil.

Example of call with only mandatory fields:

let productProperties = {
  ProductId : “Prod1234”,
  Name: “Product Name goes here”
}

distil.trackProduct(productProperties);

The customer property is not passed in the above as it is not mandatory.

Example of call with Customer Properties included:

let productProperties = {
  ProductId : “Prod1234”,
  Name: “Product Name goes here”
}

let customerProperties = {
  EmailAddress: “joe.bloggs@acme.com”
}

distil.trackProduct(productProperties, customerProperties);

Track Content

When a user views a Content page on the website, this information can be captured using the trackContent event, which needs to be added to all pages where this type of activity occurs.

In order to do that, we require that the trackContent event is called:

distil.trackContent(contentProperties, customerProperties);

with the following 2 arguments passed to the function:

ArgumentData TypeDescription
contentPropertiesJSON ObjectA JSON Object containing all of the other content properties to record. Any content property the Organisation would like to record can be passed in this JSON object. Distil will automatically try to recognise the properties sent based on the name of the property, and so naming is key.There are some mandatory properties for the trackContent function – which are referenced below.
customerPropertiesJSON ObjectA JSON Object containing all of the other Customer properties to record for this event. The customerProperties are not mandatory and can be omitted – but if the object is supplied, then at least one of the identifying properties for the customer must be included (i.e. CustomerId or EmailAddress) .

Content Properties

Additional content properties which are automatically recognised by Distil are:

PropertyTypeDescriptionMandatory
ContentIdStringThe ID of the ContentYes
TitleStringThe title of the ContentYes
ContentTypeStringThe Type of ContentNo
ThumbnailUrlStringThe URI to a thumbnail image for the contentNo
FullImageUrlStringThe URI to the full image for the contentNo
PublicUrlStringThe URI to the content No
PrecisStringDescription for the contentNo
PublishedOnUTCDate (String)Date of PublishingNeed to be in the format : ‘yyyy-MM-dd HH:mm:ss’i.e. ‘2021-05-25 11:34:01’No
ExpiresOnUTCDate (String)Date the content expiresNeed to be in the format : ‘yyyy-MM-dd HH:mm:ss’i.e. ‘2021-05-25 11:34:01’No
KeyWordsStringList of comma separated keywords for the contentNo
AvailableBooleanA boolean indicating whether the content is currently available No

All other properties not listed above in the contentProperties JSON object will be saved as Custom Properties in Distil.

Example of call with only mandatory fields:

let contentProperties = {
  ContentId: “Cont1234”,
    Title: “Content Title goes here”
  }

  distil.trackContent(contentProperties);

The customer property is not passed in the above as it is not mandatory.

Example of call with Customer Properties included:

let contentProperties = {
ContentId: “Cont1234”,
  Title: “Content Title goes here”
};

let customerProperties = {
  EmailAddress: “joe.bloggs@acme.com”
};

distil.trackContent(contentProperties, customerProperties);

Track Order

When a user places an order on the website, this information is captured using the trackOrder event, which needs to be added to all pages where this type of activity occurs.

In order to do that, we require that the trackOrder event is called:

distil.trackOrder(orderProperties, customerProperties);

with the following 2 arguments passed to the function:

ArgumentData TypeDescription
orderPropertiesJSON ObjectA JSON Object containing all of the order properties to record. Any order property the Organisation would like to record can be passed in this JSON object. Distil will automatically try to recognise the properties sent based on the name of the property, and so naming is key.There are some mandatory properties for the trackOrder function – which are referenced below.
customerPropertiesJSON ObjectA JSON Object containing all of the other Customer properties to record for this event. The Customer details are not mandatory and can be omitted – but if the object is supplied, then at least one of the identifying properties for the customer must be included (i.e. CustomerId or EmailAddress) 

OrderProperties Object

Additional order properties which are automatically recognised by Distil are:

PropertyTypeDescriptionMandatory
OrderIdStringThe Order IDYes
OrderLineItemsJSONSee OrderLineItems object definition below for the object properties.Yes
TotalOrderValueExTaxDecimalThis is the Total Order Value excluding any Tax. The value should be in the same Currency as specified in the Currency Attribute.No
TotalOrderValueIncTaxDecimalThis is the Total order Value including Tax. No
PaymentMethodStringFree text string for you to specify the Payment method.No
CurrencyStringISO Currency Code. No
BillingAddressJSONAddress Object – see definition below for object propertiesNo
DeliveryAddressJSONAddress Object – see definition below for object propertiesNo

OrderLineItems Object Properties

PropertyTypeMandatoryMandatory
OrderExternalIdStringThe Order Id (same as the OrderId property in the OrderProperties object)Yes
ProductIdStringThis should match a Product Id from the Product DataYes
OrderLineItemIdStringThe unique line item ID (can be a concatenation of the OrderExternalId and ProductId if the system does not have such a concept)No
NameStringThe Name of the productNo
UrlStringURL to the Product pageNo
QtyIntegerThis is the Qty of the Product in this Line ItemNo
PriceExTaxDecimalThe price of the item excluding taxNo
PriceInTaxDecimalThe price of the item including taxNo
ThumbnailUrlStringURL to the Product ThumbnailNo
FullImageUrlStringURL to the Product image in fullNo
CategoriesArray (String)An array of Categories for the productNo

Address object properties

PropertyTypeDescriptionMandatory
TitleStringTitle of the CustomerNo
FirstNameStringFirst Name of the CustomerNo
LastNameStringLast Name of the CustomerNo
Line1StringLine 1 of the AddressNo
Line2StringLine 1 of the AddressNo
Line3StringLine 1 of the AddressNo
TownStringTown/City for the addressNo
RegionStringRegion of the addressNo
CountryStringCountry for the AddressNo
PostcodeStringPostcode of the AddressNo
PhoneStringThe Customer’s phone numberNo
CompanyStringThe name of the CompanyNo

All other properties not listed above in the orderProperties JSON object will be saved as Custom Properties in Distil.

CustomerProperties object properties

PropertyTypeDescriptionMandatory
CustomerIdStringID of the CustomerYes
EmailAddressStringEmail Address for the CustomerYes
GDPRStatusJSONGDPRStatus Object – see definition below for object properties belowNo
FacebookSlugStringThe URI to the customer facebook profileNo
TwitterHandleStringThe URI to the customer twitter profileNo
InstagramHandleStringThe URI to the customer instagram profileNo
PostalAddressJSONPostalAddress Object – see definition below for object properties belowNo

GDPRStatus Object properties

PropertyTypeDescriptionMandatory
MarketingSubscribedBooleanWhether the user has opted inNo
RightOfAccessRequestedBooleanWhether the user has been asked to opt inNo
DataAnonymizationBooleanWhether the user has asked for their data to be anonymisedNo

PostalAddress Object properties

PropertyTypeDescriptionMandatory
Line1StringCustomer’s Address Line 1No
Line 2String Customer’s Address Line 2No
Line 3StringCustomer’s Address Line 3No
TownStringCustomer’s Address TownNo
RegionStringCustomer’s Address RegionNo
CountryStringCustomer’s Address CountryNo
PostcodeStringCustomer’s Address PostcodeNo

Example of call with only mandatory fields

let orderProperties = {
  OrderId: “Ord1234”,
  OrderLineItems: [{
    OrderExternalId: “Ord1234”,
    ProductId: “ABC-1234”
  }]
};

let customerProperties = {
  EmailAddress: ‘user@yourcompany.com’
};

distil.trackOrder(orderProperties, customerProperties);