LOG IN OR SIGN UP
Log in to your account
Sign up

Tracking Ecwid eCommerce Events In Your WordPress Site

02 December 2026 | 0 comments | Posted by Che Kohler in nichemarket Advice

tracking eCommerce events in Ecwid WP Sites

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, and purchase) with product IDs, names, prices, and order totals into window.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:

  1. In your WordPress dashboard, open Ecwid → Settings → General → Tracking & Analytics and ensure the Google Analytics ID field is completely blank.
  2. Open Ecwid → Settings → Google Tag Manager and remove your GTM-XXXXXX Container ID so your WordPress GTM plugin remains the single source loading GTM.
  3. If you use a WordPress caching or optimisation plugin (such as WP Rocket, LiteSpeed Cache, or Autoptimize), exclude ecwid.com and googletagmanager.com from JavaScript deferral or combination.

Step 2: Add the Custom HTML Listener Tag in GTM

  1. Log into Google Tag Manager and go to Tags → New.
  2. Click Tag Configuration and select Custom HTML.
  3. Paste the following script into the HTML box (remember to update storeCurrency on 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. 

  1. Under Triggering, select All Pages (or DOM Ready).
  2. Name the tag cHTML - Ecwid eCommerce DataLayer Listener and 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:

  1. Go to Triggers → New and select Custom Event.
  2. In the Event name field, paste:
    view_item|add_to_cart|purchase
  3. Check the box labelled Use regex matching.
  4. Name the trigger CE - Ecwid Ecommerce Events and click Save.

Step 4: Forward the Events to Google Analytics 4

  1. Go to Tags → New and select Google Analytics: GA4 Event.
  2. Enter your Measurement ID (G-XXXXXXX).
  3. 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, or purchase).
  4. Expand More Settings, check Send Ecommerce data, and verify that Data Source is set to Data Layer.
  5. Under Triggering, attach the CE - Ecwid Ecommerce Events trigger you created in Step 3.
  6. Name the tag GA4 - Ecommerce Events and click Save.

Step 5: Test in Tag Assistant Before Publishing

  1. Click Preview in the top right of your GTM workspace and enter your WordPress store URL.
  2. 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).
  3. Verify in Tag Assistant that view_item, add_to_cart, and purchase each fires once and contains populated items, value, currency, and transaction_id values.
  4. 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

Previous: {{ previousBlog.sTitle }}

Posted {{ previousBlog.dtDatePosting }}

Next: {{ nextBlog.sTitle }}

Posted {{ nextBlog.dtDatePosting }}

You might also like

How to Choose a Digital Signage Company in South Africa

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 more
AI content Creation

AI 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

Leave us a comment


{{comment.sUserName}}

{{comment.iDayLastEdit}} day ago

{{comment.iDayLastEdit}} days ago

{{comment.sComment}}

Sign up for our newsletter