Skip to content

Commit

Permalink
Merge branch 'main' into update_readme
Browse files Browse the repository at this point in the history
  • Loading branch information
gvidoou committed Oct 22, 2024
2 parents a06b447 + 462db42 commit bb0b321
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,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
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 cookieName = 'li_fat_id';

const eventData = getAllEventData();

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

if (data.type === 'page_view') {
const url = eventData.page_location || getRequestHeader('referer');

Expand Down Expand Up @@ -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';
}
36 changes: 36 additions & 0 deletions template.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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');
Expand Down Expand Up @@ -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___

Expand Down

0 comments on commit bb0b321

Please sign in to comment.