Articles on: Developers

How to track the UTM source

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:

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

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

    var crisp_keys = [];

    ["utm_source", "utm_medium", "utm_campaign", "utm_term", "utm_content"].forEach(function(source) {
      if (getUrlVars()[source]) {
        crisp_keys.push([source, getUrlVars()[source]]);

    if (crisp_keys.length > 0) {
      $crisp.push(["set", "session:data", [crisp_keys]]);

Updated on: 13/06/2022

Was this article helpful?

Share your feedback


Thank you!