Google Tag Manager Organization Tips

Reading time: 4 mins

Everybody loves data. Analyzing data allows you to understand what’s going around with your application/business, it being performance (Skylight, NewRelic), user experience (Hotjar) or marketing purposes (Google Analytics, Google Tag Manager).

TL;DR here’s a quick link to the organization tips, so you can jump the introduction :)

As developers know, marketing teams usually make an insane number of requests to add several tracking pixels on applications. I once worked in a company which had more than 60 tracking pixels being reported by my ad-blocker, and all of these tracking pixels were hardcoded on several templates. This inherited codebase was a classic case of “big ball of mud”.

At the time, I decided to negotiate with the marketing team how we were going to avoid opening so many tickets related to marketing needs. It was time to extract the chaos to a separate application where they could control all their experiments without going through our (long) deployment cycle. I’ve decided to introduce Google Tag Manager (GTM).

Extracting tracking pixels to GTM was a wonderful move. Implementing a rich dataLayer allowed us to remove all hardcoded pixels, upgrade Google Analytics to universal analytics and remove unused trackers.

If you don’t know what the dataLayer is, check out Google’s official tutorial and Simo Ahava’s post about it. If you have further questions around GTM, check Simo’s posts. He’s an expert on the analytics field and writes technical and non-technical posts about Google Analytics and GTM.

Since I’ve helped the marketing team with the migration, I also participated on GTM organization and coding, where custom tags, event triggering and dataLayer integration was needed. Here’s the list of some tips gathered while implementing the GTM on the “big app”:

Tips

Write defensive code on GTM

Write vanilla ES5 JS

Don’t add events on all pages

Create folders to organize tags and triggers

Create a naming convention for triggers

Create a naming convention for tags

Do not enable all variables on GTM, unless you’re going to use it

Separate staging from production

Indent your code (please!)

Bonus: debugging