2

I have Google Tag Manager installed and working on my website. There is one particular thing that I need to track but I can't figure out how to do it.

There is a block that gets inserted into a page on my site when an error has occurred. I want to track how many times this error has been encountered so need to fire a trigger when that div id or class is viewed. The URL doesn't change, so I can't use that.

I presume I need to setup a Page View and then trigger on an event, I just can't figure out how to setup the event.

2

There are three steps to the way I would do this.

  • Add code to the error reporting block that pushes an event to the Data Layer.
  • Create a Google Tag Manager Custom Trigger that fires when this custom event takes place.
  • Create and Event Tag, and attach the trigger.

The code you need to add will push an event to the data layer. This is just custom array of pairs, where the first is called 'event'. The other values (if any) are for you to define as you choose. Here is an example, with two custom variables:

dataLayer.push({'event': 'event_name','error_code': '7842F','var1': '82hf'})

This is a bare-bones example where we aren't trying to include extra information:

dataLayer.push({'event': 'error_event'})

If you test this is the Google Tag Manager preview mode, you will see this event take place. The custom trigger then needs to be set up to take place when the event named above is recorded.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.