Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Required Permissions
- const logToConsole = require('logToConsole');
- const log = data.debug ? logToConsole : (() => {});
- const injectScript = require('injectScript');
- const setInWindow = require('setInWindow');
- const copyFromWindow = require('copyFromWindow');
- const queryPermission = require('queryPermission');
- const encodeUriComponent = require('encodeUriComponent');
- const getCookieValues = require('getCookieValues');
- //Enables cookies to be read
- const cookieName = "cje";
- let cookieValues;
- if (queryPermission('get_cookies', cookieName)) {
- cookieValues = getCookieValues(cookieName);
- var cje = cookieValues.toString();
- }
- //Logging For Tests
- const onSuccess = () => {
- log('CJ: Script loaded successfully.');
- data.gtmOnSuccess();
- };
- const onFailure = () => {
- log('CJ: Script load failed.');
- data.gtmOnFailure();
- };
- //Enables user specified Data Layer array and array objects to be Read.
- const callInWindow = require('callInWindow');
- const getType = require('getType');
- // capture item level values from template field
- var inputArray = data.productArray;
- var productKey = data.productSku;
- var priceKey = data.productPrice;
- var quantityKey = data.productQuantity;
- var discountKey = data.productDiscount;
- // capture standard values from template fields
- var companyID = data.companyID;
- var actionID = data.actionID;
- var orderID = data.orderID;
- var wholeOrderDiscount = data.wholeOrderDiscount;
- var currency = data.currency;
- var coupon = data.coupon;
- var orderSubTotal = data.orderSubTotal;
- var page = data.pageType;
- //create item array if Advanced data is input by user
- if(inputArray != null) {
- var items = [];
- for (let i = 0; i < inputArray.length; i++) {
- const element = inputArray[i];
- let product = [];
- product.itemId = element[productKey];
- product.unitPrice = element[priceKey];
- product.quantity = element[quantityKey];
- product.discount = element[discountKey];
- items.push(product);
- }}
- // Create object from customParameters table if data is input by user
- if(data.customParameters != null){
- const makeTableMap = require('makeTableMap');
- const customParams = data.customParameters; // This is the array of user input from Custom Parameters Field
- var customParameterMap = makeTableMap(customParams, 'customFieldName', 'customFieldValue');
- }
- if (data.dataTypeSelect == 'orderData'){
- var cjData = {
- order:{
- 'enterpriseId' : companyID,
- 'orderId' : orderID,
- 'cjeventOrder' : cje,
- 'actionTrackerId' : actionID,
- 'currency' : currency,
- 'amount' : orderSubTotal,
- 'discount' : wholeOrderDiscount,
- 'coupon' : coupon,
- 'pointOfSale' : 'web',
- 'trackingSource' : 'gtm',
- 'pageType' : 'conversionConfirmation',
- '' : customParameterMap,
- 'items' : items
- }};
- }
- if (data.dataTypeSelect == 'pageData'){
- var cjData = {
- sitePage:{
- 'enterpriseId' : companyID,
- 'cartSubtotal' : orderSubTotal,
- 'trackingSource' : 'gtm',
- 'pageType' : page,
- '' : customParameterMap,
- 'items' : items
- }};
- }
- setInWindow("cj", cjData, true);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement