Bugs in Tracking

Czech national holiday of web analytics. Traditionally held on the first Saturday in September. Yes, MeasureCamp.

I gave a lecture on measurement errors and their monitoring. I promised the participants that I would publish the slides.

However, the slides were only a supplement to the presentation. Practical examples can be found in the GTM export.
For analysts, JSON with Export from GTM is more readable than PowerPoint slides, right?

How to track measurement errors

Lectures at MeasureCamp are not recorded. So I am adding at least a few recommendations from the lecture. If you are interested in a topic but it is not explained sufficiently, write to me on LinkedIn. I will add it to the blog’s publication plan.

So what should you do?

1. Ask the developers

Most of them have tools such as Sentry or other tools for automatically collecting errors from the web. Filtering the records that interest you is a great first step.

2. Error Listener

In GTM, you can set up a listener for JavaScript errors. Simo’s article can help you get started.

3. Custom Scripty

If you use “Custom HTML” tags, they should use the following structure. This will help you monitor errors in the tags.

<script>
(function() {
  try {
    
    // your code is here


    {{GTM}}.onHtmlSuccess();
  } catch (e) {
    {{Util - Log Error}}("JS Error in tag TAG_NAME", e);
    {{GTM}}.onHtmlFailure();    
  }
})();
</script>

You need to have custom JavaScript variables created.

  • {{GTM}} – returns window.google_tag_manager[{{Container ID}}]
  • {{Util - Log Error}} – returns a function that pushes data into the dataLayer

4. Use the Tag Monitor

You can only use try-catch in “Custom HTML”. If you want to monitor tags from templates as well, you need to use addEventCallback. And if you don’t want to write your own template, you can use Simo’s Tag Manager Monitor, for example.

With the help of callback, you can monitor not only the completion status, but also the processing speed of individual tags. For example, if tag processing takes longer than 500 ms, you may receive a notification.

If you use Tag Monitor, only the numeric tag ID is available in the callback. I therefore recommend always enabling the transfer of the tag name to the callback for each tag – you can do this as follows:

Yes, that’s the part of GTM that no one has ever seen before.

5. Write tests for templates

Do you write your own templates? Write tests for them too. Every test written today will save you a lot of headaches in the future.

Without it, it’s clear that you’re not serious about the template.

Personally, I use test-driven development for all Sklik template modifications. It works and saves a lot of time.

6. Check the totals

Define the totals with the client that must match. For example:

  • Order value = product value – discounts – voucher
  • Total value = order value + shipping cost + payment cost + tax

You can then check these totals in GTM.

For speed reasons, I would not check every event. Only the key ones, such as orders..

7. Set up alerts

In order to fix the error as soon as possible, you need to know about it as soon as possible. Don’t wait for the client to write to you. Set up mechanisms that will check the data automatically. You can:

  • Set up Insights in GA4
  • Use Assertions in DataForm in BigQuery
  • Use some custom tests

Personally, I use my own tool that performs over 100 checks on my projects based on all the problems I have encountered in my career.

I am considering turning it into a service. If you are interested, take a look at the website and you can leave me an email.