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.

Shiprocket Create User:

<script>
  var userTraits = {};
var userkeys = ["first_name", "last_name", "email", "phone_num", "city", "state", "country", "pincode"];
userkeys.forEach(function(key){
    var trait = window.google_tag_manager["GTM-ABCDEFGH"].dataLayer.get(key);
    if(trait || trait === ""){
        userTraits[key] = trait;
    }
});

var email = userTraits["email"]; 
var phone = userTraits["phone_num"]; 

var userProperties = {
    "customProperties": {
        "user_traits": {
            "t": "Object",
            "v": {
                "firstname": {
                    "t": "string",
                    "v": userTraits["first_name"]
                },
                "lastname": { 
                    "t": "string",
                    "v": userTraits["last_name"]
                },
                "email": {
                    "t": "string", 
                    "v": email
                },
                "phone": {
                    "t": "string",
                    "v": phone
                },

                "city": {
                    "t": "string",
                    "v": userTraits["city"]
                },
                "state": {
                    "t": "string",
                    "v": userTraits["state"],
                },
                "country": {
                    "t": "string",
                    "v": userTraits["country"],
                },
                "zip": {
                    "t": "string",
                    "v": userTraits["pincode"],
                },
            }
        }
    },
};

if(email && email != null && email != ""){
    userProperties["customProperties"]["identify_by_email"] ={
        "t":"string",
        "v": email,
        "ib": true
    }
    if(phone && phone != null && phone != ""){
        userProperties["customProperties"]["external_ids"] = {
            "t": "Object",
            "v": {
                "identify_by_phone": {
                    "t":"string",
                    "v": phone
                }
            }
        }
    }
}else if(phone && phone != null && phone != ""){
    userProperties["customProperties"]["identify_by_phone"] = {
        "t":"string",
        "v": phone,
        "ib": true
    }
}
if (phone || email) {
    _cl.identify(userProperties);
}

</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