Opencart extensions free download · 6 min read · Updated

GA4 Ecommerce Tracking in OpenCart 4: view_item, add_to_cart, begin_checkout and purchase Without Editing Your Theme (Free Extension)

Send Google Analytics 4 ecommerce events from OpenCart 4.1: view_item_list, view_item, add_to_cart, view_cart, begin_checkout and purchase with items, value, tax and shipping. Free extension using OpenCart events, respects the cookie policy, with DebugView testing steps.

Opencart 4 GA4 ecommerce events

Pasting the Google Analytics tag into OpenCart’s header gives you page views. It doesn’t give you revenue, conversion rate, products viewed versus bought, or where shoppers drop out of checkout. For that, GA4 needs ecommerce events with product data, and OpenCart 4 doesn’t send any.

Our free extension sends them, using OpenCart’s event system so no theme file is edited. This post explains which events GA4 expects, what the extension sends and when, and how to check that the numbers are right.

The events GA4 expects

Google’s ecommerce guide defines a set of recommended events. These are the ones that build GA4’s purchase journey and ecommerce reports:

GA4 eventWhen the extension sends itKey parameters
view_item_listA category, search, specials, brand or home page shows products (including featured, latest and bestseller modules)item_list_name, items
view_itemA product page loadscurrency, value, items
add_to_cartA product is added to the cart, from the product page or a listing buttoncurrency, value, items
view_cartThe shopping cart page loadscurrency, value, items
begin_checkoutThe checkout page loadscurrency, value, coupon, items
purchaseThe order success page loads after a completed ordertransaction_id, currency, value, tax, shipping, coupon, items

Two rules from Google’s documentation drive most tracking bugs:

Set currency at the event level when sending value (revenue) data.

Google Analytics, Measure ecommerce

Without currency, GA4 can’t convert the value and the revenue doesn’t appear. The extension always sends the currency the customer is viewing. The second rule is in Google’s purchase example: the transaction ID is “Required for purchases and refunds.” The extension uses the OpenCart order ID.

How the extension works

OpenCart 4 has an analytics extension type: enabled analytics extensions are printed in the page <head>, but only after the visitor accepts your cookie policy (if you have one under System > Settings > Option > Cookie Policy). The extension uses that for the Google tag, so consent is handled the OpenCart way. The event scripts are added through events and only run if the Google tag is present, so nothing is sent for visitors who declined.

OpenCart eventWhat it does
catalog/model/catalog/product.getProducts/afterRemembers the products shown in lists on the page
catalog/view/product/product/afterAdds view_item to the product page
catalog/controller/checkout/cart.add/afterAdds the add_to_cart data to OpenCart’s AJAX response
catalog/view/checkout/cart/afterAdds view_cart
catalog/view/checkout/checkout/afterAdds begin_checkout
catalog/controller/checkout/success/beforeReads the order before OpenCart clears it from the session
catalog/view/common/footer/afterSends view_item_list and purchase, and listens for add-to-cart responses

Add to cart in OpenCart is an AJAX request that doesn’t reload the page. Instead of guessing from button clicks, the extension adds a ga4 key to the JSON that checkout/cart.add returns, and a small listener sends it to GA4 when the request succeeds. So add_to_cart is only sent when OpenCart actually added the product, not when a required option was missing.

The purchase event is built from the saved order, not from the cart: the item prices, the order total, the tax and shipping totals and the coupon code come from what OpenCart recorded.

Installation

  1. Remove any other Google Analytics code first: the Google Analytics extension, a tag pasted in the theme header, or GA4 inside Google Tag Manager. Otherwise every page view and purchase is counted twice.
  2. Download ga4_ecommerce.ocmod.zip with the button above.
  3. Extensions > Installer, upload the zip, and click the green Install button in the list.
  4. Extensions > Extensions, choose Analytics in the filter, find GA4 Ecommerce Events, click +, then the pencil.
  5. Enter your Measurement ID (GA4 Admin > Data streams > your web stream, starts with G-).
  6. Switch on Debug mode for now, switch on Status, and save.

Settings

SettingWhat it doesSuggested
Measurement IDYour GA4 web streamG-...
Item IDWhat GA4 receives as item_id: product ID, model, or the SKU from the product identifiersThe same ID your Google Merchant Center feed uses
Prices include taxItem prices with or without tax. The purchase value is always the order total.Off
Send view_item_listProduct list impressionsOn, unless you’re close to GA4 limits
Debug modeShows events in GA4 DebugViewOn while testing only

Item ID matters if you use Google Ads or Merchant Center. When item_id matches the id in your product feed, GA4, Ads and Merchant Center can join their data. Our Google Merchant Center guide explains the feed side.

Testing with DebugView

  1. Open your store in a private window and accept the cookie notice.
  2. In GA4, go to Admin > Data display > DebugView. Your visit appears within a minute.
  3. Click through: a category page (view_item_list), a product (view_item), Add to Cart (add_to_cart), the cart (view_cart), checkout (begin_checkout), and place a test order with Cash On Delivery or Bank Transfer (purchase).
  4. Click each event in DebugView and check its parameters: items with names and prices, currency, value, and for purchase, transaction_id with your order number.
  5. Turn Debug mode off.

Ecommerce reports (Reports > Monetization) take up to a day to show new data. DebugView is immediate.

You can also check in the browser: open the developer tools, Network tab, filter for collect?, and look for en=add_to_cart and the item parameters.

When the numbers don’t match OpenCart

GA4 revenue will never exactly match Reports > Sales in OpenCart, and that’s normal:

  • Visitors who decline cookies (or block trackers) aren’t counted. Read Google Consent Mode v2 explained if you need modeled data for them.
  • Off-site payments: purchase is sent on the success page. If a customer pays on PayPal or a bank’s page and doesn’t come back to your store, the order exists in OpenCart but GA4 never sees it. A server-side purchase event (GA4’s Measurement Protocol) fixes this; that’s a bigger project.
  • Orders created or edited in the admin aren’t tracked.
  • Refunds aren’t sent; GA4 shows gross revenue.

Our post why your analytics and ad platform numbers don’t match covers the general reasons.

What’s not included

  • select_item, remove_from_cart, add_shipping_info, add_payment_info and promotion events. The six events above are the ones GA4’s purchase journey and ecommerce reports need.
  • Item categories (item_category). OpenCart products can be in many categories, and picking one reliably needs per-store rules.
  • Server-side (Measurement Protocol) events.
  • Google Tag Manager. If you use GTM, push the same data to dataLayer instead; our older guide on OpenCart conversion tracking with GA4 and GTM shows that approach.

Ad platforms need their own events: see Meta Pixel tracking in OpenCart 4. To see how much revenue comes from ChatGPT, Perplexity and other AI assistants, read measuring AI search traffic in GA4.

Built for OpenCart 4.1.0.x. The code is on GitHub with our other free OpenCart extensions.

Rupak Nepali
Written byRupak Nepali

Author of four Opencart book.
The recent are Opencart 4 developer book and Opencart 4 user manual

Leave a Reply

Your email address will not be published. Required fields are marked *