Skip to content

Commit

Permalink
Merge pull request #19 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 34f6097 + 9b42df0 commit f815e10
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 0 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: 7f38905d9da155cd8e125bfcf3f4d0228cbf97b2
changeNotes: Consent settings section.
- sha: 0d86e9a4a5fc5add1109cf5b1a8b9f020a862dcf
changeNotes: Content type fix.
- sha: 552235408d50a3b7228d649e1437b0b0600da428
Expand Down
11 changes: 11 additions & 0 deletions template.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ const gtmVersion = 'stape_2_0_1';
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 @@ -470,3 +474,10 @@ function generateTtp() {

return result;
}

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';
}
36 changes: 36 additions & 0 deletions template.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -531,6 +531,31 @@ ___TEMPLATE_PARAMETERS___
],
"help": "See \u003ca href\u003d\"https://ads.tiktok.com/marketing_api/docs?rid\u003d959icq5stjr\u0026id\u003d1701890979375106\" target\u003d\"_blank\"\u003ethis documentation\u003c/a\u003e for more details on what properties you can add to the event."
},
{
"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"
}
]
},
{
"type": "GROUP",
"name": "logsGroup",
Expand Down Expand Up @@ -589,6 +614,10 @@ const gtmVersion = 'stape_2_0_1';
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 @@ -1037,6 +1066,13 @@ function generateTtp() {
return result;
}

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 f815e10

Please sign in to comment.