Help Centre

<

Home
JavaScript Consent API

Salesfire’s JavaScript Consent API is an optional, deeper integration for merchants who need more control over how consent is handled.

Overview

The Consent API integrates seamlessly with Salesfire’s tracking system, providing granular control over three consent categories:

  • Preferences: Controls user preference tracking and customisation features
  • Analytics: Controls tracking of user behaviour, page views, and performance metrics
  • Marketing: Controls marketing-related tracking, personalisation, and retargeting

How It Works

The Consent API operates on a simple principle: tracking events are queued when consent is unknown, executed immediately when granted, and dropped when denied.

This ensures no tracking data is collected without proper consent while maintaining a smooth on-site experience.

Installation

Enable Consent API

To enable the Consent API, you need to set the consent mode to enforced. This tells Salesfire that all tracking should respect consent signals provided by your site.

Note: This must be set before any other Salesfire events are pushed into sfDataLayer and before the Salesfire script is loaded.

window.sfDataLayer = window.sfDataLayer || [];
window.sfDataLayer.push({
  consentMode: 'enforced'
});

Informing of consent

Once enabled, you can inform Salesfire of a visitor’s consent preferences. This can be done:

  • Immediately at page load, if consent is already known
  • After an action on your site, such as when a visitor interacts with your cookie banner
window.sfDataLayer = window.sfDataLayer || [];
window.sfDataLayer.push({
  preferences: true,
  analytics: true,
  marketing: false
});

By default, Salesfire caches the consent result for 6 months, in line with industry standards. You can customise this by passing a consentExpiration value (in minutes):

window.sfDataLayer.push({
  preferences: true,
  analytics: true,
  marketing: false,
  consentExpiration: 60 * 24 * 30 // 30 days
});

Integration Examples

OneTrust

Example only: Professional integration is required. Please consult OneTrust’s documentation and your technical team before implementing.

const OT_MAP = {
  preferences: 'C0001',
  analytics: 'C0002',
  marketing: 'C0003'
};

function has(id) {
  return typeof OnetrustActiveGroups === 'string' &&
         OnetrustActiveGroups.split(',').includes(id);
}

function updateConsentFromOneTrust() {
  window.sfDataLayer = window.sfDataLayer || [];
  window.sfDataLayer.push({
    preferences: has(OT_MAP.preferences),
    analytics: has(OT_MAP.analytics),
    marketing: has(OT_MAP.marketing)
  });
}

if (window.OnetrustActiveGroups) updateConsentFromOneTrust();
window.OneTrust?.OnConsentChanged && OneTrust.OnConsentChanged(updateConsentFromOneTrust);

Cookiebot

Example only: Professional integration is required. Please consult Cookiebot’s documentation and your technical team before implementing.

function updateConsentFromCookiebot() {
  const c = window.Cookiebot.consent;
  window.sfDataLayer = window.sfDataLayer || [];
  window.sfDataLayer.push({
    preferences: c.preferences,
    analytics: c.statistics,
    marketing: c.marketing
  });
}

window.addEventListener('CookiebotOnConsentReady', updateConsentFromCookiebot);
window.addEventListener('CookiebotOnConsentChange', updateConsentFromCookiebot);

if (window.Cookiebot && window.Cookiebot.consent) updateConsentFromCookiebot();