Customerlabs CDP Documentation
This article contains all the JavaScript Helper Functions (JS helper functions) that can be used to track all the events on your website.
GoKwik PaymentInfo Code
<script>
function productsConversion(productsArr) {
var products = [];
for (var i = 0; i < productsArr.length; i++) {
var productsStructure = {};
for (key in productsArr[i]) {
switch (key) {
case "item_name":
productsStructure["product_name"] = {
t: "string",
v: productsArr[i][key],
};
break;
case "item_id":
productsStructure["product_id"] = {
t: "string",
v: (productsArr[i] || {})[key],
};
break;
case "price":
productsStructure["product_price"] = {
t: "number",
v: productsArr[i][key],
};
break;
case "category":
productsStructure["product_category"] = {
t: "string",
v: productsArr[i][key],
};
break;
case "quantity":
productsStructure["product_quantity"] = {
t: "number",
v: productsArr[i][key],
};
break;
case "variant":
productsStructure["product_variant"] = {
t: "string",
v: productsArr[i][key],
};
break;
case "brand":
productsStructure["product_brand"] = {
t: "number",
v: productsArr[i][key],
};
break;
default:
if (productsArr[i][key]) {
var isNum = /^\d+$/.test(productsArr[i][key]);
var type =
Number.isFinite(productsArr[i][key]) || isNum ?
"number" :
typeof productsArr[i][key];
productsStructure["product_" + key] = {
t: type,
v: productsArr[i][key],
};
}
}
}
products.push(productsStructure);
}
return products;
}
var data = window.google_tag_manager["GTM-ABCDEFGH"].dataLayer.get("eventData");
var productProps = data["ecommerce"] || {};
var properties = {};
if (productProps) {
properties["customProperties"] = {
"currency": {
t: "string",
v: productProps.currency,
},
"content_type": {
t: "string",
v: "product_group",
},
"coupon": {
t: "string",
v: productProps.coupon,
},
"total_discount": {
t: "number",
v: productProps.total_discount,
},
"value": {
t: "number",
v: productProps.value,
},
};
properties["productProperties"] = productsConversion(productProps.items);
_cl.track("Checkout made", properties);
}
</script>