Skip to content

Commit

Permalink
Merge pull request #22 from stape-io/added-common-cookie-support
Browse files Browse the repository at this point in the history
Added common cookie support
  • Loading branch information
Bukashk0zzz authored Jul 12, 2024
2 parents 4187da2 + 6324a3f commit 7be6bf8
Show file tree
Hide file tree
Showing 3 changed files with 133 additions and 6 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: d09916e6d815e37dadd258473ce4bc65e2d50727
changeNotes: Added common cookie support.
- sha: f0b3afdab0acd076e71cf57bef517aa1f715c827
changeNotes: Update load data tag sript URL.
- sha: 6e81ef3f3e63f5b975277b9e04a0c7fc752c8212
Expand Down
47 changes: 44 additions & 3 deletions template.js
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,10 @@ function addDataForGetRequest(data, url) {
eventData = addConsentStateData(eventData);
}

if (data.add_common_cookie) {
eventData = addCommonCookie(eventData);
}

let customData = getCustomData(data, false);

if (customData.length) {
Expand Down Expand Up @@ -178,9 +182,13 @@ function addCommonDataForPostRequest(data, eventData) {
eventData.viewport_size =
dataTagData.innerWidth + 'x' + dataTagData.innerHeight;
}
if (data.add_consent_state) {
eventData = addConsentStateData(eventData);
}
}
if (data.add_consent_state) {
eventData = addConsentStateData(eventData);
}

if (data.add_common_cookie) {
eventData = addCommonCookie(eventData);
}

return eventData;
Expand Down Expand Up @@ -414,3 +422,36 @@ function getUserAndCustomDataArray() {
}
return userAndCustomDataArray;
}

function addCommonCookie(eventData) {
const cookieNames = [
// FB cookies
'_fbc',
'_fbp',
'_gtmeec',
// TikTok cookies
'ttclid',
'_ttp',
// Pinterest cookies
'_epik',
// Snapchat cookies
'_scid',
'_scclid',
// Taboola cookies
'taboola_cid',
];
let commonCookie = null;

for (var i = 0; i < cookieNames.length; i++) {
const name = cookieNames[i];
var cookie = getCookieValues(name)[0];
if (cookie) {
commonCookie = commonCookie || {};
commonCookie[name] = cookie;
}
}
if (commonCookie) {
eventData.common_cookie = commonCookie;
}
return eventData;
}
90 changes: 87 additions & 3 deletions template.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,13 @@ ___TEMPLATE_PARAMETERS___
"simpleValueType": true,
"help": "Adds \u003cb\u003econsent_state\u003c/b\u003e object to request.\u003cbr/\u003e\nIncluding following properties:\u003cbr/\u003e \nad_storage\u003cbr/\u003e\nad_user_data\u003cbr/\u003e\nad_personalization\u003cbr/\u003e\nanalytics_storage\u003cbr/\u003e\nfunctionality_storage\u003cbr/\u003e\npersonalization_storage\u003cbr/\u003e\nsecurity_storage"
},
{
"type": "CHECKBOX",
"name": "add_common_cookie",
"checkboxText": "Add Common Cookie",
"simpleValueType": true,
"help": "The tag will send common cookies in eventData to avoid some e-commerce platform limitations. Now supported by the next Stape tags: \u003cbr /\u003e\n\u003ca href\u003d\"https://tagmanager.google.com/gallery/#/owners/stape-io/templates/facebook-tag\" target\u003d\"_blank\"\u003eFacebook Conversion API\u003c/a\u003e\u003cbr /\u003e\n\u003ca href\u003d\"https://tagmanager.google.com/gallery/#/owners/stape-io/templates/tiktok-tag\" target\u003d\"_blank\"\u003eTikTok Events API\u003c/a\u003e\u003cbr /\u003e\n\u003ca href\u003d\"https://github.com/stape-io/pinterest-tag\" target\u003d\"_blank\"\u003ePinterest Conversion API\u003c/a\u003e\u003cbr /\u003e\n\u003ca href\u003d\"https://tagmanager.google.com/gallery/#/owners/stape-io/templates/snapchat-tag\" target\u003d\"_blank\"\u003eSnapchat Conversion API\u003c/a\u003e\u003cbr /\u003e\n\u003ca href\u003d\"https://tagmanager.google.com/gallery/#/owners/stape-io/templates/taboola-tag\" target\u003d\"_blank\"\u003eTaboola\u003c/a\u003e"
},
{
"type": "GROUP",
"name": "custom",
Expand Down Expand Up @@ -804,6 +811,10 @@ function addDataForGetRequest(data, url) {
eventData = addConsentStateData(eventData);
}

if (data.add_common_cookie) {
eventData = addCommonCookie(eventData);
}

let customData = getCustomData(data, false);

if (customData.length) {
Expand Down Expand Up @@ -852,9 +863,13 @@ function addCommonDataForPostRequest(data, eventData) {
eventData.viewport_size =
dataTagData.innerWidth + 'x' + dataTagData.innerHeight;
}
if (data.add_consent_state) {
eventData = addConsentStateData(eventData);
}
}
if (data.add_consent_state) {
eventData = addConsentStateData(eventData);
}

if (data.add_common_cookie) {
eventData = addCommonCookie(eventData);
}

return eventData;
Expand Down Expand Up @@ -1089,6 +1104,39 @@ function getUserAndCustomDataArray() {
return userAndCustomDataArray;
}

function addCommonCookie(eventData) {
const cookieNames = [
// FB cookies
'_fbc',
'_fbp',
'_gtmeec',
// TikTok cookies
'ttclid',
'_ttp',
// Pinterest cookies
'_epik',
// Snapchat cookies
'_scid',
'_scclid',
// Taboola cookies
'taboola_cid',
];
let commonCookie = null;
for (var i = 0; i < cookieNames.length; i++) {
const name = cookieNames[i];
var cookie = getCookieValues(name)[0];
if (cookie) {
commonCookie = commonCookie || {};
commonCookie[name] = cookie;
}
}
if (commonCookie) {
eventData.common_cookie = commonCookie;
}
return eventData;
}


___WEB_PERMISSIONS___

Expand Down Expand Up @@ -1584,6 +1632,42 @@ ___WEB_PERMISSIONS___
{
"type": 1,
"string": "stape"
},
{
"type": 1,
"string": "_fbc"
},
{
"type": 1,
"string": "_fbp"
},
{
"type": 1,
"string": "_gtmeec"
},
{
"type": 1,
"string": "ttclid"
},
{
"type": 1,
"string": "_ttp"
},
{
"type": 1,
"string": "_epik"
},
{
"type": 1,
"string": "_scid"
},
{
"type": 1,
"string": "_scclid"
},
{
"type": 1,
"string": "taboola_cid"
}
]
}
Expand Down

0 comments on commit 7be6bf8

Please sign in to comment.