Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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: 7cd6168e4637a922c4e71f3c64fe47fc2fb20784
changeNotes: Added support for li_fat_id cookie from Data Tag common_cookie.
- sha: 3686f8f16ba42e7430ea7c11bf929625aea3718d
changeNotes: Updated consent section. Updated API version to 202601.
- sha: 94000fb78f50b2442788a620ae34628cfbf16910
Expand Down
27 changes: 20 additions & 7 deletions template.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,20 +22,18 @@ const sha256Sync = require('sha256Sync');
const isLoggingEnabled = determinateIsLoggingEnabled();
const traceId = isLoggingEnabled ? getRequestHeader('trace-id') : undefined;
const cookieName = 'li_fat_id';

const eventData = getAllEventData();

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

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

if (url) {
const value = parseUrl(url).searchParams[cookieName];

if (value) {
if (clickId) {
const options = {
domain: 'auto',
path: '/',
Expand All @@ -44,7 +42,7 @@ if (data.type === 'page_view') {
'max-age': 86400 * 90
};

setCookie(cookieName, value, options, false);
setCookie(cookieName, clickId, options, false);
}
}

Expand Down Expand Up @@ -239,8 +237,16 @@ function getUserEmail() {
}

function getLinkedInFirstPartyAdsTrackingUuid() {
const liFatId = decodeUriComponent(getCookieValues(cookieName)[0] || '');
return liFatId || userIdsOverride.linkedinFirstPartyId || user_data.linkedinFirstPartyId || '';
const commonCookie = eventData.common_cookie || {};
return (
parseClickIdFromUrl(eventData, cookieName) ||
getCookieValues(cookieName)[0] ||
commonCookie[cookieName] ||
eventData[cookieName] ||
userIdsOverride.linkedinFirstPartyId ||
user_data.linkedinFirstPartyId ||
''
);
}

function getAcxiomId() {
Expand Down Expand Up @@ -322,6 +328,13 @@ function getUserInfo() {
/*==============================================================================
Helpers
==============================================================================*/
function parseClickIdFromUrl(eventData, cookieName) {
const url = eventData.page_location || eventData.page_referrer || getRequestHeader('referer');
if (!url) return;

const urlSearchParams = parseUrl(url).searchParams;
return urlSearchParams[cookieName];
}

function isHashed(value) {
if (!value) {
Expand Down
27 changes: 20 additions & 7 deletions template.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -350,20 +350,18 @@ const sha256Sync = require('sha256Sync');
const isLoggingEnabled = determinateIsLoggingEnabled();
const traceId = isLoggingEnabled ? getRequestHeader('trace-id') : undefined;
const cookieName = 'li_fat_id';

const eventData = getAllEventData();

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

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

if (url) {
const value = parseUrl(url).searchParams[cookieName];

if (value) {
if (clickId) {
const options = {
domain: 'auto',
path: '/',
Expand All @@ -372,7 +370,7 @@ if (data.type === 'page_view') {
'max-age': 86400 * 90
};

setCookie(cookieName, value, options, false);
setCookie(cookieName, clickId, options, false);
}
}

Expand Down Expand Up @@ -567,8 +565,16 @@ function getUserEmail() {
}

function getLinkedInFirstPartyAdsTrackingUuid() {
const liFatId = decodeUriComponent(getCookieValues(cookieName)[0] || '');
return liFatId || userIdsOverride.linkedinFirstPartyId || user_data.linkedinFirstPartyId || '';
const commonCookie = eventData.common_cookie || {};
return (
parseClickIdFromUrl(eventData, cookieName) ||
getCookieValues(cookieName)[0] ||
commonCookie[cookieName] ||
eventData[cookieName] ||
userIdsOverride.linkedinFirstPartyId ||
user_data.linkedinFirstPartyId ||
''
);
}

function getAcxiomId() {
Expand Down Expand Up @@ -650,6 +656,13 @@ function getUserInfo() {
/*==============================================================================
Helpers
==============================================================================*/
function parseClickIdFromUrl(eventData, cookieName) {
const url = eventData.page_location || eventData.page_referrer || getRequestHeader('referer');
if (!url) return;

const urlSearchParams = parseUrl(url).searchParams;
return urlSearchParams[cookieName];
}

function isHashed(value) {
if (!value) {
Expand Down