DEV Community

Aleksey Razbakov
Aleksey Razbakov

Posted on

GTM vs gtag

What's the benefit of using Google Tag Manager (GTM) instead of gtag?

As a Developer you have full control of what data will be sent to GoogleAnalytics (GA) with gtag and you don't need to configure it twice (gtag in code + GTM tag with trigger and variable).

I see so far few possible benefits:

  • It tracks generic events like page_view on history_change, scroll, video_play, etc.
  • Add HTML snippets for FacebookPixel or some ChatWidgets with some conditions (specific page, event) but isn't it more reliable and under control with source code?
  • Configure event mapping for FacebookPixel, etc.?
  • If you configure GTM trigger as click on button and send event without a need to add an event in code but it's unreliable solution, because once code is changed it will be difficult to figure out what's broken
  • If you push in dataLayer context, so instead of sending
gtag({ event: "search", search_term: "keyword" })
Enter fullscreen mode Exit fullscreen mode

you send

gtag({ action: "search", search_term: "keyword" })
gtag({ event: "submit" })
Enter fullscreen mode Exit fullscreen mode

but then you can figure out in GTM which variables to use, but this will require to do a lot of conditions in GTM to define different logic for each event

There is no simple way just to forward all events from GTM to GA, if you forward all events it will also forward all gtm events like: gtm.start, gtm.history, etc. So the workaround is to use:

{ event: "interaction", action: "search" }
Enter fullscreen mode Exit fullscreen mode

But also in this case you will need extra conditions if you want to send different context for different events.

I like GTM. I like how it works and how it looks. I just don't understand benefit of using it, while you can do things faster and better with gtag.

Top comments (0)