artfulrobot
artfulrobot

Reputation: 21397

What is gtag and why do I have to add that separately from google tag manager?

I find Google documentation around Google Tag Manager (GTM) terrible at helping me figure out which bits go where.

As I understand, GTM requires that you put a <script> snippet on your pages which is supposed to bring in other code snippets, as could be configured by a non-technical user.

I'm a technical user, though. Perhaps that's the problem! I also find it problematic that Google use the word "tag" to refer to either an HTML element tag, like <script>, or their own proprietary use of the word to mean calling a function ("triggering a tag") in another script, also unhelpfully referred to as a tag.

They also have "gtag" which is what - a helper? something that enables you to send general analytics events through the GTM API? The docs simply say:

The global site tag (gtag.js) is a JavaScript tagging framework and API that allows you to send event data to Google Analytics, Google Ads, and Google Marketing Platform.

... but we could already send analytics? What does this add?

For example, I wish to send an e-commerce Purchase event.

I've found that to do this I needed to add a new snippet of code with two <script> tags to the header on the site (thought GTM meant I didn't need to do this?) that sources gtag.js, then I'm able to call the following at the appropriate place in my javascript:

gtag('event', 'purchase', { value: 1.23, transaction_id: 'test' });

Or without it (although this does not seem to work):

ga('require', 'ec');
ga('ec:addProduct', {name: 'test product', price: 1.23})
ga('ec:setAction', 'purchase', { id: 'test_id_1', revenue: 1.23 })

So my question is: when would you use gtag() over ga(), and why can't GTM install gtag?

Upvotes: 5

Views: 4989

Answers (2)

grace
grace

Reputation: 11

Note: The built-in events don't use category, label, and value. Take care to use the correct keys when sending these events.

Upvotes: 0

Max
Max

Reputation: 13334

When would you use gtag() over ga()?

Use gtag if you want to send data to supported Google products other than Google Analytics. As you pointed out, "The global site tag (gtag.js) is a JavaScript tagging framework and API that allows you to send event data to Google Analytics, Google Ads, and Google Marketing Platform.", whereas ga only works for Google Analytics. But (see below), you might decide to never use gtag nor ga and always use GTM.

Why can't GTM install gtag?

It could (you could have a GTM tag inserting some gtag code) but it's beside the point as they are meant to be used as 2 different solutions:

  • gtag is a purely programmatic tracking tool for sending data and only works with 3 Google products (so far - Analytics, Ads, Marketing Platform - more maybe added in the future), it's made to provide basic out-of-the-box tracking with a simple copy/paste + small lines of code (if needed for customization).

  • GTM is a tag manager: it can work programmatically BUT requires a minimal configuration of the container via the GTM UI (a default container won't send data anywhere), and can send data to whatever products you want (just need to setup the corresponding tags in GTM), while having a bunch of other features

A few questions to help you choose:

  • Am I sending data to other tools than Google Analytics/Ads/Marketing platform?
  • Do I want to use some the extra features GTM offers (UI, version control, templates, debug, environments etc...)?
  • Is there some tracking that would be heavy to implement via pure custom JS (eg scroll tracking) which GTM can facilitate with its built-in listeners (eg scroll tracking)?

If YES to any of the above, then use GTM

I personally never use gtag, I always replace it with GTM because it's considerably more powerful than gtag.

What Google is doing is progressively replacing all their default snippets with gtag so they only have 1 unified API to maintain and it's an easy copy/paste for users (bear in mind most users aren't tech savy and just need to paste the snippets in into their CMS). Forcing people to use GTM would be too much of a friction as out-of-the-box GTM simply doesn't track anything and people would need to learn & configure GTM, too much work vs a simple copy/paste.

Upvotes: 3

Related Questions