Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 6 additions & 21 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
const callInWindow = require("callInWindow");
const injectScript = require("injectScript");
const setDefaultConsentState = require("setDefaultConsentState");
const updateConsentState = require("updateConsentState");
const createQueue = require("createQueue");

const dataLayerPush = createQueue("dataLayer");

const callInWindow = require("callInWindow");
const injectScript = require("injectScript");
/*
* Because we can't rely on Fides.js to be initialized or even loaded before the GTM container, we use
* the GTM events to update the consent state. If Fides.js runs before this, it will push the events to
Expand Down Expand Up @@ -62,9 +58,6 @@ const CONSENT_MAP = {
security_storage: ["essential"],
};

const isFidesEvent = data.event.indexOf("Fides") > -1;
const isFidesConsentModeEvent = data.event.indexOf("FidesConsentMode") > -1;
const isNonConsentModeFidesEvent = isFidesEvent && !isFidesConsentModeEvent;

if (data.event === "gtm.init_consent") {
// The default Consent Initialization trigger fired
Expand Down Expand Up @@ -102,9 +95,9 @@ if (data.event === "gtm.init_consent") {
data.gtmOnSuccess();
},
data.gtmOnFailure
);
}
} else if (isNonConsentModeFidesEvent) {
);
}
} else if (data.event.indexOf("Fides") > -1) {
// This update only has an effect when Fides.consent contains privacy notice keys
updateGTMConsent(data.fides.consent, data.event);
}
Expand All @@ -119,8 +112,6 @@ return data.gtmOnSuccess();

function updateGTMConsent(fidesConsent, event) {
const gtmConsent = {};
const fidesConsentModeEvent = "FidesConsentMode" + event.split("Fides")[1];

for (const key in CONSENT_MAP) {
const values = [];
for (const value of CONSENT_MAP[key]) {
Expand All @@ -134,10 +125,4 @@ function updateGTMConsent(fidesConsent, event) {

updateConsentState(gtmConsent);

// Push an event to the dataLayer that represents the updated consent mode state
// This event will contain the latest consent update state and can be used as a trigger event
dataLayerPush({
Fides: data.fides.consent,
event: fidesConsentModeEvent,
});
}
}
25 changes: 5 additions & 20 deletions template.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -562,14 +562,10 @@ ___WEB_PERMISSIONS___

___SANDBOXED_JS_FOR_WEB_TEMPLATE___

const callInWindow = require("callInWindow");
const injectScript = require("injectScript");
const setDefaultConsentState = require("setDefaultConsentState");
const updateConsentState = require("updateConsentState");
const createQueue = require("createQueue");

const dataLayerPush = createQueue("dataLayer");

const callInWindow = require("callInWindow");
const injectScript = require("injectScript");
/*
* Because we can't rely on Fides.js to be initialized or even loaded before the GTM container, we use
* the GTM events to update the consent state. If Fides.js runs before this, it will push the events to
Expand Down Expand Up @@ -626,9 +622,6 @@ const CONSENT_MAP = {
security_storage: ["essential"],
};

const isFidesEvent = data.event.indexOf("Fides") > -1;
const isFidesConsentModeEvent = data.event.indexOf("FidesConsentMode") > -1;
const isNonConsentModeFidesEvent = isFidesEvent && !isFidesConsentModeEvent;

if (data.event === "gtm.init_consent") {
// The default Consent Initialization trigger fired
Expand Down Expand Up @@ -666,9 +659,9 @@ if (data.event === "gtm.init_consent") {
data.gtmOnSuccess();
},
data.gtmOnFailure
);
}
} else if (isNonConsentModeFidesEvent) {
);
}
} else if (data.event.indexOf("Fides") > -1) {
// This update only has an effect when Fides.consent contains privacy notice keys
updateGTMConsent(data.fides.consent, data.event);
}
Expand All @@ -683,8 +676,6 @@ return data.gtmOnSuccess();

function updateGTMConsent(fidesConsent, event) {
const gtmConsent = {};
const fidesConsentModeEvent = "FidesConsentMode" + event.split("Fides")[1];

for (const key in CONSENT_MAP) {
const values = [];
for (const value of CONSENT_MAP[key]) {
Expand All @@ -698,12 +689,6 @@ function updateGTMConsent(fidesConsent, event) {

updateConsentState(gtmConsent);

// Push an event to the dataLayer that represents the updated consent mode state
// This event will contain the latest consent update state and can be used as a trigger event
dataLayerPush({
Fides: data.fides.consent,
event: fidesConsentModeEvent,
});
}

___TESTS___
Expand Down