Google Tag Manager (GTM)

Connect your GTM container (read-only) to check the configuration and generate the import file for ecommerce, form, outbound, scroll and download tracking.

The role of GTM in metricsKit#

metricsKit's ecommerce attribution / conversion tracking relies on your site's GTM container to send events (purchases, forms, outbound clicks…) into GA4. The GTM connection is used to:

  • Check whether your container has the required configuration (the "Check configuration" action)
  • Generate the import file: it contains the required triggers / tags / variables for you to import in GTM
  • Generate a GTM import file (JSON) you can also import manually
Note: GTM uses the read-only scope (tagmanager.readonly): metricsKit only reads your container for checks and verification and never modifies it; creating and publishing entities is entirely up to you in GTM.

Prerequisites#

  1. A Google account with edit access (or higher) to the target GTM container.
  2. The site already has the GTM container snippets installed, or follow the setup wizard.
  3. The container already has a GA4 Configuration tag — create one first if missing.
  4. Check the GTM service during authorization.

Binding the container#

  1. After authorization, metricsKit lists your GTM accounts and containers; a unique domain match binds automatically.
  2. You can also paste the container page URL, the full path (accounts/{id}/containers/{id}), or the public ID.
  3. Note: API paths require the numeric internal ID; the public GTM-XXXX ID alone cannot call the API.
Tip: Accounts with container-level-only permission may not see the container in the list — bind it with the full path manually.

Deployment#

metricsKit never writes to your container (GTM is granted read-only access). The flow: download the generated "Import file" (JSON) → import it in GTM → Admin → Import Container → Submit → Publish in GTM.

Note: Importing creates duplicates if run twice: import once, or choose "Overwrite" in the import dialog. Nothing takes effect until you Submit and Publish in GTM.

Container configuration items#

The complete container configuration is as follows (identical to what the metricsKit "Import file" creates): 2 custom JavaScript variables, 4 data-layer variables, 9 triggers and 10 tags. Every tag is of type "Google Analytics: GA4 Event", using the site's bound GA4 measurement ID.

Note: Prerequisite: the container must already contain a GA4 configuration tag (Google tag / GA4 Configuration with a G-XXXXXXXXXX measurement ID). metricsKit does not create it; without it no event tag will send.
Variable nameTypeConfiguration / Data Layer name
metricsKit - Outbound DomainCustom JavaScriptCompares the clicked link host with the site host to detect outbound clicks
mk - Affiliate DetectorCustom JavaScriptOutputs program / affiliateId / affiliateType from your AFF patterns
dlv - ecommerce.valueData Layer Variableecommerce.value
dlv - ecommerce.currencyData Layer Variableecommerce.currency
dlv - ecommerce.transaction_idData Layer Variableecommerce.transaction_id
dlv - ecommerce.itemsData Layer Variableecommerce.items
Trigger nameTypeConfiguration
metricsKit - Form SubmissionForm SubmissionAll forms
metricsKit - Outbound ClickClick - Just LinksWait for tags 2000ms (timeout 2000ms); validation wait off
metricsKit - Scroll DepthScroll DepthVertical thresholds 25 / 50 / 75 / 100 %
metricsKit - File DownloadLink ClickWait for tags 2000ms; validation wait off
metricsKit - Ecommerce PurchaseCustom EventEvent name purchase
metricsKit - Ecommerce Add To CartCustom EventEvent name add_to_cart
metricsKit - Ecommerce Begin CheckoutCustom EventEvent name begin_checkout
metricsKit - Ecommerce View ItemCustom EventEvent name view_item
metricsKit - Ecommerce RefundCustom EventEvent name refund
Tag nameEvent nameEvent parametersFiring trigger
metricsKit - GA4 Event - Form Submitform_submitformId, formClasses, formText, formUrl, formDestinationForm Submission
metricsKit - GA4 Event - Outbound ClickclicklinkUrl, linkDomain, linkText, outbound=trueOutbound Click
metricsKit - GA4 Event - Scrollscrollpercent_scrolledScroll Depth
metricsKit - GA4 Event - File Downloadfile_downloadfile_name, link_url, link_textFile Download
metricsKit - GA4 Event - Affiliate Clickaffiliate_clickaffiliate=true, affiliate_program, affiliate_id, affiliate_type, link_url, link_textOutbound Click
metricsKit - GA4 Event - Ecommerce Purchasepurchasevalue, currency, transaction_id, items (from the dataLayer ecommerce object)Ecommerce Purchase
metricsKit - GA4 Event - Ecommerce Add To Cartadd_to_cartvalue, currency, transaction_id, itemsEcommerce Add To Cart
metricsKit - GA4 Event - Ecommerce Begin Checkoutbegin_checkoutvalue, currency, transaction_id, itemsEcommerce Begin Checkout
metricsKit - GA4 Event - Ecommerce View Itemview_itemvalue, currency, transaction_id, itemsEcommerce View Item
metricsKit - GA4 Event - Ecommerce Refundrefundvalue, currency, transaction_id, itemsEcommerce Refund
Note: The import file carries the 2 custom JavaScript variables (Outbound Domain, Affiliate Detector); when ecommerce is selected it also contains the 4 dlv - ecommerce.* data-layer variables (ecommerce.value / ecommerce.currency / ecommerce.transaction_id / ecommerce.items). metricsKit never writes to your container — you import every entity in GTM.
Tip: Deployment: download the "Import file" (JSON) and import it via GTM → Admin → Import Container; GTM assigns entity IDs, then Submit → Publish. metricsKit never writes to your container (GTM is granted read-only access).

Platform guides#

  • WordPress (WooCommerce / EDD, WPForms, Contact Form 7…): /docs/wordpress/gtm
  • Shopify (Custom Pixel / Web Pixel support boundaries): /docs/shopify/gtm

Troubleshooting#

  • Check shows all ✗: the entities are not imported yet, or imported but not published in GTM. Follow the import flow, then re-check.
  • Empty container list: missing account-level access or a container-level grant — bind with the full path.
  • Check shows partial: some entities are missing — re-import in GTM (or add the missing ones) and publish, then re-check.