Skip to content

Commit

Permalink
Merge pull request #52 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 ee6a5bb + 49c5ef1 commit a08fdd4
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 8 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: 5ba35048c523c380b6ed2904a8354c1dd71ec0e1
changeNotes: Added common cookie support.
- sha: 1ab4ccc09f86a65f2e2256b862f2b47f851b9075
changeNotes: Added support of x-fb-cd-content_type.
- sha: e1e5321231eaa46c13b397d5cedaa207ecefa7a8
Expand Down
10 changes: 6 additions & 4 deletions template.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,10 @@ if (url && url.lastIndexOf('https://gtm-msr.appspot.com/', 0) === 0) {
return data.gtmOnSuccess();
}

let fbc = getCookieValues('_fbc')[0];
let fbp = getCookieValues('_fbp')[0];
const commonCookie = eventData.common_cookie || {};

let fbc = getCookieValues('_fbc')[0] || commonCookie._fbc;
let fbp = getCookieValues('_fbp')[0] || commonCookie._fbp;

if (!fbc) fbc = eventData._fbc;
if (!fbp) fbp = eventData._fbp;
Expand Down Expand Up @@ -672,11 +674,11 @@ function setGtmEecCookie(userData) {

function enhanceEventData(userData) {
const cookieValues = getCookieValues('_gtmeec');
if (!cookieValues || cookieValues.length === 0) {
if ((!cookieValues || cookieValues.length === 0) && !commonCookie._gtmeec) {
return userData;
}

const encodedValue = cookieValues[0];
const encodedValue = cookieValues[0] || commonCookie._gtmeec;
if (!encodedValue) {
return userData;
}
Expand Down
10 changes: 6 additions & 4 deletions template.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -775,8 +775,10 @@ if (url && url.lastIndexOf('https://gtm-msr.appspot.com/', 0) === 0) {
return data.gtmOnSuccess();
}

let fbc = getCookieValues('_fbc')[0];
let fbp = getCookieValues('_fbp')[0];
const commonCookie = eventData.common_cookie || {};

let fbc = getCookieValues('_fbc')[0] || commonCookie._fbc;
let fbp = getCookieValues('_fbp')[0] || commonCookie._fbp;

if (!fbc) fbc = eventData._fbc;
if (!fbp) fbp = eventData._fbp;
Expand Down Expand Up @@ -1406,11 +1408,11 @@ function setGtmEecCookie(userData) {

function enhanceEventData(userData) {
const cookieValues = getCookieValues('_gtmeec');
if (!cookieValues || cookieValues.length === 0) {
if ((!cookieValues || cookieValues.length === 0) && !commonCookie._gtmeec) {
return userData;
}

const encodedValue = cookieValues[0];
const encodedValue = cookieValues[0] || commonCookie._gtmeec;
if (!encodedValue) {
return userData;
}
Expand Down

0 comments on commit a08fdd4

Please sign in to comment.