WordPress · GTM container configuration

Full GTM setup for GTM4WP / EDD / WPForms / CF7: ecommerce events, forms, outbound clicks, affiliate clicks, scroll depth, file downloads.

Prerequisites#

  1. GA4 connected (events end up in your GA4 property)
  2. GTM authorized (read-only, for checks and verification)
  3. The GTM container snippets installed on the site

Install the container code (pick one):

  • GTM4WP plugin (recommended): install Google Tag Manager for WordPress, enter the container ID — snippets and dataLayer handled automatically
  • Insert Headers and Footers style plugin: first snippet in Header, second in Body
  • Theme header.php: first snippet inside head, second right after body
Note: The container code must be shared site-wide (head/body); installing it on individual pages only tracks those pages.

Ecommerce plugin (WooCommerce)#

  1. Install and enable GTM4WP (Google Tag Manager for WordPress)
  2. GTM4WP settings → WooCommerce tab → enable Track e-commerce
  3. Enable the GA4 data-layer options if you need GA4-standard ecommerce parameters

Events GTM4WP pushes into the dataLayer (GA4-standard names):

EventFires when
view_itemProduct detail page view
add_to_cartAdded to cart
remove_from_cartRemoved from cart
view_cartCart viewed
begin_checkoutCheckout started
add_shipping_infoShipping info submitted
add_payment_infoPayment info submitted
purchaseOrder completed (thank-you page)
refundOrder refunded
Note: On Cart / Checkout Block themes keep GTM4WP 2.0+; older versions may lose add_to_cart / begin_checkout.

EDD (Easy Digital Downloads)#

GTM4WP 2.x no longer bundles an EDD data layer. Two options:

  • Option A (recommended): in functions.php or a custom plugin, push a purchase event with ecommerce parameters on EDD hooks such as edd_complete_purchase
  • Option B: use a third-party GTM data-layer plugin that supports EDD

Once pushed, the GTM-side configuration is identical to WooCommerce.

Form plugins (WPForms / Contact Form 7)#

Form submission is captured via GTM's Form Submission trigger listening to the native DOM submit event — no plugin changes needed:

  • WPForms: create and embed the form; AJAX submits also dispatch the native submit event
  • Contact Form 7: create the form and embed the shortcode; submits are captured the same way
Note: Fully custom JS submissions (no form submit event, e.g. plain fetch) cannot be captured — push dataLayer.push({ event: "form_submit" }) in the success callback and switch to a Custom Event trigger.

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).

Import file structure example#

Note: The above is a structural example (other entities omitted): the real import file contains all 9 triggers / 10 tags / 6 variables, and its measurement ID (measurementIdOverride), account/container path, site name and the mk - Affiliate Detector script are generated per site from your domain and AFF patterns. Do not copy the sample values — download your own file from Console → Conversions → Download import file.
{
  "containerVersion": {
    "path": "accounts/0000000/containers/0000000/versions/0",
    "name": "metricsKit Tracking (example.com)",
    "trigger": [
      { "triggerId": "100", "name": "metricsKit - Form Submission",
        "type": "FORM_SUBMISSION", "fingerprint": "" },
      { "triggerId": "101", "name": "metricsKit - Outbound Click",
        "type": "LINK_CLICK", "fingerprint": "",
        "waitForTags": { "type": "TEMPLATE", "value": "2000" },
        "waitForTagsTimeout": { "type": "TEMPLATE", "value": "2000" },
        "checkValidation": { "type": "BOOLEAN", "value": "false" } },
      { "triggerId": "104", "name": "metricsKit - Ecommerce Purchase",
        "type": "CUSTOM_EVENT", "fingerprint": "",
        "customEventFilter": [{ "type": "EQUALS", "parameter": [
          { "type": "TEMPLATE", "key": "arg0", "value": "{{_event}}" },
          { "type": "TEMPLATE", "key": "arg1", "value": "purchase" } ] }] }
    ],
    "variable": [
      { "name": "mk - Affiliate Detector", "type": "jsm", "fingerprint": "",
        "parameter": [{ "type": "TEMPLATE", "key": "javascript",
          "value": "function(){ /* generated from your AFF patterns, per-site */ }" }] },
      { "name": "dlv - ecommerce.value", "type": "v", "fingerprint": "",
        "parameter": [{ "type": "TEMPLATE", "key": "name", "value": "ecommerce.value" }] }
    ],
    "tag": [
      { "tagId": "200", "name": "metricsKit - GA4 Event - Ecommerce Purchase",
        "type": "gaawe", "fingerprint": "",
        "parameter": [
          { "type": "TEMPLATE", "key": "measurementIdOverride", "value": "G-XXXXXXXXXX" },
          { "type": "TEMPLATE", "key": "eventName", "value": "purchase" },
          { "type": "TEMPLATE", "key": "value", "value": "{{dlv - ecommerce.value}}" },
          { "type": "TEMPLATE", "key": "items", "value": "{{dlv - ecommerce.items}}" } ],
        "firingTriggerId": ["104"] }
    ]
  }
}

GA4 configuration tag & verification#

  1. If the container has no GA4 configuration tag, create one: Google Analytics (GA4) config + measurement ID G-XXXX + All Pages trigger
  2. Use GTM Preview on your site: submit a form, click an outbound link, browse a product — confirm tags fire with correct parameters
  3. Submit → Publish — nothing works until published
  4. Confirm event arrival in Realtime after 5-30 minutes; full reports populate in 24-48 hours
Tip: After publishing, run "Check configuration" in the console conversions page to auto-compare the container entities as a final check.

References#

  • GTM4WP WooCommerce settings reference: gtm4wp.com/google-tag-manager-for-woocommerce/woocommerce-settings-reference
  • WooCommerce official data layer: woocommerce.com/document/datalayer-for-woocommerce
  • Google Tag Manager Help: support.google.com/tagmanager