WordPress · GTM container configuration
Full GTM setup for GTM4WP / EDD / WPForms / CF7: ecommerce events, forms, outbound clicks, affiliate clicks, scroll depth, file downloads.
Prerequisites#
- GA4 connected (events end up in your GA4 property)
- GTM authorized (read-only, for checks and verification)
- 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
Ecommerce plugin (WooCommerce)#
- Install and enable GTM4WP (Google Tag Manager for WordPress)
- GTM4WP settings → WooCommerce tab → enable Track e-commerce
- Enable the GA4 data-layer options if you need GA4-standard ecommerce parameters
Events GTM4WP pushes into the dataLayer (GA4-standard names):
| Event | Fires when |
|---|---|
| view_item | Product detail page view |
| add_to_cart | Added to cart |
| remove_from_cart | Removed from cart |
| view_cart | Cart viewed |
| begin_checkout | Checkout started |
| add_shipping_info | Shipping info submitted |
| add_payment_info | Payment info submitted |
| purchase | Order completed (thank-you page) |
| refund | Order refunded |
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
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.
| Variable name | Type | Configuration / Data Layer name |
|---|---|---|
| metricsKit - Outbound Domain | Custom JavaScript | Compares the clicked link host with the site host to detect outbound clicks |
| mk - Affiliate Detector | Custom JavaScript | Outputs program / affiliateId / affiliateType from your AFF patterns |
| dlv - ecommerce.value | Data Layer Variable | ecommerce.value |
| dlv - ecommerce.currency | Data Layer Variable | ecommerce.currency |
| dlv - ecommerce.transaction_id | Data Layer Variable | ecommerce.transaction_id |
| dlv - ecommerce.items | Data Layer Variable | ecommerce.items |
| Trigger name | Type | Configuration |
|---|---|---|
| metricsKit - Form Submission | Form Submission | All forms |
| metricsKit - Outbound Click | Click - Just Links | Wait for tags 2000ms (timeout 2000ms); validation wait off |
| metricsKit - Scroll Depth | Scroll Depth | Vertical thresholds 25 / 50 / 75 / 100 % |
| metricsKit - File Download | Link Click | Wait for tags 2000ms; validation wait off |
| metricsKit - Ecommerce Purchase | Custom Event | Event name purchase |
| metricsKit - Ecommerce Add To Cart | Custom Event | Event name add_to_cart |
| metricsKit - Ecommerce Begin Checkout | Custom Event | Event name begin_checkout |
| metricsKit - Ecommerce View Item | Custom Event | Event name view_item |
| metricsKit - Ecommerce Refund | Custom Event | Event name refund |
| Tag name | Event name | Event parameters | Firing trigger |
|---|---|---|---|
| metricsKit - GA4 Event - Form Submit | form_submit | formId, formClasses, formText, formUrl, formDestination | Form Submission |
| metricsKit - GA4 Event - Outbound Click | click | linkUrl, linkDomain, linkText, outbound=true | Outbound Click |
| metricsKit - GA4 Event - Scroll | scroll | percent_scrolled | Scroll Depth |
| metricsKit - GA4 Event - File Download | file_download | file_name, link_url, link_text | File Download |
| metricsKit - GA4 Event - Affiliate Click | affiliate_click | affiliate=true, affiliate_program, affiliate_id, affiliate_type, link_url, link_text | Outbound Click |
| metricsKit - GA4 Event - Ecommerce Purchase | purchase | value, currency, transaction_id, items (from the dataLayer ecommerce object) | Ecommerce Purchase |
| metricsKit - GA4 Event - Ecommerce Add To Cart | add_to_cart | value, currency, transaction_id, items | Ecommerce Add To Cart |
| metricsKit - GA4 Event - Ecommerce Begin Checkout | begin_checkout | value, currency, transaction_id, items | Ecommerce Begin Checkout |
| metricsKit - GA4 Event - Ecommerce View Item | view_item | value, currency, transaction_id, items | Ecommerce View Item |
| metricsKit - GA4 Event - Ecommerce Refund | refund | value, currency, transaction_id, items | Ecommerce Refund |
Import file structure example#
{
"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#
- If the container has no GA4 configuration tag, create one: Google Analytics (GA4) config + measurement ID G-XXXX + All Pages trigger
- Use GTM Preview on your site: submit a form, click an outbound link, browse a product — confirm tags fire with correct parameters
- Submit → Publish — nothing works until published
- Confirm event arrival in Realtime after 5-30 minutes; full reports populate in 24-48 hours
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