GTAG GET API - Custom Tag Template

The GTAG GET API custom tag template is a tag template for Google Tag Manager’s community template gallery.

Blog post
Vendor documentation
Gallery entry
GitHub repo


This tag writes the values for the selected default fields (Client ID, Session ID, GCLID) as well as any custom fields set with the Google Analytics 4 template into dataLayer.

It utilizes the asynchronous .get() API of Google Site Tag.

See the official documentation for a summary of the API.


Create a tag with the GTAG GET API template, and choose all the fields you want it to write into dataLayer.

Then, and this is important, you have to set the tag in a tag sequence to fire after (as a Cleanup Tag) the Google Analytics 4: Configuration tag (or an Event tag if you don’t use a Configuration tag).

This tag must fire after a Google Analytics 4 tag has completely fired, or else the gtag() GET API will not do anything.

When the tag fires, it launches a number of calls to gtag() GET API - one for each field it has to resolve. Once all the fields have been resolved, a dataLayer.push() is done with the following contents:

  "event": "gtagApiGet",
  "gtagApiResult": {
    "client_id": "123123123.123123123",
    "session_id": "1608578585",

After this, you can create a Custom Event trigger for the gtagApiGet event and Data Layer variables for the individual field values in the gtagApiResult object.

Release notes

Date Changeset
21 December 2020 Remove console logging.
21 December 2020 Initial release.