Cart abandonment and checkout drop-offs are the most critical friction points in any eCommerce funnel. Leveraging Google Analytics 4 (GA4) with Google Tag Manager (GTM), OpenCart merchants can track where users exit the funnelβenabling precise optimization and personalized remarketing.
β What Will You Achieve?
GA4 Event | Purpose |
---|---|
add_to_cart |
Detect interest but no checkout |
begin_checkout |
Detect checkout intent |
purchase |
Confirm conversion |
Custom Dimensions | Track checkout step numbers |
Funnel Report | Visualize drop-off rates per step |
π§° Requirements
- OpenCart 3.x or 4.x
- Google Analytics 4 property
- GTM web container installed
- GA4 base tag implemented
- Checkout built on OpenCartβs default controller (or customized checkout endpoint)
π Step-by-Step Implementation
πΉ Step 1: Track add_to_cart
Events
Edit: catalog/controller/checkout/cart.php
$product_info = $this->model_catalog_product->getProduct($product_id);
$data['gtm_add_to_cart'] = json_encode([
'event' => 'add_to_cart',
'ecommerce' => [
'currency' => $this->session->data['currency'],
'value' => $product_info['price'],
'items' => [[
'item_id' => $product_info['model'],
'item_name' => $product_info['name'],
'price' => $product_info['price'],
'quantity' => $quantity
]]
]
]);
In the appropriate .twig
file (e.g., cart.twig
):
{% if gtm_add_to_cart %}
<script>
window.dataLayer = window.dataLayer || [];
dataLayer.push({{ gtm_add_to_cart|raw }});
</script>
{% endif %}
πΉ Step 2: Track begin_checkout
Events
Edit: catalog/controller/checkout/checkout.php
$products = $this->cart->getProducts();
$items = [];
foreach ($products as $product) {
$items[] = [
'item_id' => $product['model'],
'item_name' => $product['name'],
'price' => $product['price'],
'quantity' => $product['quantity']
];
}
$data['gtm_begin_checkout'] = json_encode([
'event' => 'begin_checkout',
'ecommerce' => [
'currency' => $this->session->data['currency'],
'items' => $items
]
]);
In checkout.twig
:
{% if gtm_begin_checkout %}
<script>
dataLayer.push({{ gtm_begin_checkout|raw }});
</script>
{% endif %}
πΉ Step 3: Track purchase
on Order Success
Edit: catalog/controller/checkout/success.php
$order_info = $this->model_checkout_order->getOrder($this->session->data['order_id']);
$products = $this->model_checkout_order->getOrderProducts($order_info['order_id']);
$items = [];
foreach ($products as $product) {
$items[] = [
'item_id' => $product['model'],
'item_name' => $product['name'],
'price' => $product['price'],
'quantity' => $product['quantity']
];
}
$data['gtm_purchase'] = json_encode([
'event' => 'purchase',
'ecommerce' => [
'transaction_id' => $order_info['order_id'],
'value' => $order_info['total'],
'currency' => $order_info['currency_code'],
'items' => $items
]
]);
In success.twig
:
{% if gtm_purchase %}
<script>
dataLayer.push({{ gtm_purchase|raw }});
</script>
{% endif %}
πΉ Step 4: Add Checkout Step Tracking (Optional but Recommended)
You can push the checkout step as a custom dimension:
$data['gtm_checkout_step'] = json_encode([
'event' => 'checkout_progress',
'ecommerce' => [
'checkout_step' => 2 // billing step
]
]);
Then in GTM, create a Custom Dimension in GA4 config:
- Name:
checkout_step
- Scope: Event
πΉ Step 5: Configure GA4 Event Tags in GTM
In GTM:
- Tag Type: GA4 Event
- Use Event Name matching
add_to_cart
,begin_checkout
, etc. - Event Parameters:
currency
,value
,items
- Trigger:
- Custom Event Trigger with matching name (e.g.,
add_to_cart
)
- Custom Event Trigger with matching name (e.g.,
Repeat for each event.
πΉ Step 6: Mark Conversions in GA4
In GA4 Admin β Events:
- Mark
purchase
as a conversion - Optionally also mark
begin_checkout
for checkout funnel analysis
πΉ Step 7: Build a Funnel Exploration in GA4
Go to GA4 β Explore > Funnel Exploration
Funnel Steps:
add_to_cart
begin_checkout
purchase
Use elapsed time to see conversion delays.
Breakdowns:
- Device
- Source/medium
- Region
- Product category
πΉ Step 8: Detect Cart Abandonment (via Audience)
In GA4 β Configure β Audiences:
- Include users who triggered
add_to_cart
- AND did not trigger
begin_checkout
orpurchase
in 1 hour - Use this audience for remarketing in Google Ads
π§ Pro Tips
Tip | Reason |
---|---|
Match item_id with feed id |
Enables Google Ads dynamic remarketing |
Add checkout step custom dimension | Enables more granular funnel steps |
Use DebugView extensively | Avoid silent data errors |
Track quantity and price for cart value | Useful for abandoned cart revenue estimation |
Use time-based audiences | Retarget based on cart delay (e.g., 30 mins) |
π§ͺ QA Checklist
Event | DataLayer Push | GTM Event Trigger | GA4 DebugView |
---|---|---|---|
add_to_cart |
β | β | β |
begin_checkout |
β | β | β |
purchase |
β | β | β |
checkout_step |
β (optional) | β | β |
GA4 Conversions | Tracked | Triggered | Verified |
π¦ Summary Table
Page | GA4 Event | Purpose |
---|---|---|
Product Page | add_to_cart |
User intent |
Checkout Page | begin_checkout |
Purchase intent |
Thank You Page | purchase |
Final conversion |
Intermediate Step | checkout_progress |
Step drop-off |