Skip to content

Commit

Permalink
Reformat with prettier
Browse files Browse the repository at this point in the history
  • Loading branch information
kHorozhanov committed Jun 21, 2024
1 parent 13782e2 commit b3a4473
Show file tree
Hide file tree
Showing 3 changed files with 166 additions and 125 deletions.
5 changes: 5 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"singleQuote": true,
"trailingComma": "none",
"printWidth": 150
}
146 changes: 82 additions & 64 deletions template.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,86 +15,104 @@ const isLoggingEnabled = determinateIsLoggingEnabled();
const traceId = getRequestHeader('trace-id');

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

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

if (value) {
const options = {
domain: 'auto',
path: '/',
secure: true,
httpOnly: false
};
if (value) {
const options = {
domain: 'auto',
path: '/',
secure: true,
httpOnly: false
};

if (data.expiration > 0) options['max-age'] = data.expiration;
if (data.expiration > 0) options['max-age'] = data.expiration;

setCookie('taboola_cid', value, options, false);
}
setCookie('taboola_cid', value, options, false);
}
}

data.gtmOnSuccess();
data.gtmOnSuccess();
} else {
const clickId = getCookieValues('taboola_cid')[0] || '';

if (!clickId) {
data.gtmOnSuccess();
const clickId = getCookieValues('taboola_cid')[0] || '';

return;
}

let requestUrl = 'https://trc.taboola.com/actions-handler/log/3/s2s-action?name='+enc(data.eventName)+'&click-id='+enc(clickId)+'&revenue='+enc(data.revenue)+'&currency='+enc(data.currencyCode)+'&orderid='+enc(data.orderId);

if (isLoggingEnabled) {
logToConsole(JSON.stringify({
'Name': 'Taboola',
'Type': 'Request',
'TraceId': traceId,
'EventName': data.eventName,
'RequestMethod': 'POST',
'RequestUrl': requestUrl,
}));
}
if (!clickId) {
data.gtmOnSuccess();

sendHttpRequest(requestUrl, (statusCode, headers, body) => {
if (isLoggingEnabled) {
logToConsole(JSON.stringify({
'Name': 'Taboola',
'Type': 'Response',
'TraceId': traceId,
'EventName': data.eventName,
'ResponseStatusCode': statusCode,
'ResponseHeaders': headers,
'ResponseBody': body,
}));
}

if (statusCode >= 200 && statusCode < 300) {
data.gtmOnSuccess();
} else {
data.gtmOnFailure();
}
}, {method: 'POST'});
return;
}

let requestUrl =
'https://trc.taboola.com/actions-handler/log/3/s2s-action?name=' +
enc(data.eventName) +
'&click-id=' +
enc(clickId) +
'&revenue=' +
enc(data.revenue) +
'&currency=' +
enc(data.currencyCode) +
'&orderid=' +
enc(data.orderId);

if (isLoggingEnabled) {
logToConsole(
JSON.stringify({
Name: 'Taboola',
Type: 'Request',
TraceId: traceId,
EventName: data.eventName,
RequestMethod: 'POST',
RequestUrl: requestUrl
})
);
}

sendHttpRequest(
requestUrl,
(statusCode, headers, body) => {
if (isLoggingEnabled) {
logToConsole(
JSON.stringify({
Name: 'Taboola',
Type: 'Response',
TraceId: traceId,
EventName: data.eventName,
ResponseStatusCode: statusCode,
ResponseHeaders: headers,
ResponseBody: body
})
);
}

if (statusCode >= 200 && statusCode < 300) {
data.gtmOnSuccess();
} else {
data.gtmOnFailure();
}
},
{ method: 'POST' }
);
}

function enc(data) {
data = data || '';
return encodeUriComponent(data);
data = data || '';
return encodeUriComponent(data);
}

function determinateIsLoggingEnabled() {
if (!data.logType) {
return isDebug;
}
if (!data.logType) {
return isDebug;
}

if (data.logType === 'no') {
return false;
}
if (data.logType === 'no') {
return false;
}

if (data.logType === 'debug') {
return isDebug;
}
if (data.logType === 'debug') {
return isDebug;
}

return data.logType === 'always';
return data.logType === 'always';
}
140 changes: 79 additions & 61 deletions template.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -190,88 +190,106 @@ const isLoggingEnabled = determinateIsLoggingEnabled();
const traceId = getRequestHeader('trace-id');

