Skip to content

Commit

Permalink
Merge pull request #7 from stape-io/consent-settings-section
Browse files Browse the repository at this point in the history
consent settings section
  • Loading branch information
Bukashk0zzz authored Mar 29, 2024
2 parents 2935468 + b5dc042 commit 1e38d83
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 2 deletions.
2 changes: 2 additions & 0 deletions metadata.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
homepage: "https://stape.io/"
versions:
- sha: 13bb6329d9e594b1dd9b86cb1a2793474d9575c3
changeNotes: Consent settings section.
- sha: a70a5ab2d5bc11707a72f9097b59fe02f9101487
changeNotes: Removed custom parse url funciton.
- sha: 0c049d2c3f851edba50799e02add978db7415cb7
Expand Down
12 changes: 11 additions & 1 deletion template.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ const getRequestHeader = require('getRequestHeader');
const getType = require('getType');
const Math = require('Math');
const generateRandom = require('generateRandom');
const decodeUriComponent = require('decodeUriComponent');
const parseUrl = require('parseUrl');

const containerVersion = getContainerVersion();
Expand All @@ -23,6 +22,10 @@ const traceId = getRequestHeader('trace-id');
const eventData = getAllEventData();
const url = eventData.page_location || getRequestHeader('referer');

if (!isConsentGivenOrNotRequired()) {
return data.gtmOnSuccess();
}

if (url && url.lastIndexOf('https://gtm-msr.appspot.com/', 0) === 0) {
return data.gtmOnSuccess();
}
Expand Down Expand Up @@ -416,3 +419,10 @@ function getClickId() {
}
return getCookieValues('_scclid')[0];
}

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';
}
37 changes: 36 additions & 1 deletion template.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -484,6 +484,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",
Expand Down Expand Up @@ -531,7 +556,6 @@ const getRequestHeader = require('getRequestHeader');
const getType = require('getType');
const Math = require('Math');
const generateRandom = require('generateRandom');
const decodeUriComponent = require('decodeUriComponent');
const parseUrl = require('parseUrl');

const containerVersion = getContainerVersion();
Expand All @@ -542,6 +566,10 @@ const traceId = getRequestHeader('trace-id');
const eventData = getAllEventData();
const url = eventData.page_location || getRequestHeader('referer');

if (!isConsentGivenOrNotRequired()) {
return data.gtmOnSuccess();
}

if (url && url.lastIndexOf('https://gtm-msr.appspot.com/', 0) === 0) {
return data.gtmOnSuccess();
}
Expand Down Expand Up @@ -936,6 +964,13 @@ function getClickId() {
return getCookieValues('_scclid')[0];
}

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___

Expand Down

0 comments on commit 1e38d83

Please sign in to comment.