This article covers how to track UTM data and submit it to your Crisp customer's profile.

As explained on Wikipedia, UTM Parameters are five variants of URL parameters used by marketers to track the effectiveness of online marketing campaigns across traffic sources and publishing media.

Here is an example:

https://www.example.com/page?utm_content=buffercf3b2&utm_medium=social&utm_source=facebook.com&utm_campaign=buffer

In this case it could be very interesting to know that the visitor we are talking to is coming from a Facebook campaign.

A Javascript code to track UTM parameters

<script>
function getUrlVars() {
var vars = {};
var parts = window.location.href.replace(/[?&]+([^=&]+)=([^&]*)/gi, function(m,key,value) {
vars[key] = value;
});
return vars;
}

if (getUrlVars()["utm_source"]) {
$crisp.push(["set", "session:data", ["utm_source", getUrlVars()["utm_source"]]]);
}

if (getUrlVars()["utm_medium"]) {
$crisp.push(["set", "session:data", ["utm_medium", getUrlVars()["utm_medium"]]]);
}

if (getUrlVars()["utm_campaign"]) {
$crisp.push(["set", "session:data", ["utm_campaign", getUrlVars()["utm_campaign"]]]);
}

if (getUrlVars()["utm_term"]) {
$crisp.push(["set", "session:data", ["utm_term", getUrlVars()["utm_term"]]]);
}

if (getUrlVars()["utm_content"]) {
$crisp.push(["set", "session:data", ["utm_content", getUrlVars()["utm_content"]]]);
}
</script>
Was this article helpful?
Cancel
Thank you!