| 开发者 |
suhanduman
cenkcagdas |
|---|---|
| 更新时间 | 2026年4月23日 03:18 |
/wp-content/plugins/ directory and activate it.FB_. Since we will be creating our own tags manually, only they should be active.gtm-template.json template file. Download this file to your computer.
Step 2: Import the Template into GTM
gtm-template.json file you downloaded.META_PIXEL_ID with your actual Meta Pixel ID.GA4_MEASUREMENT_ID with your actual GA4 Measurement ID (e.g., G-XXXXXXXXXX).PINTEREST_TAG_ID with your actual Pinterest Tag ID.DLV - event_idevent_idDLV - ecommerceecommerceDLV - Hashed Emailuser_data.emailDLV - ecommerce.shipping_methodecommerce.shipping_methodDLV - ecommerce.payment_methodecommerce.payment_methodCE - PageView Metapage_view_metaCE - View Itemview_itemCE - Add to Cartadd_to_cartCE - Begin Checkoutbegin_checkoutCE - PurchasepurchaseCE - View Item Listview_item_listCE - View Cartview_cartCE - Select Itemselect_itemCE - Add Shipping Infoadd_shipping_infoCE - Add Payment Infoadd_payment_infoPageView{{DLV - event_id}}CE - PageView MetaViewContent{{DLV - ecommerce}}{{DLV - event_id}}CE - View ItemAddToCart{{DLV - ecommerce}}{{DLV - event_id}}CE - Add to CartInitiateCheckout{{DLV - ecommerce}}{{DLV - event_id}}CE - Begin CheckoutPurchase{{DLV - ecommerce}}{{DLV - event_id}}CE - PurchaseViewCategory{{DLV - ecommerce}}{{DLV - event_id}}CE - View Item ListAddPaymentInfo{{DLV - ecommerce}}{{DLV - event_id}}CE - Add Payment InfoDLV - ecommerce.value (Data Layer Variable Name: ecommerce.value)DLV - ecommerce.currency (Data Layer Variable Name: ecommerce.currency)DLV - ecommerce.items (Data Layer Variable Name: ecommerce.items)
Create the following tags:
{{DLV - Hashed Email}}page_visitevent_id, Value {{DLV - event_id}}CE - PageView Meta{{DLV - Hashed Email}}pagevisitevent_id, value, currency, and contents with their corresponding variables.CE - View Item{{DLV - Hashed Email}}add_to_cartevent_id, value, currency, and contents with their corresponding variables.CE - Add to Cart{{DLV - Hashed Email}}initiate_checkoutevent_id, value, currency, and contents with their corresponding variables.CE - Begin Checkout{{DLV - Hashed Email}}checkoutevent_id, value, currency, and contents with their corresponding variables.CE - Purchase{{DLV - Hashed Email}}viewcategoryevent_id, Value {{DLV - event_id}}content_name, Value {{DLV - ecommerce.item_list_name}}CE - View Item ListG-) from your Google Analytics 4 property. You must also create the following Data Layer Variables:
DLV - ecommerce.currency (Data Layer Variable Name: ecommerce.currency)DLV - ecommerce.value (Data Layer Variable Name: ecommerce.value)DLV - ecommerce.items (Data Layer Variable Name: ecommerce.items)DLV - ecommerce.transaction_id (Data Layer Variable Name: ecommerce.transaction_id)DLV - ecommerce.item_list_name (Data Layer Variable Name: ecommerce.item_list_name)
First, create the main configuration tag that loads GA4 on all pages.
G-XXXXXXXXXX)All Pages
Next, create the event tags that will send data from the dataLayer to Google Analytics.
GA4 - Google Tag (Configuration) tag.page_viewCE - PageView MetaGA4 - Google Tag (Configuration) tag.view_itemcurrency, Value: {{DLV - ecommerce.currency}}value, Value: {{DLV - ecommerce.value}}items, Value: {{DLV - ecommerce.items}}CE - View ItemGA4 - Google Tag (Configuration) tag.add_to_cartcurrency, Value: {{DLV - ecommerce.currency}}value, Value: {{DLV - ecommerce.value}}items, Value: {{DLV - ecommerce.items}}CE - Add to CartGA4 - Google Tag (Configuration) tag.begin_checkoutcurrency, Value: {{DLV - ecommerce.currency}}value, Value: {{DLV - ecommerce.value}}items, Value: {{DLV - ecommerce.items}}CE - Begin CheckoutGA4 - Google Tag (Configuration) tag.purchasetransaction_id, Value: {{DLV - ecommerce.transaction_id}}currency, Value: {{DLV - ecommerce.currency}}value, Value: {{DLV - ecommerce.value}}items, Value: {{DLV - ecommerce.items}}CE - PurchaseGA4 - Google Tag (Configuration) tag.view_item_listitem_list_name, Value: {{DLV - ecommerce.item_list_name}}items, Value: {{DLV - ecommerce.items}}CE - View Item ListGA4 - Google Tag (Configuration) tag.view_cartcurrency, Value: {{DLV - ecommerce.currency}}value, Value: {{DLV - ecommerce.value}}items, Value: {{DLV - ecommerce.items}}CE - View CartGA4 - Google Tag (Configuration) tag.select_itemitems, Value: {{DLV - ecommerce.items}}CE - Select ItemGA4 - Google Tag (Configuration) tag.add_shipping_infocurrency, Value: {{DLV - ecommerce.currency}}value, Value: {{DLV - ecommerce.value}}shipping_tier, Value: {{DLV - ecommerce.shipping_method}}items, Value: {{DLV - ecommerce.items}}CE - Add Shipping InfoGA4 - Google Tag (Configuration) tag.add_payment_infocurrency, Value: {{DLV - ecommerce.currency}}value, Value: {{DLV - ecommerce.value}}payment_type, Value: {{DLV - ecommerce.payment_method}}items, Value: {{DLV - ecommerce.items}}CE - Add Payment Info
After creating all tags, submit and publish your GTM container.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.
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.
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.
WooCommerce. That's it. If you use other GTM plugins (like Google Site Kit), disable their e-commerce features to avoid conflicts.
No. Everything is included.
Check these in order:
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.
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.
Go to Autoptimize → JS, CSS & HTML → Exclude scripts from Autoptimize and add the same script IDs.
The plugin adds data-cfasync="false" to its inline scripts, which Cloudflare Rocket Loader respects. No configuration needed.
Yes. The plugin's tracking works with the WooCommerce Products block used by FSE themes.
/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.<head> (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.external_id is now SHA-256 hashed when sent to Meta (was sent plain, which hurt Event Match Quality).<form> in admin UI — "Refresh Log" button now actually submits (was silently dropped by browsers).double-hash on Pinterest external_id (since it's now hashed upstream) — passed through as-is.mcapi_queue_batch_size — high-traffic stores can raise the 100-per-tick ceiling.nocache_headers() so Cloudflare and other upstream caches do not cache the POST response._fbp and _fbc cookies are re-written server-side on every request with a 90-day TTL, which iOS/macOS Safari does NOT cap to 7 days (only JS-written cookies are capped). Long-window attribution for iOS shoppers is restored; often the single biggest EMQ lift for stores with heavy iOS traffic.external_id is now the cookie-backed UUID (not billing email) when an order is processed. Keeps the Meta user journey consistent across PageView → AddToCart → Purchase. Email is still sent separately in the em field, so Meta's matching is unchanged.mcapi_guest_external_id cookie now HTTP-only, Secure (on HTTPS), SameSite=Lax, 1-year TTL.data-no-defer="1" and data-no-minify="1" attributes to inline scripts so LiteSpeed Cache and other aggressive optimizers don't wrap them in type="litespeed/javascript" (which prevented the scripts from running)./wp-admin/admin-ajax.php. This was lowering Meta Event Match Quality (EMQ) scores and breaking attribution.woocommerce_before_single_product (before related-products/upsells render) instead of reading global $product in wp_footer (where it was often overwritten by the last related product in the loop). Meta was receiving wrong product IDs on product pages with related/upsell sections.data-mcapi-product-data attribute already present on the add-to-cart button (no extra HTML output).data-cfasync="false" and data-no-optimize="1" attributes to all plugin inline scripts. These signal Cloudflare Rocket Loader, LiteSpeed Cache, WP Rocket, and Autoptimize not to defer or combine the scripts — helps events fire on sites with aggressive JS optimizers.uniqid() alongside cart_item_key. Adding the same product twice no longer gets silently deduplicated by Meta (WooCommerce reuses cart_item_key when incrementing quantity on an existing cart item).woocommerce_before_shop_loop_item_title, and the JS walks up the DOM from the clicked link to find it — no hard-coded CSS class dependencies.woocommerce_add_to_cart hook for all flows (classic page-reload AND AJAX cart), instead of relying on frontend JS. This is what CAPI was designed for — reliable tracking immune to adblockers, tracker blockers, and theme incompatibilities. Maximum theme coverage.woocommerce_add_to_cart_fragments filter, which injects the push script into the AJAX response. Works on any theme that uses WooCommerce's standard AJAX cart.event_id between server-side CAPI and browser-side dataLayer push (based on cart_item_key), guaranteeing Meta deduplication.mcapi_ajax_fired_* session flag and DOING_AJAX skip logic that was causing events to be lost when JS AJAX was blocked.woocommerce_add_to_cart trigger now reaches Meta/Pinterest, regardless of browser-side interference.eventName: "standard" + standardEventName parameters. Previously all browser-side events were sent as PageView because the Facebook Pixel community template requires a radio button selector, not a direct event name.CONST - Meta Pixel ID) instead of referencing a tag name, which GTM cannot resolve.item_price to price to match GA4 standard. Fixes zero revenue in GA4 Item Revenue reports.view_content instead of page_visit.view_category event instead of search.contents instead of line_items, correct sub-field names).add_payment_info and view_category events.mcapi_ prefix per WordPress naming conventions.$_SERVER superglobal inputs to prevent potential injection issues.