if (data.type === 'page_view') {
const url = getEventData('page_location') || getRequestHeader('referer');
const url = getEventData('page_location') || getRequestHeader('referer');
if (url) {
const value = parseUrl(url).searchParams[data.clickIdParameterName];
if (url) {
const value = parseUrl(url).searchParams[data.clickIdParameterName];
if (value) {
const options = {
domain: 'auto',
path: '/',
secure: true,
httpOnly: false
};
if (value) {
const options = {
domain: 'auto',
path: '/',
secure: true,
httpOnly: false
};

if (data.expiration > 0) options['max-age'] = data.expiration;
if (data.expiration > 0) options['max-age'] = data.expiration;

setCookie('taboola_cid', value, options, false);
}
setCookie('taboola_cid', value, options, false);
}
}

data.gtmOnSuccess();
data.gtmOnSuccess();
} else {
const clickId = getCookieValues('taboola_cid')[0] || '';
const clickId = getCookieValues('taboola_cid')[0] || '';
if (!clickId) {
data.gtmOnSuccess();
if (!clickId) {
data.gtmOnSuccess();
return;
}
return;
}

let requestUrl = 'https://trc.taboola.com/actions-handler/log/3/s2s-action?name='+enc(data.eventName)+'&click-id='+enc(clickId)+'&revenue='+enc(data.revenue)+'&currency='+enc(data.currencyCode)+'&orderid='+enc(data.orderId);

if (isLoggingEnabled) {
logToConsole(JSON.stringify({
'Name': 'Taboola',
'Type': 'Request',
'TraceId': traceId,
'EventName': data.eventName,
'RequestMethod': 'POST',
'RequestUrl': requestUrl,
}));
}
let requestUrl =
'https://trc.taboola.com/actions-handler/log/3/s2s-action?name=' +
enc(data.eventName) +
'&click-id=' +
enc(clickId) +
'&revenue=' +
enc(data.revenue) +
'&currency=' +
enc(data.currencyCode) +
'&orderid=' +
enc(data.orderId);

if (isLoggingEnabled) {
logToConsole(
JSON.stringify({
Name: 'Taboola',
Type: 'Request',
TraceId: traceId,
EventName: data.eventName,
RequestMethod: 'POST',
RequestUrl: requestUrl
})
);
}

sendHttpRequest(requestUrl, (statusCode, headers, body) => {
if (isLoggingEnabled) {
logToConsole(JSON.stringify({
'Name': 'Taboola',
'Type': 'Response',
'TraceId': traceId,
'EventName': data.eventName,
'ResponseStatusCode': statusCode,
'ResponseHeaders': headers,
'ResponseBody': body,
}));
}
sendHttpRequest(
requestUrl,
(statusCode, headers, body) => {
if (isLoggingEnabled) {
logToConsole(
JSON.stringify({
Name: 'Taboola',
Type: 'Response',
TraceId: traceId,
EventName: data.eventName,
ResponseStatusCode: statusCode,
ResponseHeaders: headers,
ResponseBody: body
})
);
}

if (statusCode >= 200 && statusCode < 300) {
data.gtmOnSuccess();
} else {
data.gtmOnFailure();
}
}, {method: 'POST'});
if (statusCode >= 200 && statusCode < 300) {
data.gtmOnSuccess();
} else {
data.gtmOnFailure();
}
},
{ method: 'POST' }
);
}

function enc(data) {
data = data || '';
return encodeUriComponent(data);
data = data || '';
return encodeUriComponent(data);
}

function determinateIsLoggingEnabled() {
if (!data.logType) {
return isDebug;
}
if (!data.logType) {
return isDebug;
}

if (data.logType === 'no') {
return false;
}
if (data.logType === 'no') {
return false;
}

if (data.logType === 'debug') {
return isDebug;
}
if (data.logType === 'debug') {
return isDebug;
}

return data.logType === 'always';
return data.logType === 'always';
}


Expand Down

0 comments on commit b3a4473

Please sign in to comment.