Recent posts
nichemarket Advice
Tracking Ecwid eCommerce Events In Your WordPress Site
02 December 2026
Geek Chic
What Is RomM?
01 December 2026
Industry Experts
How to Choose a Digital Signage Company in South Africa
30 November 2026
Alarming
Did You Get a Ransomware Email From Your Own Address?
29 November 2026
Popular posts
Extravaganza
Trending Music Hashtags To Get Your Posts Noticed
24 August 2018
Geek Chic
How To Fix iPhone/iPad Only Charging In Certain Positions
05 July 2020
Extravaganza
Trending Wedding Hashtags To Get Your Posts Noticed
18 September 2018
Money Talks
How To Find Coupons & Vouchers Online In South Africa
28 March 2019
Tracking Ecwid eCommerce Events In Your WordPress Site
02 December 2026 | 0 comments | Posted by Che Kohler in nichemarket Advice
I come across some strange tech stacks from time to time and am never quite sure why, but once the client has settled on it, you have to work within the boundaries you're given. You could have picked WordPress and run WooCommerce, or you could have picked Ecwid, but instead you decided, "Why not both?"
You installed a WordPress instance for your landing pages and blog, but you're running all your eCommerce products through your Ecwid account via a plugin. While I can see some operational benefits to avoiding WooCommerce, the documentation, plugin support, and tracking options are pretty easy to set up.
But when you take on unique approaches like this, you'll find those old tracking methods are thrown out the window.
How to Track Ecwid eCommerce Events in Google Tag Manager on WordPress (When the Official App Fails)
Setting up eCommerce tracking for an Ecwid store hosted inside WordPress should be straightforward, yet many store owners hit a frustrating wall. Even after connecting Google Tag Manager (GTM) and installing Ecwid’s official GTM integration, product views, add-to-cart actions, and purchases often fail to show up in Google Tag Assistant or GA4.
If you are running the Ecwid Ecommerce Shopping Cart plugin on WordPress alongside an existing GTM setup and seeing zero eCommerce data in your dataLayer, this guide explains why it happens and gives you a copy-paste JavaScript solution that tracks view_item, add_to_cart, and purchase events reliably—without duplicate firing.
The Setup & Conditions Where This Happens
This specific tracking issue occurs under a very common WordPress configuration:
- Platform: A WordPress website using the official Ecwid Ecommerce Shopping Cart plugin to embed a storefront onto a WordPress page.
- Tag Management: Google Tag Manager is already installed at the WordPress level (via a plugin like GTM4WP, Google Site Kit, or a theme header script) to manage site-wide analytics and pixels.
- Analytics Goal: Sending standard GA4 eCommerce events (
view_item,add_to_cart, andpurchase) with product IDs, names, prices, and order totals intowindow.dataLayer.
Why Standard Ecwid + GTM Tracking Breaks on WordPress
When you combine WordPress GTM plugins with Ecwid, three technical conflicts commonly prevent events from firing properly:
1. Data Layer Conflicts Between WordPress and Ecwid
When a WordPress plugin loads GTM first, it initialises window.dataLayer on the parent page. Ecwid loads asynchronously as an external AJAX storefront inside that page. Frequently, Ecwid's built-in GTM app fails to bind its event listeners to the existing WordPress dataLayer, leaving your Tag Assistant timeline completely empty when shoppers browse or buy.
2. Legacy Analytics Settings Overriding GTM
If a Google Analytics ID (G-XXXXXXX or UA-XXXXXX) was ever entered under Ecwid → Settings → General → Tracking & Analytics, Ecwid routes eCommerce data directly to Google Analytics instead of pushing events into Google Tag Manager.
3. Duplicate add_to_cart Firing on OnCartChanged
If you try to bypass the official app by listening to Ecwid's JavaScript API (Ecwid.OnCartChanged), you quickly hit another snag: OnCartChanged does not only fire when a user clicks Add to Bag. It also fires on initial page load, mini-cart syncs, and background cart checks—causing a single add-to-cart action to fire three or more times in GA4.
Step-by-Step Solution: Hook Ecwid's JS API Directly into GTM
Note: Before you start, do not use the Ecwid GTM connector; instead, embed your GTM script in your site header, as it will fire across both Ecwid pages and your standard WordPress pages.
Instead of relying on Ecwid's built-in GTM app to bridge the gap, you can add a single Custom HTML Tag inside Google Tag Manager.
This script listens directly to Ecwid's native storefront API (Ecwid.OnAPILoaded), compares cart states to prevent duplicate add_to_cart events, and pushes clean GA4 eCommerce schemas into your WordPress dataLayer.
Step 1: Clean Up Conflicting Settings in WordPress & Ecwid
Before adding the custom script, make sure GTM only loads once on your site:
- In your WordPress dashboard, open Ecwid → Settings → General → Tracking & Analytics and ensure the Google Analytics ID field is completely blank.
- Open Ecwid → Settings → Google Tag Manager and remove your
GTM-XXXXXXContainer ID so your WordPress GTM plugin remains the single source loading GTM. - If you use a WordPress caching or optimisation plugin (such as WP Rocket, LiteSpeed Cache, or Autoptimize), exclude
ecwid.comandgoogletagmanager.comfrom JavaScript deferral or combination.
Step 2: Add the Custom HTML Listener Tag in GTM
- Log into Google Tag Manager and go to Tags → New.
- Click Tag Configuration and select Custom HTML.
- Paste the following script into the HTML box (remember to update
storeCurrencyon line 8 to match your store's currency, such as'USD','EUR', or'ZAR'):
html
<script>
window.dataLayer = window.dataLayer || [];
function initEcwidGTM() {
if (typeof Ecwid === 'undefined') return;
Ecwid.OnAPILoaded.add(function() {
var storeCurrency = 'USD'; // Change to your store currency (e.g., ZAR, EUR, GBP)
var previousCart = null;
// Helper: Convert cart items into a lookup map by product ID + selected options
function mapCartItems(items) {
var map = {};
if (!items) return map;
items.forEach(function(item) {
var key = item.product.id + '_' + JSON.stringify(item.options || {});
map[key] = {
id: item.product.sku || String(item.product.id),
name: item.product.name,
price: item.product.price,
quantity: item.quantity
};
});
return map;
}
// 1. Capture initial cart state on page load without firing add_to_cart
Ecwid.Cart.get(function(cart) {
previousCart = mapCartItems(cart.items);
});
// 2. Track Product Views (view_item)
Ecwid.OnPageLoaded.add(function(page) {
if (page.type === 'PRODUCT') {
var titleEl = document.querySelector('.product-details__product-title');
var skuEl = document.querySelector('meta[itemprop="sku"]');
var priceEl = document.querySelector('[itemprop="price"]');
window.dataLayer.push({ ecommerce: null });
window.dataLayer.push({
event: 'view_item',
ecommerce: {
currency: storeCurrency,
value: priceEl ? parseFloat(priceEl.getAttribute('content')) : 0,
items: [{
item_id: skuEl ? skuEl.getAttribute('content') : String(page.productId),
item_name: titleEl ? titleEl.textContent.trim() : 'Product ' + page.productId,
price: priceEl ? parseFloat(priceEl.getAttribute('content')) : 0,
quantity: 1
}]
}
});
}
});
// 3. Track Add to Cart (add_to_cart) — Fires only when quantity increases
Ecwid.OnCartChanged.add(function(cart) {
var currentCart = mapCartItems(cart.items);
// Skip if initial cart baseline hasn't loaded yet
if (previousCart === null) {
previousCart = currentCart;
return;
}
Object.keys(currentCart).forEach(function(key) {
var currentItem = currentCart[key];
var prevQty = previousCart[key] ? previousCart[key].quantity : 0;
var addedQty = currentItem.quantity - prevQty;
if (addedQty > 0) {
window.dataLayer.push({ ecommerce: null });
window.dataLayer.push({
event: 'add_to_cart',
ecommerce: {
currency: storeCurrency,
value: currentItem.price * addedQty,
items: [{
item_id: currentItem.id,
item_name: currentItem.name,
price: currentItem.price,
quantity: addedQty
}]
}
});
}
});
// Update baseline for the next cart action
previousCart = currentCart;
});
// 4. Track Completed Purchases (purchase)
Ecwid.OnOrderPlaced.add(function(order) {
var purchasedItems = order.items.map(function(item) {
return {
item_id: item.sku || String(item.productId),
item_name: item.name,
price: item.price,
quantity: item.quantity
};
});
window.dataLayer.push({ ecommerce: null });
window.dataLayer.push({
event: 'purchase',
ecommerce: {
transaction_id: String(order.orderNumber),
value: order.total,
tax: order.tax,
shipping: order.shipping,
currency: storeCurrency,
items: purchasedItems
}
});
});
});
}
// Guard against the tag initializing twice during AJAX navigation
if (!window.ecwidGTMInitialized) {
window.ecwidGTMInitialized = true;
var ecwidCheck = setInterval(function() {
if (typeof Ecwid !== 'undefined') {
clearInterval(ecwidCheck);
initEcwidGTM();
}
}, 300);
}
</script>
Use code with caution.
- Under Triggering, select All Pages (or DOM Ready).
- Name the tag
cHTML - Ecwid eCommerce DataLayer Listenerand click Save.
Step 3: Create the GA4 Ecommerce Trigger in GTM
Now that Ecwid is pushing clean events into window.dataLayer, tell GTM to listen for them:
- Go to Triggers → New and select Custom Event.
- In the Event name field, paste:
view_item|add_to_cart|purchase - Check the box labelled Use regex matching.
- Name the trigger
CE - Ecwid Ecommerce Eventsand click Save.
Step 4: Forward the Events to Google Analytics 4
- Go to Tags → New and select Google Analytics: GA4 Event.
- Enter your Measurement ID (
G-XXXXXXX). - In the Event Name field, click the variable icon and select
{{Event}}so GTM dynamically forwards the exact event name (view_item,add_to_cart, orpurchase). - Expand More Settings, check Send Ecommerce data, and verify that Data Source is set to Data Layer.
- Under Triggering, attach the
CE - Ecwid Ecommerce Eventstrigger you created in Step 3. - Name the tag
GA4 - Ecommerce Eventsand click Save.
Step 5: Test in Tag Assistant Before Publishing
- Click Preview in the top right of your GTM workspace and enter your WordPress store URL.
- View a product page, add an item to your cart, and complete a test order (enable an offline payment method in Ecwid temporarily so you do not have to process a real card).
- Verify in Tag Assistant that
view_item,add_to_cart, andpurchaseeach fires once and contains populateditems,value,currency, andtransaction_idvalues. - Return to GTM and click Submit to publish your changes live.
Need Help With Your Tracking?
If this all sounds like too much of a headache and you'd much prefer a tracking expert to set up your ad account pixel, reach out to us and we'll get you set up.Are you looking to promote your business?
Business owners can create their free business listings on nichemarket. The more information you provide about your business, the easier it will be for your customers to find you online. Registering with nichemarket is easy; just head to our sign-up form and follow the instructions.
If you need a more detailed guide on creating your profile or listing, we recommend checking out the following articles.
Recommended reading
If you enjoyed this post and have a little extra time to dive deeper down the rabbit hole, why not check out the following posts on tracking.
Tags: WordPress, eCommerce, Tracking
You might also like
How to Choose a Digital Signage Company in South Africa
30 November 2026
Posted by Pamela Lattimore in Industry Experts
Compare digital signage companies in South Africa on CMS control, hardware quality, pricing, and ongoing support before you sign a subscription agree...
Read moreAI Content Creation on a Budget: Marketing Tips for SA Startups
24 November 2026
Posted by Reva Tatianna in Industry Experts
Practical tips for South African startups to create AI content on a tight budget: lean tool stacks, short video, local languages, POPIA and data cost...
Read more{{comment.sUserName}}
{{comment.iDayLastEdit}} day ago
{{comment.iDayLastEdit}} days ago
{{blogcategory.sCategoryName}}