Skip to content

Commit

Permalink
Merge pull request #4 from stape-io/added-page-view-type
Browse files Browse the repository at this point in the history
Added page_view type
  • Loading branch information
kHorozhanov authored Mar 15, 2024
2 parents 0f2be86 + 54e071d commit 37924ef
Show file tree
Hide file tree
Showing 3 changed files with 179 additions and 3 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: bc7a5088976da3a828500f4a978e25401b80609a
changeNotes: Added Page View event type.
- sha: 991d3c20627eb30dc9f059e64668e34e4125a352
changeNotes: Update Access Token help link.
- sha: ab0b14b682472f6a87d2ec1f50043efc84a00c60
Expand Down
28 changes: 27 additions & 1 deletion template.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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 ||
Expand Down
152 changes: 150 additions & 2 deletions template.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -39,6 +57,13 @@ ___TEMPLATE_PARAMETERS___
{
"type": "NON_EMPTY"
}
],
"enablingConditions": [
{
"paramName": "type",
"paramValue": "conversion",
"type": "EQUALS"
}
]
},
{
Expand All @@ -50,6 +75,13 @@ ___TEMPLATE_PARAMETERS___
{
"type": "NON_EMPTY"
}
],
"enablingConditions": [
{
"paramName": "type",
"paramValue": "conversion",
"type": "EQUALS"
}
]
},
{
Expand Down Expand Up @@ -102,6 +134,13 @@ ___TEMPLATE_PARAMETERS___
"newRowButtonText": "Add property",
"valueValidators": []
}
],
"enablingConditions": [
{
"paramName": "type",
"paramValue": "conversion",
"type": "EQUALS"
}
]
},
{
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -213,6 +259,13 @@ ___TEMPLATE_PARAMETERS___
"type": "SIMPLE_TABLE",
"newRowButtonText": "Add property"
}
],
"enablingConditions": [
{
"paramName": "type",
"paramValue": "conversion",
"type": "EQUALS"
}
]
},
{
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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 ||
Expand Down Expand Up @@ -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
}
]

Expand Down

0 comments on commit 37924ef

Please sign in to comment.