diff --git a/metadata.yaml b/metadata.yaml index 4f3f6e8..43ed93c 100644 --- a/metadata.yaml +++ b/metadata.yaml @@ -1,6 +1,8 @@ homepage: 'https://stape.io/' documentation: "https://stape.io/blog/linkedin-conversion-api-tag-for-server-google-tag-manager" versions: + - sha: 224c0c5dbc7025830e17bb15bf60b7b4a6a8f58f + changeNotes: Added consent options. - sha: 962b61b2dcbbe560e3571033ea3023d783171828 changeNotes: Not send empty conversionValue. - sha: fd368e01b863881794c62752d9da0a138c2f8ddd diff --git a/template.js b/template.js index fb9c865..9af87a4 100644 --- a/template.js +++ b/template.js @@ -23,6 +23,10 @@ const cookieName = 'li_fat_id'; const eventData = getAllEventData(); +if (!isConsentGivenOrNotRequired()) { + return data.gtmOnSuccess(); +} + if (data.type === 'page_view') { const url = eventData.page_location || getRequestHeader('referer'); @@ -382,3 +386,10 @@ function determinateIsLoggingEnabled() { return data.logType === 'always'; } + +function isConsentGivenOrNotRequired() { + if (data.adStorageConsent !== 'required') return true; + if (eventData.consent_state) return !!eventData.consent_state.ad_storage; + const xGaGcs = eventData['x-ga-gcs'] || ''; // x-ga-gcs is a string like "G110" + return xGaGcs[2] === '1'; +} diff --git a/template.tpl b/template.tpl index 075b7d8..4b7ef43 100644 --- a/template.tpl +++ b/template.tpl @@ -268,6 +268,31 @@ ___TEMPLATE_PARAMETERS___ } ] }, + { + "type": "GROUP", + "name": "consentSettingsGroup", + "displayName": "Consent Settings", + "groupStyle": "ZIPPY_CLOSED", + "subParams": [ + { + "type": "RADIO", + "name": "adStorageConsent", + "displayName": "", + "radioItems": [ + { + "value": "optional", + "displayValue": "Send data always" + }, + { + "value": "required", + "displayValue": "Send data in case marketing consent given" + } + ], + "simpleValueType": true, + "defaultValue": "optional" + } + ] + }, { "displayName": "Logs Settings", "name": "logsGroup", @@ -326,6 +351,10 @@ const cookieName = 'li_fat_id'; const eventData = getAllEventData(); +if (!isConsentGivenOrNotRequired()) { + return data.gtmOnSuccess(); +} + if (data.type === 'page_view') { const url = eventData.page_location || getRequestHeader('referer'); @@ -686,6 +715,13 @@ function determinateIsLoggingEnabled() { return data.logType === 'always'; } +function isConsentGivenOrNotRequired() { + if (data.adStorageConsent !== 'required') return true; + if (eventData.consent_state) return !!eventData.consent_state.ad_storage; + const xGaGcs = eventData['x-ga-gcs'] || ''; // x-ga-gcs is a string like "G110" + return xGaGcs[2] === '1'; +} + ___SERVER_PERMISSIONS___