=== 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.4.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.** == 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. == 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, you must update the placeholder IDs with your own tracking IDs. 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 the variable. All Meta tags will automatically use this value. 3. Go to the **Tags** section. 4. Find and click on the **"GA4 - Google Tag (Configuration)"** tag. * Replace `GA4_MEASUREMENT_ID` with your actual GA4 Measurement ID (e.g., `G-XXXXXXXXXX`). * Save the tag. 5. Find and click on the **"Pinterest - PageView"** tag. * Replace `PINTEREST_TAG_ID` with your actual Pinterest Tag ID. * Save the tag. **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. ### 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 **Custom JavaScript Variables** (Variable Type: Custom JavaScript). The plugin emits e-commerce data using the modern GA4 schema (`ecommerce.items[]` with `item_id`, `item_name`, `price`, etc.), but Meta and Pinterest expect the `contents[]` shape (`id`, `quantity`, `item_price`). These two variables convert the schema in the browser before the tag fires. * **Variable Name:** `CJS - Meta Object Properties` * **Custom JavaScript:** `function() {` ` var ecommerce = {{DLV - ecommerce}};` ` if (!ecommerce || !ecommerce.items) return undefined;` ` var contents = ecommerce.items.map(function(item) {` ` return {` ` id: item.id || item.item_id,` ` quantity: item.quantity || 1,` ` item_price: item.price` ` };` ` });` ` return {` ` value: ecommerce.value,` ` currency: ecommerce.currency,` ` content_type: 'product',` ` contents: contents,` ` content_ids: contents.map(function(item) { return item.id; })` ` };` `}` * **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 (Facebook Pixel) Install the **"Facebook Pixel"** template from the GTM Community Template Gallery. Create the following tags. * **Tag: Meta - PageView** * **Event Name:** `PageView` * **More Settings > Event ID:** `{{DLV - event_id}}` * **Trigger:** `CE - PageView Meta` * **Tag: Meta - ViewContent** * **Event Name:** `ViewContent` * **Object Properties:** `{{CJS - Meta Object Properties}}` * **More Settings > Event ID:** `{{DLV - event_id}}` * **Trigger:** `CE - View Item` * **Tag: Meta - AddToCart** * **Event Name:** `AddToCart` * **Object Properties:** `{{CJS - Meta Object Properties}}` * **More Settings > Event ID:** `{{DLV - event_id}}` * **Trigger:** `CE - Add to Cart` * **Tag: Meta - InitiateCheckout** * **Event Name:** `InitiateCheckout` * **Object Properties:** `{{CJS - Meta Object Properties}}` * **More Settings > Event ID:** `{{DLV - event_id}}` * **Trigger:** `CE - Begin Checkout` * **Tag: Meta - Purchase** * **Event Name:** `Purchase` * **Object Properties:** `{{CJS - Meta Object Properties}}` * **More Settings > Event ID:** `{{DLV - event_id}}` * **Trigger:** `CE - Purchase` * **Tag: Meta - ViewCategory** * **Event Name:** `ViewCategory` * **Object Properties:** `{{CJS - Meta Object Properties}}` * **More Settings > Event ID:** `{{DLV - event_id}}` * **Trigger:** `CE - View Item List` * **Tag: Meta - AddPaymentInfo** * **Event Name:** `AddPaymentInfo` * **Object Properties:** `{{CJS - Meta Object Properties}}` * **More Settings > Event ID:** `{{DLV - event_id}}` * **Trigger:** `CE - Add Payment Info` #### 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. == Upgrade Notice == = 3.4.2 = **Action required for existing installs.** This release fixes a schema-conversion bug that caused Meta Events Manager to reject parameters from browser-side tags. Your existing GTM container needs to be updated to receive the fix. After updating, the plugin will show a one-time admin notice with two paths: (A) re-download the GTM template from the plugin settings page and re-import it with "Merge" mode, or (B) manually create the two new Custom JavaScript variables in GTM. Server-side CAPI was unaffected and continues to work as before. == Changelog == = 3.4.2 = * Fix: GTM container template now ships with two Custom JavaScript Variables (`CJS - Meta Object Properties` and `CJS - Pinterest Contents`) that convert the plugin's GA4-schema dataLayer (`ecommerce.items[]`) into the `contents[]` shape Meta Pixel and Pinterest Tag expect (`id`, `quantity`, `item_price`). All Meta tag `objectProperties` now reference the new CJS variable instead of `{{DLV - ecommerce}}`. Without this conversion, Meta Events Manager would surface "missing parameter" warnings and Pinterest catalog matching would fail because the schemas do not align. * Fix: Manual GTM setup instructions in the readme are updated to mirror the template change. Step 1 now lists every Data Layer Variable used across Meta, Pinterest, and GA4 sections (previously duplicated as section-specific prerequisites) plus the two new CJS variables. Step 3 (Meta) tags reference `{{CJS - Meta Object Properties}}` for Object Properties; Step 3 (Pinterest) tags reference `{{CJS - Pinterest Contents}}` for the `contents` and `content_ids` custom parameters. * Fix: Pinterest event-name typos in the manual setup. `Pinterest - ViewContent` was instructed to fire `pagevisit` (causing it to dedupe with PageView server-side); now correctly `view_content`. `Pinterest - ViewCategory` was `viewcategory`; now `view_category`. Both match the plugin's CAPI event-name mapping, so server-side and browser-side events now share an `event_id` for the same Pinterest event name and can be properly deduped. * Fix: Pinterest tag instructions were missing the `content_ids` custom parameter. Without it, Pinterest cannot match events to catalog products for retargeting and dynamic-product-ad attribution. = 3.4.1 = * Fix: dataLayer items now include `item_id` alongside `id`. GA4's Enhanced Ecommerce schema requires `item_id` — without it, the GA4 Items report showed "(not set)" for product breakdowns even though events were firing correctly. Meta CAPI continues to read `id` from `contents[]` as before, so server-side tracking is unchanged. Existing GTM tags configured to read `id` keep working; new tags can use the GA4-spec `item_id`. = 3.4.0 = * Fix: Event log timestamps were displayed up to a few hours ahead of real time on hosts where the PHP server timezone differs from the WordPress timezone (e.g. PHP set to UTC, WP set to Europe/Prague). Logs are now stored in UTC and converted to the WordPress timezone for display, matching the cleanup queries that already used UTC. * Fix: GTM container template (`assets/gtm-template.json`) failed to import with "File format is invalid. Error deserializing enum type. Unrecognized value [EVENT]." All nine GA4 Event tag parameter blocks have been restructured from the invalid `EVENT`-typed stringified payload into the correct `LIST` of `MAP` entries with `name`/`value` keys, per the GTM container schema. The template now imports cleanly. * Improvement: Bot and crawler traffic is now filtered before reaching the event queue. AhrefsBot, SemrushBot, Wordfence, Pingdom, GTmetrix, headless browsers (Puppeteer/Playwright), `curl`, `python-requests`, and similar self-identifying clients no longer generate phantom AddToCart, PageView, or other events. Purchase events are intentionally exempt to avoid losing real conversions to over-eager UA matching. Filterable via `mcapi_is_bot_request`. * Improvement: Recurring tasks (event queue processor, daily log cleanup) now use Action Scheduler when available — the same library WooCommerce ships with. Action Scheduler runs reliably on low-traffic sites that rarely trigger WP-Cron, has built-in retry, and exposes a Tools → Scheduled Actions admin UI for debugging stuck jobs. Existing installs are migrated automatically on first load. WP-Cron is preserved as a fallback if Action Scheduler is unavailable. * Improvement: SelectItem (item-list click) detection no longer depends on a hard-coded list of theme-specific wrapper classes. A new `mcapi-loop-item` class is injected onto every WooCommerce loop product via the `woocommerce_post_class` filter, providing a stable, theme-agnostic anchor for the click handler. The legacy class list is retained as a fallback for builders that bypass `post_class`. * Improvement: Log entries written from the cron batch processor now record the original event time (when the visitor's action actually fired) rather than the cron processing time, eliminating the up-to-60-second drift in the event log timeline. * Fix: Login event ID could collide on same-second logins (e.g. SSO double-callback). Now uses microsecond precision plus a six-character random suffix. = 3.3.0 = * New: REST API endpoint `/wp-json/mcapi/v1/event` for cache-safe browser-side tracking. No nonce required, so events continue to fire on pages served from a 7-day LiteSpeed/Varnish/Cloudflare cache. Secured by strict same-origin check, per-IP rate limit (50/min), global rate limit (1000/min), 16 KB body cap, and event-name whitelist. * New: Inline bootstrap helper printed at top of `
` (priority 1). All three inline tracking scripts (PageView, ViewContent, ViewCategory) share one code path that tries REST first, falls back to admin-ajax.php with a hard-coded fallback nonce if REST is blocked by a WAF. * Improvement: Reliable retries — transient API failures (HTTP 5xx, 429, network timeouts) no longer drop events from the queue. They stay queued and retry on the next cron tick. Permanent failures (4xx) still drop to avoid infinite retries. Queue retention extended to 24 hours to cover longer API outages. * Improvement: ViewCart and ViewCategory events now respect the per-event enable checkboxes in settings. They were previously always-on. * Improvement: `external_id` is now SHA-256 hashed when sent to Meta (was sent plain, which hurt Event Match Quality). * Improvement: REST handler respects per-event enable checkboxes — prevents cached pages from sending events the merchant has turned off. * Improvement: Description rewritten to highlight cache compatibility, REST/AJAX dual path, and retry semantics. * Fix: Nested `