<
HomeSalesfire’s JavaScript Consent API is an optional, deeper integration for merchants who need more control over how consent is handled.
The Consent API integrates seamlessly with Salesfire’s tracking system, providing granular control over three consent categories:
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.
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'
});Once enabled, you can inform Salesfire of a visitor’s consent preferences. This can be done:
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
});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);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();