How to Implement Kissmetrics Tracking

Kissmetrics is an excellent tool for anyone with a website or web app, as it provides users with acquisition data for every customer. Through visualization tools, users can see how customers are interacting with their site and products. Best of all, although it is in no way related to Google Analytics, you can use Google Tag Manager to send your data to the Kissmetrics tool.how-to-implement-kissmetrics-tracking-1

Setting Up for Kissmetrics

To benefit from Kissmetrics, you need to create tag templates that will send events and properties to the tool. You will also want to identify users, which means connecting their anonymous IDs with real-world identifiers. To do this, you need to define a standard template tag and send the data it receives to Kissmetrics.

To achieve both of these aims, before you create any tags you need to create three dataLayer variables. The Data Layer Variables names should be as follows: km_event, km_property, and km_property_email. Set the Data Layer Version in all three to Version 2.

how-to-implement-kissmetrics-tracking-2The Tags

The first tags you need are template tags:

Tracking code

Set a tag called Kissmetrics - Tracking Code to fire first on each page. This will load the Kissmetrics tracking library. Set the tag type as Custom HTML and give it a tag firing property of I. You can find the tracking code you need on the Kissmetrics settings page.

Record events

Use a tag called Kissmetrics - Record Event to gain a standard template to send data to Kissmetrics. Set the tag type to Custom HTML and set trigger rule to event equals km_record. The tag content is as follows:

<script>

   var _kmq = window._kmq || [];

  _kmq.push(function() {

       _kmq.push(['record','{{km_event}}',{{km_property}}]);        

       // empty the km_property object so it can be reused for sending more events

       dataLayer.push({

           'km_property':{}

       });

       // this script is used for identifying user if a valid email address is found.

       var regEmail = /^\S+@\S+\.\S+$/;

       var email = "{{km_property_email}}".replace(/ /g,'');

       if (email.match(regEmail) !== null){

           _kmq.push(['identify', email]);

       }

   });

</script>

Send properties

Name a tag Kissmetrics - Set Property for a standard template to send properties to Kissmetrics. The tag type should be Custom HTML and trigger rule event equals km_set. The content is:

<script>

var _kmq = window._kmq || [];

_kmq.push(function() {

   _kmq.push(['set', {{km_property}}]);

   // empty the km_property object so it can be reused for sending more events

   dataLayer.push({

      'km_property':{}

   });

   // this script is used for identifying user if a valid email address is found.

   var regEmail = /^\S+@\S+\.\S+$/;

   var email = "{{km_property_email}}".replace(/ /g,'');

   if (email.match(regEmail) !== null){

       _kmq.push(['identify', email]);

   }

});

</script>

Next, you need some templates to format data appropriately .

Send events

The first tag will send events on Call to Action Click. Call this Kissmetrics - Record Buy Now, set the tag type to Custom HTML, and make the trigger rule event equals gtm.click, element ID equals buy-now. For the tag content, add:

<script>

dataLayer.push({

   'event':'km_record',

   'km_event':'Buy Now Clicked',

   'km_property':{

       'url':'{{page path}}',

       'button text':'{{element text}}'

   }

});

</script>

Identify users

Finally, you can find out exactly who is taking action by identifying users by their email address or some kind of internal ID. Use this code:

<script>

var regEmail = /^\S+@\S+\.\S+$/;

var email = "{{km_property_email}}".replace(/ /g,'');

if (email.match(regEmail) !== null){

   _kmq.push(['identify', email]);

}

</script>

Identify tag should fire with record event, set properties and identify user so that whenever a user email is passed to kissmetrics he will be identified and aliased with that email.

Make the most of everything Kissmetrics has to offer by adding all the above tags into Google Tag Manager. This will make managing and understanding data both easier and faster.

 

If you like my articles,