From bc7a5088976da3a828500f4a978e25401b80609a Mon Sep 17 00:00:00 2001 From: Kostiantyn Horozhanov Date: Fri, 15 Mar 2024 12:44:43 +0100 Subject: [PATCH 1/2] Added page_view type --- template.js | 28 +++++++++- template.tpl | 152 ++++++++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 177 insertions(+), 3 deletions(-) diff --git a/template.js b/template.js index beb55f9..2a5b5fb 100644 --- a/template.js +++ b/template.js @@ -14,11 +14,37 @@ const makeNumber = require('makeNumber'); const makeTableMap = require('makeTableMap'); const getCookieValues = require('getCookieValues'); const decodeUriComponent = require('decodeUriComponent'); +const parseUrl = require('parseUrl'); +const setCookie = require('setCookie'); const isLoggingEnabled = determinateIsLoggingEnabled(); const traceId = isLoggingEnabled ? getRequestHeader('trace-id') : undefined; +const cookieName = 'li_fat_id'; const eventData = getAllEventData(); + +if (data.type === 'page_view') { + const url = eventData.page_location || getRequestHeader('referer'); + + if (url) { + const value = parseUrl(url).searchParams[cookieName]; + + if (value) { + const options = { + domain: 'auto', + path: '/', + secure: true, + httpOnly: false, + 'max-age': 86400 * 90 + }; + + setCookie(cookieName, value, options, false); + } + } + + return data.gtmOnSuccess(); +} + const user_data = eventData.user_data || {}; const user_address = user_data.address || {}; const eventDataOverride = makeOverrideTableMap(data.eventData); @@ -178,7 +204,7 @@ function getUserEmail() { } function getLinkedInFirstPartyAdsTrackingUuid() { - const liFatId = decodeUriComponent(getCookieValues('li_fat_id')[0] || ''); + const liFatId = decodeUriComponent(getCookieValues(cookieName)[0] || ''); return ( liFatId || userIdsOverride.linkedinFirstPartyId || diff --git a/template.tpl b/template.tpl index 542603e..2078317 100644 --- a/template.tpl +++ b/template.tpl @@ -29,6 +29,24 @@ ___INFO___ ___TEMPLATE_PARAMETERS___ [ + { + "type": "RADIO", + "name": "type", + "displayName": "Event Type", + "radioItems": [ + { + "value": "page_view", + "displayValue": "Page View" + }, + { + "value": "conversion", + "displayValue": "Conversion" + } + ], + "simpleValueType": true, + "help": "\u003cb\u003ePage View\u003c/b\u003e - stores the li_fat_id URL parameter inside the li_fat_id cookie\u003cbr\u003e\u003cbr\u003e \u003cb\u003eConversion\u003c/b\u003e - Send request with data about the conversion to the LinkedIn", + "defaultValue": "conversion" + }, { "type": "TEXT", "name": "accessToken", @@ -39,6 +57,13 @@ ___TEMPLATE_PARAMETERS___ { "type": "NON_EMPTY" } + ], + "enablingConditions": [ + { + "paramName": "type", + "paramValue": "conversion", + "type": "EQUALS" + } ] }, { @@ -50,6 +75,13 @@ ___TEMPLATE_PARAMETERS___ { "type": "NON_EMPTY" } + ], + "enablingConditions": [ + { + "paramName": "type", + "paramValue": "conversion", + "type": "EQUALS" + } ] }, { @@ -102,6 +134,13 @@ ___TEMPLATE_PARAMETERS___ "newRowButtonText": "Add property", "valueValidators": [] } + ], + "enablingConditions": [ + { + "paramName": "type", + "paramValue": "conversion", + "type": "EQUALS" + } ] }, { @@ -158,7 +197,14 @@ ___TEMPLATE_PARAMETERS___ "newRowButtonText": "Add property" } ], - "groupStyle": "ZIPPY_CLOSED" + "groupStyle": "ZIPPY_CLOSED", + "enablingConditions": [ + { + "paramName": "type", + "paramValue": "conversion", + "type": "EQUALS" + } + ] }, { "displayName": "User Info Override", @@ -213,6 +259,13 @@ ___TEMPLATE_PARAMETERS___ "type": "SIMPLE_TABLE", "newRowButtonText": "Add property" } + ], + "enablingConditions": [ + { + "paramName": "type", + "paramValue": "conversion", + "type": "EQUALS" + } ] }, { @@ -264,11 +317,37 @@ const makeNumber = require('makeNumber'); const makeTableMap = require('makeTableMap'); const getCookieValues = require('getCookieValues'); const decodeUriComponent = require('decodeUriComponent'); +const parseUrl = require('parseUrl'); +const setCookie = require('setCookie'); const isLoggingEnabled = determinateIsLoggingEnabled(); const traceId = isLoggingEnabled ? getRequestHeader('trace-id') : undefined; +const cookieName = 'li_fat_id'; const eventData = getAllEventData(); + +if (data.type === 'page_view') { + const url = eventData.page_location || getRequestHeader('referer'); + + if (url) { + const value = parseUrl(url).searchParams[cookieName]; + + if (value) { + const options = { + domain: 'auto', + path: '/', + secure: true, + httpOnly: false, + 'max-age': 86400 * 90 + }; + + setCookie(cookieName, value, options, false); + } + } + + return data.gtmOnSuccess(); +} + const user_data = eventData.user_data || {}; const user_address = user_data.address || {}; const eventDataOverride = makeOverrideTableMap(data.eventData); @@ -428,7 +507,7 @@ function getUserEmail() { } function getLinkedInFirstPartyAdsTrackingUuid() { - const liFatId = decodeUriComponent(getCookieValues('li_fat_id')[0] || ''); + const liFatId = decodeUriComponent(getCookieValues(cookieName)[0] || ''); return ( liFatId || userIdsOverride.linkedinFirstPartyId || @@ -776,6 +855,75 @@ ___SERVER_PERMISSIONS___ "isEditedByUser": true }, "isRequired": true + }, + { + "instance": { + "key": { + "publicId": "set_cookies", + "versionId": "1" + }, + "param": [ + { + "key": "allowedCookies", + "value": { + "type": 2, + "listItem": [ + { + "type": 3, + "mapKey": [ + { + "type": 1, + "string": "name" + }, + { + "type": 1, + "string": "domain" + }, + { + "type": 1, + "string": "path" + }, + { + "type": 1, + "string": "secure" + }, + { + "type": 1, + "string": "session" + } + ], + "mapValue": [ + { + "type": 1, + "string": "li_fat_id" + }, + { + "type": 1, + "string": "*" + }, + { + "type": 1, + "string": "*" + }, + { + "type": 1, + "string": "any" + }, + { + "type": 1, + "string": "any" + } + ] + } + ] + } + } + ] + }, + "clientAnnotations": { + "isEditedByUser": true + }, + "isRequired": true } ] From 54e071dff688b765bbc72e49b151f5b08c45d02b Mon Sep 17 00:00:00 2001 From: Kostiantyn Horozhanov Date: Fri, 15 Mar 2024 14:17:07 +0100 Subject: [PATCH 2/2] Meta update --- metadata.yaml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/metadata.yaml b/metadata.yaml index 584c240..0e5860f 100644 --- a/metadata.yaml +++ b/metadata.yaml @@ -1,5 +1,7 @@ homepage: 'https://stape.io/' versions: + - sha: bc7a5088976da3a828500f4a978e25401b80609a + changeNotes: Added Page View event type. - sha: 991d3c20627eb30dc9f059e64668e34e4125a352 changeNotes: Update Access Token help link. - sha: ab0b14b682472f6a87d2ec1f50043efc84a00c60