Installing Kissmetrics through Google Tag Manager

Google Tag Manager is a free tag management system. Rather than editing site code every time you want to add HTML/JavaScript snippets, you can install the Tag Manager script once and make updates from within Google.

The concept is similar to creating events with our Event Library , where you install our main piece of JavaScript once and manage your events within Kissmetrics.

Step 1: Get Started

Set up your account at the Google Tag Manager website. You’ll be asked to create a "container", which is a collection of tags for a website. Then you’ll get a piece of code:

Step 2: Install the Google Tag Manager Code + Kissmetrics Code

Make sure the provided Google Tag Manager script is placed on every page of your site.

For example, here’s a screenshot of installing in a Wordpress template (by going to Appearance -> Editor and changing the header.php file):

Step 3: Back in Google Tag Manager, Set Up a Tag for the Kissmetrics JavaScript Snippet

  • Back in Google Tag Manager, create a "Custom HTML Tag".

  • Please refer to your site’s Settings page to obtain your Kissmetrics JavaScript snippet, which you’ll place in the "HTML" field:

  • Click the button to +Add a Firing Rule, so that you can tell Google to load our snippet on All Pages:
  • Save this tag.

Step 4: Add Additional JavaScript for Custom Events

If you’d like, you can define custom Kissmetrics events by adding more tags to the container. In the next example, we’ll create a rule to record the "Viewed Homepage" event when people go to the URL path /.

Notice the presence of var _kmq = _kmq || [];. This is necessary because Google Tag Manager doesn’t let you control the order in which your tags are loaded. Without adding this line above your JavaScript for custom events, you may end up with JavaScript errors.

Step 5: Create a Container Version and Publish

  • When you are ready, go to the Container Draft Overview section on the left. Click the button to create a new version of your container and publish the changes.

That’s It!

As always, you can check in Kissmetrics Live to look for your own activity, and to check that you’ve installed properly.

👍

To recap, there are 4 steps:

  1. Create a tag containing the JavaScript snippet and/or API calls.
  2. Create a rule that tells on which pages to load those tags.
  3. Create a version to save a history of your changes.
  4. Publish the version so that it is actively running on your site.