=== All-in-one CAPI for Meta & Pinterest + GTM === Contributors: suhanduman Tags: capi, conversion api, meta pixel, pinterest, GTM Requires at least: 6.0 Tested up to: 6.9 Stable tag: 3.5.2 Requires PHP: 7.4 WC requires at least: 8.0 WC tested up to: 10.7 License: GPLv2 or later License URI: https://www.gnu.org/licenses/gpl-2.0.html Free server-side CAPI for Meta & Pinterest + GTM dataLayer. Cache-safe, theme-agnostic, no cloud server needed. == Description == Server-side tracking for your WooCommerce store — without a GTM Server Container, without a premium plugin, without a monthly bill. This plugin sends Meta (Facebook) and Pinterest Conversions API events from your WordPress server, and sets up a clean GTM dataLayer so your browser-side tags (Pixel, GA4, Pinterest Tag) work alongside it. Same event ID on both sides, so Meta merges them into one event instead of double-counting. **What it does:** * **Meta & Pinterest CAPI** — PageView, ViewContent, AddToCart, InitiateCheckout, Purchase, Search, AddToWishlist, Lead, and the full checkout funnel (AddShippingInfo, AddPaymentInfo). Sent server-side with hashed user data for high Event Match Quality. * **GTM dataLayer** — Automatic script injection and a standards-compliant dataLayer for GA4, Meta Pixel, Pinterest Tag, or anything else you run through GTM. * **Full WooCommerce coverage** — 14 event types, classic checkout and block checkout, HPOS compatible. * **Cache-safe** — Works with LiteSpeed Cache, WP Rocket, Varnish, and Cloudflare full-page cache. Events carry a unique random ID per visit so Meta never deduplicates cached traffic into one event. * **Batch delivery** — Events are queued and sent in bulk every 60 seconds. No synchronous HTTP on user requests, no latency added to page loads. * **Built-in debug log** — See exactly which events were sent, to which platform, and whether the API accepted them. Filterable by event type, with success/failure stats. * **REST + AJAX fallback** — Browser events go to a REST endpoint (no nonce, cache-proof) and fall back to admin-ajax.php if REST is blocked by a firewall. **What you don't need:** * No GTM Server Container (saves $30-150/month in cloud fees) * No premium tier — every feature is in the free plugin * No external tracking SaaS subscription **Please check the installation page for the recommended GTM settings for deduplication.** == Stop Losing 30% of Your Data to Cookie Banners == When a visitor clicks "Deny" on your cookie banner, most tracking plugins simply shut down. You lose the conversion data, your ads fly blind, and your ROAS artificially drops. Other "aggressive" plugins ignore the banner and send personal data (PII) to Meta anyway, risking massive GDPR fines. **We do something smarter.** When combined with Google Consent Mode v2, this plugin uses an advanced technique called **Server-Side Consent Gating with Event ID Deduplication**: * **The Cookieless Ping** — When consent is denied, the browser sends a tiny, anonymous ping to Meta and Google (no cookies, no personal identity). * **The Safe Server Event** — Our CAPI integration fires from your server, strictly stripping out all personal data (email, phone, name) to protect user privacy, but securely transmitting the essential order data (cart value, products, currency). * **The Magic (Event ID)** — We attach the exact same `event_id` to both. Meta's machine learning connects the anonymous browser ping with your server's exact order value. **The result.** Meta and Google's modeling algorithms can now accurately model your "lost" conversions. You recover up to 50% of your missing ROAS data, feed your ad optimization with real purchase values, and remain 100% GDPR compliant. Most other free plugins fall into one of two camps: the **"timid" approach** (shuts CAPI off entirely when consent is denied — your ads go blind), or the **"reckless" approach** (sends hashed PII to Meta regardless of consent — direct GDPR violation). This plugin is the only free option we know of that does the harder, correct thing: keep the signal flowing without sending the data the visitor refused. Enable it from **Settings → Privacy & Consent (Server-side) → Strict server-side consent mode**. == Our Philosophy == This plugin is free. Not "free with limits" — just free. Every feature works, no pro version behind a paywall. I built it because setting up server-side tracking shouldn't require a cloud engineering degree or a monthly bill. If it helps your store, that's good enough. == Frequently Asked Questions == = Does this plugin replace the Meta Pixel? = No, it works alongside it. The plugin sends server-side (CAPI) events, while GTM handles the browser-side Pixel. Both use the same `event_id`, so Meta merges them automatically without counting anything twice. = What is the difference between this and a GTM Server Container? = A GTM Server Container runs on Google Cloud and costs money every month. This plugin does the same job directly from your WordPress server — no extra infrastructure, no extra bill. = Does it work with page caching plugins (WP Rocket, LiteSpeed, etc.)? = Yes. PageView and ViewCategory events fire from JavaScript, so they work even on fully cached pages. Cart, checkout, and purchase pages are not cached by default. = What plugins are required? = WooCommerce. That's it. If you use other GTM plugins (like Google Site Kit), disable their e-commerce features to avoid conflicts. = Is there a pro version? = No. Everything is included. = My events aren't showing in Meta Events Manager. What's wrong? = Check these in order: 1. Open your **Event Log** tab in the plugin settings. If events appear there with "Success (Meta)", the plugin is sending them. If Meta isn't receiving them, the problem is on Meta's end — usually Pixel ID or Access Token mismatch. 2. If the log is empty after visiting your store, you likely have a JS optimizer (LiteSpeed / WP Rocket / Autoptimize) deferring the plugin's tracking scripts. See next answer. 3. Check the admin notice on the plugin settings page — the plugin auto-detects your cache setup and shows exclude-list instructions. = I use LiteSpeed Cache. How do I configure it? = Go to **LiteSpeed Cache → Page Optimization → JS Settings → JS Defer Excludes** and add these script IDs (one per line): `mcapi-pageview-init` `mcapi-viewcontent-events` `mcapi-viewcategory-events` `mcapi-frontend-events` Then purge all cache. = I use WP Rocket. How do I configure it? = Go to **WP Rocket → File Optimization → JavaScript → Excluded JavaScript Files** and add the same script IDs listed above for LiteSpeed. Then clear WP Rocket cache. = I use Autoptimize. How do I configure it? = Go to **Autoptimize → JS, CSS & HTML → Exclude scripts from Autoptimize** and add the same script IDs. = What about Cloudflare Rocket Loader? = The plugin adds `data-cfasync="false"` to its inline scripts, which Cloudflare Rocket Loader respects. No configuration needed. = Does it work with a block-based theme (e.g. Twenty Twenty-Five)? = Yes. The plugin's tracking works with the WooCommerce Products block used by FSE themes. = GA4 / Meta browser tags fire successfully in GTM Preview but the plugin's Event Log is empty. What's wrong? = GTM tags firing means your dataLayer pushes work — but your CMP's auto-blocker may be stopping the plugin's inline scripts from running, so no event ever reaches the server. Open browser DevTools → Elements, search for `mcapi-pageview-init`, and check the script tag's `type` attribute. If it reads `type="text/plain"` (or anything other than `text/javascript` / no type), your CMP has blocked it. v3.5.0+ adds CMP exemption attributes (`data-cookieconsent="ignore"`, `data-cookieyes="cookieyes-necessary"`, `data-cmplz-no-cookielaw="1"`) automatically, so updating to the latest version usually resolves this. For less common CMPs use the `mcapi_inline_script_attrs` filter — see the **CMP Auto-Blocking and the Plugin's Inline Scripts** section in the **Advanced Configuration** tab. = GTM container template import fails with "Error deserializing enum type [EventType]. Unrecognized value [customEvent]". = This was a schema-mismatch bug in v3.4.x and earlier — the trigger types were emitted in the Tag Manager API format (camelCase) instead of the container-import format (UPPER_SNAKE_CASE). Fixed in v3.5.0. Update the plugin, re-download the template from the settings page, and re-import. Existing manual GTM setups continue to work; only the JSON file import needed correction. = I sell subscriptions and Meta is over-attributing revenue to old ad campaigns. = WooCommerce Subscriptions auto-renewals are sent to Meta CAPI as fresh `Purchase` events by default, so Meta credits the original ad with the renewal value. v3.5.0+ adds a "WooCommerce Subscriptions Integration" section to the plugin settings with four behavior modes — most subscription stores pick "Skip" or "Subscribe / SubscriptionRenewal events" to keep their `Purchase` metric clean. See the **WooCommerce Subscriptions Integration** section in the **Advanced Configuration** tab for the full breakdown. = I serve EU traffic — does the plugin respect cookie-banner consent for server-side CAPI? = By default, no — the server-side CAPI calls fire from PHP and never see your CMP's browser-side `gtag('consent', ...)` signals. v3.5.0 adds an opt-in "Strict server-side consent mode" toggle in the plugin's **Privacy & Consent (Server-side)** settings section. When enabled, the plugin reads your CMP's cookie (Cookiebot, CookieYes, Complianz auto-detected; others via the `mcapi_marketing_consent_granted` filter) and, if the visitor explicitly denied marketing consent, strips the hashed PII (email, phone, name, billing address, fbp/fbc) from the CAPI payload. The event still ships with `event_id` and non-PII context so Meta's browser↔CAPI dedup and conversion modeling keep working — the data simply no longer carries personally identifying fields. Default OFF preserves backward compatibility; recommended ON for EU stores. See the **Strict server-side consent mode** section in the **Advanced Configuration** tab for the full mechanism. == External Services == This plugin connects your website to external services to send event data. * **Service Used:** Meta Conversion API * **Purpose:** To send user interaction and e-commerce event data from your server to Meta's servers for ad performance measurement, optimization, and audience building. * **Data Sent:** Event details (product ID, price) and user parameters (IP address, user agent, hashed email/name/phone, Facebook cookies) are sent when a user performs a key action. * **Service Used:** Pinterest Conversions API * **Purpose:** Same as the Meta CAPI, providing reliable tracking for ad performance and audience building on Pinterest. * **Data Sent:** Event details and hashed user parameters are sent upon user action. * **Service Used:** Google Tag Manager * **Purpose:** To load a JavaScript container from Google's servers that allows you to manage and deploy marketing and analytics tags. * **Data Sent:** The plugin provides your GTM Container ID to Google to fetch the correct script. GTM itself may collect data based on how you configure your tags. == Installation == 1. Upload the plugin folder to the `/wp-content/plugins/` directory and activate it. 2. Navigate to the **Meta CAPI & GTM** page from your main WordPress menu. 3. Enter your **GTM Container ID** to inject the GTM script on your site. 4. Enter your **Meta Pixel ID** and **API Access Token** for the server-side connection. Do the same for Pinterest if applicable. 5. Go to the "Event Management" tab to select which CAPI events you want to track. 6. Configure your GTM container using the instructions in the "Recommended GTM Setup" section below. --- ### Recommended GTM Setup **Crucial First Steps:** To prevent duplicate events and ensure data accuracy, you must configure two settings in your Meta account and GTM container. 1. **Turn Off Meta's Automatic Event Tracking:** * In your Meta Business Suite, navigate to **Events Manager** and select your Pixel. * Go to the **Settings** tab. * Scroll to the **Event Setup** section and turn **Off** the toggle for **Track Events Automatically Without Code**. This plugin will handle all event sending. 2. **Pause Automatically Created GTM Tags:** * In your GTM container, please pause or delete any automatically created tags that start with `FB_`. Since we will be creating our own tags manually, only they should be active. --- ### TEMPLATE SETUP To save time and prevent errors, we have created a GTM container template. You can import this file to automatically create all the necessary variables, triggers, and tags. **Step 1: Download the Template** Go to the "Meta CAPI & GTM" settings page in your WordPress admin panel. In the Main Settings tab, you will see a highlighted box with a link to download the `gtm-template.json` template file. Download this file to your computer. **Step 2: Import the Template into GTM** 1. Go to your Google Tag Manager container. 2. Navigate to the **Admin** section. 3. Click on **Import Container**. 4. Click **Choose container file** and select the `gtm-template.json` file you downloaded. 5. Choose a **New** workspace and give it a descriptive name (e.g., "CAPI Import"). 6. **IMPORTANT:** Choose the **Merge** import option. Do NOT choose "Overwrite", as this could delete your existing tags. 7. The preview screen will show you all the new tags, triggers, and variables that will be added. Click **Confirm**. **Step 3: Configure Your IDs** After the import is complete, update the two placeholder constants with your own tracking IDs. Both Meta and GA4 tags read from these variables, so you only edit them once. 1. Go to the **Variables** section. 2. Find and click on the **"CONST - Meta Pixel ID"** variable. * Replace `META_PIXEL_ID` with your actual Meta Pixel ID. Save. All seven Meta tags now use this value. 3. Find and click on the **"CONST - GA4 Measurement ID"** variable. * Replace `GA4_MEASUREMENT_ID` with your actual GA4 Measurement ID (e.g., `G-XXXXXXXXXX`). Save. The Google Tag (Configuration) and all ten GA4 Event tags now use this value via `measurementIdOverride`. > **Note on Pinterest:** This template ships with GA4 and Meta tags only. The Pinterest Tag is a Community Template (not a GTM built-in), and embedding it inside a container export can fail import on some GTM workspaces with permission or template-version errors. If you use Pinterest CAPI, follow the **MANUAL SETUP → Step 3: B) Pinterest Tags** section below to add the Pinterest tags yourself — it takes a couple of minutes and avoids the import edge cases. **Step 4: Publish** Once you have updated your IDs, click the **Submit** button in the top right corner, then **Publish** your container. Your GTM setup is now complete! If you prefer to configure Google Tag Manager manually, or if you encounter any issues with the template import, the following guide provides step-by-step instructions to get everything configured. For Consent Mode v2 setup, the strict server-side consent mode toggle, CMP auto-block compatibility, and the WooCommerce Subscriptions integration, see the **Advanced Configuration** tab. ### MANUAL SETUP ### Step 1: Create GTM Variables Create the following **Data Layer Variables** (Variable Type: Data Layer Variable): * **Variable Name:** `DLV - event_id` * **Data Layer Variable Name:** `event_id` * **Variable Name:** `DLV - ecommerce` * **Data Layer Variable Name:** `ecommerce` * **Variable Name:** `DLV - Hashed Email` * **Data Layer Variable Name:** `user_data.email` * **Variable Name:** `DLV - ecommerce.currency` * **Data Layer Variable Name:** `ecommerce.currency` * **Variable Name:** `DLV - ecommerce.value` * **Data Layer Variable Name:** `ecommerce.value` * **Variable Name:** `DLV - ecommerce.items` * **Data Layer Variable Name:** `ecommerce.items` * **Variable Name:** `DLV - ecommerce.transaction_id` * **Data Layer Variable Name:** `ecommerce.transaction_id` * **Variable Name:** `DLV - ecommerce.item_list_name` * **Data Layer Variable Name:** `ecommerce.item_list_name` * **Variable Name:** `DLV - ecommerce.shipping_method` * **Data Layer Variable Name:** `ecommerce.shipping_method` * **Variable Name:** `DLV - ecommerce.payment_method` * **Data Layer Variable Name:** `ecommerce.payment_method` Then create the following **Constant Variables** (Variable Type: Constant). One placeholder per platform — every Meta tag and every GA4 tag references these, so when you rotate IDs you only edit them once. * **Variable Name:** `CONST - Meta Pixel ID` * **Value:** Your Meta Pixel ID (e.g. `1234567890123456`) * **Variable Name:** `CONST - GA4 Measurement ID` * **Value:** Your GA4 Measurement ID (e.g. `G-XXXXXXXXXX`) Finally, create one **Custom JavaScript Variable** for Pinterest CAPI (only needed if you actually use Pinterest — the new Meta Pixel template auto-converts the GA4 ecommerce schema for you, so a Meta-side CJS variable is no longer required). * **Variable Name:** `CJS - Pinterest Contents` * **Custom JavaScript:** `function() {` ` var ecommerce = {{DLV - ecommerce}};` ` if (!ecommerce || !ecommerce.items) return undefined;` ` return ecommerce.items.map(function(item) {` ` return {` ` id: item.id || item.item_id,` ` quantity: item.quantity || 1,` ` item_price: item.price` ` };` ` });` `}` ### Step 2: Create GTM Triggers Create the following triggers using the **Custom Event** type. * **Trigger Name:** `CE - PageView Meta` * **Event name:** `page_view_meta` * **Trigger Name:** `CE - View Item` * **Event name:** `view_item` * **Trigger Name:** `CE - Add to Cart` * **Event name:** `add_to_cart` * **Trigger Name:** `CE - Begin Checkout` * **Event name:** `begin_checkout` * **Trigger Name:** `CE - Purchase` * **Event name:** `purchase` * **Trigger Name:** `CE - View Item List` * **Event name:** `view_item_list` * **Trigger Name:** `CE - View Cart` * **Event name:** `view_cart` * **Trigger Name:** `CE - Select Item` * **Event name:** `select_item` * **Trigger Name:** `CE - Add Shipping Info` * **Event name:** `add_shipping_info` * **Trigger Name:** `CE - Add Payment Info` * **Event name:** `add_payment_info` ### Step 3: Create GTM Tags #### A) Meta Tags (Meta Pixel) **Prerequisite:** Install the **"Meta Pixel"** template by `facebook` from the GTM Community Template Gallery (the older "Facebook Pixel" template under `facebookarchive` is deprecated and will not import). Then create one tag per event below. For every Meta tag, set these common fields the same way (using the variables from Step 1): * **Pixel ID:** `{{CONST - Meta Pixel ID}}` * **Event ID:** `{{DLV - event_id}}` — required for browser↔CAPI deduplication * **Use GA4 Ecommerce data:** **enabled** (Meta's template auto-converts the plugin's `ecommerce.items[]` into Meta's `contents[]` shape — no Custom JavaScript variable needed any more) * **Consent:** **enabled** — respects Consent Mode v2 categories the visitor approved * **Send page view:** leave default (the template handles it via `eventName`) Then per tag, only the **Event Name** and **Trigger** change: * **Meta - PageView** → Event Name: standard `PageView`, Trigger: `CE - PageView Meta` * **Meta - ViewContent** → Event Name: standard `ViewContent`, Trigger: `CE - View Item` * **Meta - AddToCart** → Event Name: standard `AddToCart`, Trigger: `CE - Add to Cart` * **Meta - InitiateCheckout** → Event Name: standard `InitiateCheckout`, Trigger: `CE - Begin Checkout` * **Meta - Purchase** → Event Name: standard `Purchase`, Trigger: `CE - Purchase` * **Meta - AddPaymentInfo** → Event Name: standard `AddPaymentInfo`, Trigger: `CE - Add Payment Info` * **Meta - ViewCategory** → Event Name: **custom**, Custom Event Name: `ViewCategory`, Trigger: `CE - View Item List` (Meta does not have a standard ViewCategory event, so this fires as a custom event in Events Manager) #### B) Pinterest Tags **Prerequisite:** Install the **"Pinterest Tag"** template from the GTM Community Template Gallery. The Data Layer Variables and the `CJS - Pinterest Contents` Custom JavaScript Variable from Step 1 are reused here. For each tag below, the standard Custom Parameter set is the same: `event_id` → `{{DLV - event_id}}`, `value` → `{{DLV - ecommerce.value}}`, `currency` → `{{DLV - ecommerce.currency}}`, `contents` → `{{CJS - Pinterest Contents}}`, `content_ids` → `{{CJS - Pinterest Contents}}` (Pinterest extracts the ids from the array). Create the following tags: * **Tag: Pinterest - PageView** * **Tag ID:** Your Pinterest Tag ID * **Hashed Email:** `{{DLV - Hashed Email}}` * **Event to Fire:** `page_visit` * **Custom Parameters:** Name `event_id`, Value `{{DLV - event_id}}` * **Trigger:** `CE - PageView Meta` * **Tag: Pinterest - ViewContent** * **Tag ID:** Your Pinterest Tag ID * **Hashed Email:** `{{DLV - Hashed Email}}` * **Event to Fire:** `view_content` * **Custom Parameters:** Add `event_id`, `value`, `currency`, `contents`, and `content_ids` per the standard set above. * **Trigger:** `CE - View Item` * **Tag: Pinterest - AddToCart** * **Tag ID:** Your Pinterest Tag ID * **Hashed Email:** `{{DLV - Hashed Email}}` * **Event to Fire:** `add_to_cart` * **Custom Parameters:** Add `event_id`, `value`, `currency`, `contents`, and `content_ids` per the standard set above. * **Trigger:** `CE - Add to Cart` * **Tag: Pinterest - InitiateCheckout** * **Tag ID:** Your Pinterest Tag ID * **Hashed Email:** `{{DLV - Hashed Email}}` * **Event to Fire:** `initiate_checkout` * **Custom Parameters:** Add `event_id`, `value`, `currency`, `contents`, and `content_ids` per the standard set above. * **Trigger:** `CE - Begin Checkout` * **Tag: Pinterest - Purchase** * **Tag ID:** Your Pinterest Tag ID * **Hashed Email:** `{{DLV - Hashed Email}}` * **Event to Fire:** `checkout` * **Custom Parameters:** Add `event_id`, `value`, `currency`, `contents`, and `content_ids` per the standard set above. * **Trigger:** `CE - Purchase` * **Tag: Pinterest - ViewCategory** * **Tag ID:** Your Pinterest Tag ID * **Hashed Email:** `{{DLV - Hashed Email}}` * **Event to Fire:** `view_category` * **Custom Parameters:** * Name `event_id`, Value `{{DLV - event_id}}` * Name `content_name`, Value `{{DLV - ecommerce.item_list_name}}` * **Trigger:** `CE - View Item List` #### C) Google Analytics 4 Tags **Prerequisite:** Make sure you have your **Measurement ID** (starts with `G-`) from your Google Analytics 4 property. The Data Layer Variables required here were already created in Step 1. First, create the main configuration tag that loads GA4 on all pages. * **Tag: GA4 - Google Tag (Configuration)** * **Tag Type:** Google Analytics > Google Tag * **Tag ID:** Your GA4 Measurement ID (e.g., `G-XXXXXXXXXX`) * **Important:** Uncheck the "Send a page view event when this configuration loads" box. We will send it manually with the next tag. * **Trigger:** `All Pages` Next, create the event tags that will send data from the `dataLayer` to Google Analytics. * **Tag: GA4 - Event - PageView** * **Tag Type:** Google Analytics > GA4 Event * **Configuration Tag:** Select your `GA4 - Google Tag (Configuration)` tag. * **Event Name:** `page_view` * **Trigger:** `CE - PageView Meta` * **Tag: GA4 - Event - ViewItem** * **Tag Type:** Google Analytics > GA4 Event * **Configuration Tag:** Select your `GA4 - Google Tag (Configuration)` tag. * **Event Name:** `view_item` * **Event Parameters:** * Parameter Name: `currency`, Value: `{{DLV - ecommerce.currency}}` * Parameter Name: `value`, Value: `{{DLV - ecommerce.value}}` * Parameter Name: `items`, Value: `{{DLV - ecommerce.items}}` * **Trigger:** `CE - View Item` * **Tag: GA4 - Event - AddToCart** * **Tag Type:** Google Analytics > GA4 Event * **Configuration Tag:** Select your `GA4 - Google Tag (Configuration)` tag. * **Event Name:** `add_to_cart` * **Event Parameters:** * Parameter Name: `currency`, Value: `{{DLV - ecommerce.currency}}` * Parameter Name: `value`, Value: `{{DLV - ecommerce.value}}` * Parameter Name: `items`, Value: `{{DLV - ecommerce.items}}` * **Trigger:** `CE - Add to Cart` * **Tag: GA4 - Event - BeginCheckout** * **Tag Type:** Google Analytics > GA4 Event * **Configuration Tag:** Select your `GA4 - Google Tag (Configuration)` tag. * **Event Name:** `begin_checkout` * **Event Parameters:** * Parameter Name: `currency`, Value: `{{DLV - ecommerce.currency}}` * Parameter Name: `value`, Value: `{{DLV - ecommerce.value}}` * Parameter Name: `items`, Value: `{{DLV - ecommerce.items}}` * **Trigger:** `CE - Begin Checkout` * **Tag: GA4 - Event - Purchase** * **Tag Type:** Google Analytics > GA4 Event * **Configuration Tag:** Select your `GA4 - Google Tag (Configuration)` tag. * **Event Name:** `purchase` * **Event Parameters:** * Parameter Name: `transaction_id`, Value: `{{DLV - ecommerce.transaction_id}}` * Parameter Name: `currency`, Value: `{{DLV - ecommerce.currency}}` * Parameter Name: `value`, Value: `{{DLV - ecommerce.value}}` * Parameter Name: `items`, Value: `{{DLV - ecommerce.items}}` * **Trigger:** `CE - Purchase` * **Tag: GA4 - Event - ViewItemList** * **Tag Type:** Google Analytics > GA4 Event * **Configuration Tag:** Select your `GA4 - Google Tag (Configuration)` tag. * **Event Name:** `view_item_list` * **Event Parameters:** * Parameter Name: `item_list_name`, Value: `{{DLV - ecommerce.item_list_name}}` * Parameter Name: `items`, Value: `{{DLV - ecommerce.items}}` * **Trigger:** `CE - View Item List` * **Tag: GA4 - Event - ViewCart** * **Tag Type:** Google Analytics > GA4 Event * **Configuration Tag:** Select your `GA4 - Google Tag (Configuration)` tag. * **Event Name:** `view_cart` * **Event Parameters:** * Parameter Name: `currency`, Value: `{{DLV - ecommerce.currency}}` * Parameter Name: `value`, Value: `{{DLV - ecommerce.value}}` * Parameter Name: `items`, Value: `{{DLV - ecommerce.items}}` * **Trigger:** `CE - View Cart` * **Tag: GA4 - Event - SelectItem** * **Tag Type:** Google Analytics > GA4 Event * **Configuration Tag:** Select your `GA4 - Google Tag (Configuration)` tag. * **Event Name:** `select_item` * **Event Parameters:** * Parameter Name: `items`, Value: `{{DLV - ecommerce.items}}` * **Trigger:** `CE - Select Item` * **Tag: GA4 - Event - AddShippingInfo** * **Tag Type:** Google Analytics > GA4 Event * **Configuration Tag:** Select your `GA4 - Google Tag (Configuration)` tag. * **Event Name:** `add_shipping_info` * **Event Parameters:** * Parameter Name: `currency`, Value: `{{DLV - ecommerce.currency}}` * Parameter Name: `value`, Value: `{{DLV - ecommerce.value}}` * Parameter Name: `shipping_tier`, Value: `{{DLV - ecommerce.shipping_method}}` * Parameter Name: `items`, Value: `{{DLV - ecommerce.items}}` * **Trigger:** `CE - Add Shipping Info` * **Tag: GA4 - Event - AddPaymentInfo** * **Tag Type:** Google Analytics > GA4 Event * **Configuration Tag:** Select your `GA4 - Google Tag (Configuration)` tag. * **Event Name:** `add_payment_info` * **Event Parameters:** * Parameter Name: `currency`, Value: `{{DLV - ecommerce.currency}}` * Parameter Name: `value`, Value: `{{DLV - ecommerce.value}}` * Parameter Name: `payment_type`, Value: `{{DLV - ecommerce.payment_method}}` * Parameter Name: `items`, Value: `{{DLV - ecommerce.items}}` * **Trigger:** `CE - Add Payment Info` After creating all tags, submit and publish your GTM container. == Advanced Configuration == Setup details for Consent Mode v2, the strict server-side consent mode (GDPR PII gating), CMP auto-block compatibility, and the WooCommerce Subscriptions integration. None of these are required for a basic CAPI setup — turn them on as your store needs them. ### Consent Mode v2 Setup (GDPR / EU Compliance) If you serve EU visitors, GA4 and Meta browser tags will not fire when a visitor refuses or has not yet acted on the cookie banner. The GTM tags wait for a `gtag('consent', 'update', ...)` signal that grants the relevant categories. Without **Google Consent Mode v2** wired up, this typically costs a store **20–50% of its measured event volume** in GA4 and Meta Events Manager. The data does not become "untrackable" — Google models it back, but only if you tell GTM that consent management is in play. **How Consent Mode v2 actually recovers the lost data** When a visitor denies consent, GA4 and Google Ads tags do not stop firing — they switch to **cookieless pings**: small anonymous beacons that carry no client identifier (no `_ga`, no `_fbp`, no IP retention) but include enough conversion context (event name, value, currency, timestamp) for Google's machine learning to perform **conversion modeling**. Modeled conversions appear in your standard reports, mixed with directly-observed ones, with a "modeled" footnote. Google publicly reports that Consent Mode users recover, on average, 20–50% of the conversions they would otherwise have lost to consent denial. The Meta Pixel GTM template reads the same `ad_storage` / `ad_user_data` / `ad_personalization` signals that Consent Mode v2 sets — so a single CMP integration repairs both GA4 and Meta attribution at once. Server-side CAPI continues to operate independently. **This plugin's job is to push events to the dataLayer regardless of consent state. The CMP's job is to tell GTM which categories the visitor allowed. GTM does the actual gating and signals back to the vendors.** **Step 1: Enable Consent Mode v2 in your CMP** Most popular CMP plugins have native Consent Mode v2 support. Find the toggle in your CMP plugin's settings: * **Cookiebot** — Settings → "Enable Google Consent Mode" (v2 is default in current versions) * **CookieYes** — Site Settings → "Google Consent Mode" → enable * **Complianz** — Integrations → Google Consent Mode → enable * **Iubenda** — Cookie Solution → Advanced settings → "Enable Consent Mode" → "v2 (advanced)" * **Termly** — Settings → Google Consent Mode → enable * **OneTrust** — Geolocation Rules → Consent Mode → enable + map categories Once enabled, your CMP will automatically call `gtag('consent', 'default', {...denied})` before GTM loads, then `gtag('consent', 'update', {...granted})` after the visitor accepts. **Step 2: (Optional) Enable the Consent Defaults tag in GTM** If you imported the GTM container template, it includes a paused Custom HTML tag named **"Consent Defaults (Pre-CMP) — Disabled, see readme"**. Enable this tag **only** if your CMP does **not** call `gtag('consent', 'default', ...)` on its own (rare with modern CMPs): 1. In GTM, open the tag. 2. Click the pause icon to enable it. 3. Change its trigger from `CE - PageView Meta` to the built-in **"Consent Initialization - All Pages"** trigger (visible in the trigger picker dropdown — guarantees this fires before any other tag). 4. Submit and publish. The tag sets all four consent types (`ad_storage`, `ad_user_data`, `ad_personalization`, `analytics_storage`) to `denied` with a 500 ms `wait_for_update` window. Your CMP's `gtag('consent', 'update', ...)` call then grants the categories the visitor approved. **Step 3: Verify it is working** * **GTM Preview Mode** — Open a page with the GTM Preview, click on `Consent Initialization` (top of timeline). Confirm `default` consent values appear for all four categories. After accepting in your CMP, click `Consent` events lower in the timeline; you should see `update` calls flipping the relevant categories to `granted`. * **Browser DevTools** — Network tab, filter for `g/collect` (GA4) or `tr` (Meta Pixel). Each request should include a `gcs=` query parameter. `gcs=G100` means denied, `G111` means granted, `G101` means analytics-only. If you see `gcs=` you have Consent Mode active. If you do not, the CMP wiring is incomplete. * **Tag Assistant** (tagassistant.google.com) — Connect to your site, fire any event, click on it, scroll to the "Consent" panel. Should show the current state and any updates within the session. ### Strict server-side consent mode (PII gating for CAPI) Consent Mode v2 controls the **browser** tags. The plugin's **server-side** CAPI calls do not see `gtag('consent', ...)` signals — they fire from PHP, hash the visitor's email/phone/address, and POST directly to `graph.facebook.com`. By default this happens regardless of cookie-banner choice, which is fine for non-EU stores but a GDPR concern for European traffic. The **Privacy & Consent (Server-side)** section in the plugin settings adds a "Strict server-side consent mode" checkbox (default OFF). When enabled, the plugin reads your CMP's cookie before queuing each event: * **Cookiebot** — `CookieConsent` cookie, looks for `marketing:true|false` * **CookieYes** — `cookieyes-consent` cookie, looks for `advertisement:yes|no` * **Complianz** — `cmplz_marketing` cookie, value `allow` / `deny` * **Other CMPs** — supply state via the `mcapi_marketing_consent_granted` filter (return `true` / `false` / `null`) If marketing consent is **explicitly denied**, identifying PII fields (`em`, `ph`, `fn`, `ln`, `ct`, `st`, `zp`, `country`, `external_id`, `fbp`, `fbc`, Pinterest click ID) are stripped from the CAPI payload. The event still ships — IP, user-agent, `event_id`, `value`, `currency`, `content_ids`, `contents` are retained — so Meta still receives a deduplicated server signal it can fold into conversion modeling, but the data is no longer personally identifying. If the cookie state is unknown (no recognized CMP) or consent is granted, behavior is unchanged. **How this complements Consent Mode v2.** When a visitor denies marketing consent, your browser-side GA4 / Meta Pixel switches to cookieless pings — small anonymous beacons that Google's ML uses to model the conversions you would have measured. That recovers some of the data, but it's modeled, not observed. With Strict server-side consent mode enabled, your **server-side CAPI continues to fire alongside the cookieless ping** — it ships the same `event_id` the browser ping carries, with `value` / `currency` / `contents` filled in from the order, just without the PII. Meta deduplicates the two events by `event_id` and now has a full server-side observed signal feeding the same conversion record the cookieless ping created. That is a cleaner input than what either browser-only or naïve "send everything" CAPI provides — and it is GDPR-defensible because no identifying user data is transmitted without consent. The toggle is OFF by default so existing setups don't see a sudden drop in CAPI matching once they update; turn it on after you've configured Consent Mode v2 in your CMP. ### CMP Auto-Blocking and the Plugin's Inline Scripts Some CMPs (especially CookieYes and Cookiebot when "auto-blocking" is enabled) scan every `