DEV Community

Aleksey Razbakov
Aleksey Razbakov

Posted on

2 3

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.

Image of Timescale

🚀 pgai Vectorizer: SQLAlchemy and LiteLLM Make Vector Search Simple

We built pgai Vectorizer to simplify embedding management for AI applications—without needing a separate database or complex infrastructure. Since launch, developers have created over 3,000 vectorizers on Timescale Cloud, with many more self-hosted.

Read full post →

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

đź‘‹ Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay