Skip to content

Commit

Permalink
Add custom parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
jhuret committed Mar 20, 2023
1 parent f5f7e56 commit a475e36
Showing 1 changed file with 44 additions and 2 deletions.
46 changes: 44 additions & 2 deletions template.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,33 @@ ___TEMPLATE_PARAMETERS___
}
]
},
{
"type": "GROUP",
"name": "customParameters",
"displayName": "Custom Parameters",
"groupStyle": "ZIPPY_CLOSED",
"subParams": [
{
"type": "SIMPLE_TABLE",
"name": "customParametersTable",
"displayName": "",
"simpleTableColumns": [
{
"defaultValue": "",
"displayName": "ref",
"name": "ref",
"type": "TEXT"
},
{
"defaultValue": "",
"displayName": "value",
"name": "value",
"type": "TEXT"
}
]
}
]
},
{
"type": "GROUP",
"name": "advancedParameters",
Expand Down Expand Up @@ -196,7 +223,7 @@ switch (eventModel.event_name) {

if (!kwankoCookie || !kwankoCookie[0]) {
data.gtmOnSuccess();
break;
break;
}

const urlParams = [
Expand All @@ -205,7 +232,7 @@ switch (eventModel.event_name) {
'cible=' + safeEncodeUriComponent(kwankoCookie[0]),
'argann=' + safeEncodeUriComponent(data.transactionId ? data.transactionId : eventModel.transaction_id)
];

if (eventModel.event_name === PURCHASE_EVENT) {
urlParams.push('argmon=' + safeEncodeUriComponent(data.purchaseAmount ? data.purchaseAmount : eventModel.value));
Expand All @@ -223,6 +250,21 @@ switch (eventModel.event_name) {
urlParams.push(data.payName !== undefined ? 'argmodp=' + safeEncodeUriComponent(data.payName) : '');
}

const includedRef = [];
for (let key in data.customParametersTable) {
const row = data.customParametersTable[key];
if (includedRef.indexOf(row.ref) !== -1) {
continue;
}

if (row.value === undefined) {
continue;
}

includedRef.push(row.ref);
urlParams.push(row.ref + '=' + safeEncodeUriComponent(row.value));
}

const urlParamsString = urlParams.filter((v) => v).join('&');

if (data.clearCookie) {
Expand Down

0 comments on commit a475e36

Please sign in to comment.