Customerlabs CDP Documentation

You are here:

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>
Was this article helpful?
0 out Of 5 Stars
5 Stars 0%
4 Stars 0%
3 Stars 0%
2 Stars 0%
1 Stars 0%
5
How can we improve this article?
How Can We Improve This Article?
Need help?
Table of Contents
CustomerLabs gives freedom, flexibility and wings to digital marketers.
Sign Up

Be Part of the Next Era of Performance Marketing — Join Us in Bengaluru | Only 300 Seats -Know more

Schedule a 1-1 Demo