I’ve spent a considerable amount of time talking and writing about how to improve the granularity of your Google Analytics data, especially when using Google Tag Manager. I’ve also gone on and on and on (and on) about customTask, which makes adding metadata to the Google Analytics hits dispatched from your website a breeze.

In this article, I’ll introduce a simple way to add yet another level of detail to your GA hits, using customTask as the method of choice. The piece of data we’ll add is the hit type of the hit (e.g. pageview, event, and timing) which, for some ludicrous reason, is not a default dimension available in Google Analytics reports.

X

The Simmer Newsletter

Subscribe to the Simmer newsletter to get the latest news and content from Simo Ahava into your email inbox!

Tip 80: Add hit type as a Custom Dimension

Adding hit type as a Custom Dimension is fairly easy, because it’s a default field available in the model object that customTask automatically receives as a parameter when executed.

So, to start with, create a new Hit-scoped Custom Dimension in your Google Analytics Property Settings. Name it Hit type. Make note of the Index number assigned to the new dimension.

Then, in Google Tag Manager, create a new Custom JavaScript variable (or edit your existing customTask variable). Add the following code within:

function() {
  var hitTypeIndex = 2;
  return function(model) {
    model.set('dimension' + hitTypeIndex, model.get('hitType'));
  };
}

Change the hitTypeIndex variable value from 2 in the example to whatever the index number of your Custom Dimension is.

Finally, add this variable to all your Google Analytics tags in More Settings / Fields To Set. It’s easiest if you just add it to your Google Analytics Settings variable (you are using one, right?). The field name should be customTask, and the value should be the Custom JavaScript variable you just created.

Now, every tag that has this field set will send its hit type automatically to Google Analytics as part of the hit payload.

You can verify this setup works by using the Google Analytics Debugger browser extension, and checking that the hit type is being sent with the correct Custom Dimension parameter (&cdX, where X is the index number).

If you can see that parameter, you’ll know everything should be working as intended.

And what can you do with this data, you ask? Well, the most useful (my opinion) application is with segments. You can create Advanced Segments such as the one in the title image of this article to find specific sequences of different hit types, such as sessions where an event preceded a pageview hit.

Or you can pull the data out using the Reporting API, and use the new Hit type Custom Dimension as an additional level of detail. This is particularly useful when combined with dimensions such as hit timestamp, session ID, and the variety of browsing behavior dimensions introduced in this article.

Let me know in the comments if you can think of other uses for this data! Always happy to delegate actual analytics work to people wiser than me.