๐Ÿ›’ GA4 Cart Abandonment & Checkout Funnel Drop-off Tracking in OpenCart

Standard

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:

  1. Tag Type: GA4 Event
  2. Use Event Name matching add_to_cart, begin_checkout, etc.
  3. Event Parameters:
    • currency, value, items
  4. Trigger:
    • Custom Event Trigger with matching name (e.g., add_to_cart)

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:

  1. add_to_cart
  2. begin_checkout
  3. 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:

  1. Include users who triggered add_to_cart
  2. AND did not trigger begin_checkout or purchase in 1 hour
  3. 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


๐Ÿ›๏ธ Leveraging Enhanced Ecommerce in GA4 for OpenCart Sales Funnel Analysis

Standard

Enhanced Ecommerce in Google Analytics 4 (GA4) allows OpenCart merchants to map every touchpoint in the customer journeyโ€”from product views to purchaseโ€”enabling powerful funnel analysis, drop-off tracking, and conversion optimization.

โœ… Benefits of Enhanced Ecommerce Funnel Tracking

Funnel Stage GA4 Event Use Case
Product View view_item Track interest in products
Cart Addition add_to_cart Detect cart abandonment
Checkout Started begin_checkout Identify checkout drop-offs
Transaction Completed purchase Conversion and revenue tracking


๐Ÿงฐ Requirements

  • OpenCart store (v3.x or later)
  • GA4 property with GTM configured
  • Access to OpenCart theme files (.twig and PHP)
  • Consent management (recommended for GDPR)


๐Ÿš€ Step-by-Step Implementation


๐Ÿ”น Step 1: Track view_item on Product Pages

In: catalog/controller/product/product.php

$product_info = $this->model_catalog_product->getProduct($this->request->get['product_id']);
$category = $this->model_catalog_category->getCategory($product_info['category_id']);

$data['gtm_view_item'] = json_encode([
'event' => 'view_item',
'ecommerce' => [
'items' => [[
'item_id' => $product_info['model'], // Match with GMC or SKU
'item_name' => $product_info['name'],
'item_category' => $category['name'],
'price' => $product_info['price'],
'currency' => $this->session->data['currency']
]]
]
]);

In: product.twig

{% if gtm_view_item %}
<script>
window.dataLayer = window.dataLayer || [];
dataLayer.push({{ gtm_view_item|raw }});
</script>
{% endif %}


๐Ÿ”น Step 2: Track add_to_cart on Cart Actions

In: 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
]]
]
]);

Then add to your cart-related Twig view:

{% if gtm_add_to_cart %}
<script>
dataLayer.push({{ gtm_add_to_cart|raw }});
</script>
{% endif %}


๐Ÿ”น Step 3: Track begin_checkout When User Proceeds to Checkout

In: 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 4: Track purchase on Order Success Page

In: catalog/controller/checkout/success.php

$order_info = $this->model_checkout_order->getOrder($this->session->data['order_id']);
$products = $this->model_checkout_order->getOrderProducts($this->session->data['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 5: Create GA4 Event Tags in GTM

In GTM:

  1. Tag Type: GA4 Event
  2. Configuration Tag: Your GA4 base config
  3. Event Name: e.g., view_item, add_to_cart, etc.
  4. Event Parameters:
    • currency, value, items

Create one tag per event and link to matching Custom Event trigger (e.g., Trigger for Event Name = view_item)


๐Ÿ”น Step 6: Enable Enhanced Ecommerce in GA4

GA4 automatically recognizes these events. However:

  1. Go to Admin โ†’ Events
  2. Verify all 4 events (view_item, add_to_cart, begin_checkout, purchase) appear
  3. Optionally mark purchase and begin_checkout as Conversions


๐Ÿ”น Step 7: Analyze in GA4 Funnel Exploration

Go to Explore โ†’ Funnel Exploration

Steps:

  1. Step 1: view_item
  2. Step 2: add_to_cart
  3. Step 3: begin_checkout
  4. Step 4: purchase

Breakdowns:

  • Item category
  • Device category
  • Source/medium

Use “Elapsed Time” and “Next Action Timing” features to identify drop-off delays.


๐Ÿง  Pro Tips

Tip Why It Matters
Always use model as item_id Ensures feed and tracking alignment
Use dynamic category names Enables richer funnel breakdowns
Create audience segments for each stage Drive re-engagement with remarketing
Validate every push in GA4 DebugView Catch silent event failures
Combine with consent mode Ensure privacy-compliance in EU/CCPA regions


๐Ÿงช QA Checklist

Step โœ…
Product page pushes view_item โœ…
Cart action pushes add_to_cart โœ…
Checkout loads begin_checkout โœ…
Order complete triggers purchase โœ…
GA4 DebugView shows all events โœ…
Funnel Exploration configured โœ…


๐Ÿ“ฆ Summary Table

Event Purpose Trigger Page
view_item Product viewed product.twig
add_to_cart Item added to cart cart.twig
begin_checkout Checkout started checkout.twig
purchase Order completed success.twig


๐Ÿš€ GA4 to Google Ads Integration: Custom Conversions in OpenCart

Standard

Integrating Google Analytics 4 (GA4) with Google Ads is a game changer for OpenCart merchants. With custom conversions, you can define your own success metrics, beyond just purchasesโ€”like form submissions, add-to-carts, or even scroll depthโ€”and import them into Google Ads for bidding and attribution.

โœ… Why Use Custom GA4 Conversions in Google Ads?

Feature Benefit
Track micro-conversions Add to cart, signup, scroll, etc.
Smarter bidding Optimize for user intent, not just purchases
Full funnel visibility Understand pre-purchase behavior
Flexible attribution Control which signals matter to Google Ads


๐Ÿงฐ Requirements

  • GA4 property configured
  • GTM web container implemented in OpenCart
  • Google Ads and GA4 linked in the same Google account
  • Event dataLayer pushes in OpenCart (e.g., add_to_cart, begin_checkout)
  • GTM setup to fire GA4 custom events


๐Ÿงฉ Example Use Case: Add-to-Cart as a Custom Conversion

Letโ€™s say we want to:

  • Send a custom add_to_cart event from OpenCart to GA4
  • Mark it as a conversion
  • Use it in Google Ads for audience building and bidding


๐Ÿ”น Step 1: Push add_to_cart to dataLayer in OpenCart

In catalog/controller/checkout/cart.php, after the product is added:

$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'], // Match Merchant Center
'item_name' => $product_info['name'],
'price' => $product_info['price'],
'quantity' => $quantity
]]
]
]);

Then in cart.twig (or output file):

{% if gtm_add_to_cart %}
<script>
window.dataLayer = window.dataLayer || [];
dataLayer.push({{ gtm_add_to_cart|raw }});
</script>
{% endif %}


๐Ÿ”น Step 2: Setup GA4 Event Tag in GTM

In Google Tag Manager:

  1. Tag Type: GA4 Event
  2. Configuration Tag: Your GA4 base config
  3. Event Name: add_to_cart (must match what you push)
  4. Event Parameters:
    • currency: {{DLV - ecommerce.currency}}
    • value: {{DLV - ecommerce.value}}
    • items: {{DLV - ecommerce.items}}
  5. Trigger:
    • Type: Custom Event
    • Event Name: add_to_cart

Create all data layer variables as needed:

  • ecommerce.currency
  • ecommerce.value
  • ecommerce.items.0.item_id, etc.

โœ… This sends the structured add_to_cart event to GA4 with all necessary parameters.


๐Ÿ”น Step 3: Verify in GA4 DebugView

  • Go to GA4 โ†’ Admin โ†’ DebugView
  • Add a product to cart
  • Confirm add_to_cart event fires with:
    • value, currency, and item_id


๐Ÿ”น Step 4: Mark the Custom Event as a Conversion in GA4

  1. In GA4 Admin โ†’ Events
  2. Locate add_to_cart in the list
  3. Toggle the Mark as Conversion switch ON

โœ… GA4 now treats this event as a conversion and can send it to Google Ads.


๐Ÿ”น Step 5: Link GA4 with Google Ads

In GA4 Admin:

  1. Go to Product Links โ†’ Google Ads
  2. Click Link and choose your Ads account
  3. Enable:
    • Personalized Advertising
    • Auto-tagging
    • Enable conversion import

โœ… GA4 events marked as conversions will now be available in Ads.


๐Ÿ”น Step 6: Import Conversions into Google Ads

  1. Go to Google Ads โ†’ Tools & Settings โ†’ Conversions
  2. Click New Conversion Action โ†’ Import โ†’ Google Analytics 4 properties (Web)
  3. Select add_to_cart or any other GA4-marked conversion
  4. Assign a value or use the one from GA4

โœ… Done! Your GA4 custom conversion is now available in Google Ads for:

  • Smart bidding
  • Audience segmentation
  • Campaign performance tracking


๐ŸŽฏ Use Cases for Custom Conversions in OpenCart

Custom Event Strategy
add_to_cart Target cart abandoners
view_item Product-based engagement
begin_checkout Pre-purchase signals
newsletter_signup Lead-gen retargeting
form_submit Micro-conversions in B2B stores


๐Ÿง  Pro Tips

  • Name events consistently in dataLayer, GTM, and GA4
  • Use transaction_id in purchase events to prevent duplicates
  • GA4 sends conversions with event timestamp, ensuring accurate attribution
  • Always test each step in GTM preview and GA4 DebugView before importing to Ads


๐Ÿงช QA Checklist

Task โœ…
add_to_cart fires in dataLayer โœ…
GA4 event tag sends event correctly โœ…
Event visible in DebugView โœ…
Event marked as conversion โœ…
Imported to Google Ads โœ…
Conversion appears in Ads reports โœ…


๐Ÿ“ฆ Summary Table

Step Description
1 Push GA4-style event into OpenCart dataLayer
2 Fire GA4 event tag in GTM
3 Mark the event as a conversion in GA4
4 Link GA4 to Google Ads
5 Import the custom event into Ads
6 Use it for bidding, targeting, and reports


๐Ÿ›’ Matching OpenCart Product Feeds with Google Ads Dynamic Remarketing Events

Standard

For effective Google Ads Dynamic Remarketing, you need to ensure that the product IDs in your OpenCart events match the product IDs in your Google Merchant Center (GMC) feed. Without a perfect match, your ads wonโ€™t show the right products or may not appear at all.

โœ… Why Matching Product IDs Matters

Element Must Match
GA4/GTM ecomm_prodid Merchant feed id
Price in GTM Feed product price (optional but recommended)
Category (optional) Helps with audience segmentation


๐Ÿงฐ Requirements

  • OpenCart store (v3.x or v4.x)
  • Google Merchant Center account and approved product feed
  • Google Ads linked to Merchant Center
  • GTM container installed on your site
  • Feed uses Product ID (SKU or model) as id field


๐Ÿš€ Step-by-Step: Match OpenCart Product Data to Merchant Center IDs


๐Ÿ”น Step 1: Decide Your Feed Identifier Strategy

Check your Google Merchant Center product feed:

  • Is the product ID the SKU?
  • Or the model number?
  • Or the OpenCart product ID?

Most feeds are set up with the model number or SKU.

๐Ÿ‘‰ Youโ€™ll need to send the same value in the ecomm_prodid for GTM dynamic remarketing.


๐Ÿ”น Step 2: Modify product.php Controller to Include Correct Product ID

Edit: catalog/controller/product/product.php

$product_id = (int)$this->request->get['product_id'];
$product_info = $this->model_catalog_product->getProduct($product_id);

$data['gtm_view_item'] = json_encode([
'event' => 'view_item',
'ecommerce' => [
'items' => [[
'id' => $product_info['model'], // Use model to match GMC feed
'name' => $product_info['name'],
'category' => 'Replace with category if available',
'price' => $product_info['price']
]]
]
]);

๐Ÿ‘‰ Replace 'model' with 'sku' if thatโ€™s what your Merchant feed uses.

โœ… This ensures the same ID is used in both feed and event.


๐Ÿ”น Step 3: Output the DataLayer Script in the Product Page

In product.twig:

{% if gtm_view_item %}
<script>
window.dataLayer = window.dataLayer || [];
dataLayer.push({{ gtm_view_item|raw }});
</script>
{% endif %}

โœ… This outputs the view_item event in a GA4/eCommerce-ready format.


๐Ÿ”น Step 4: Add the Same Product ID to Cart Events

In catalog/controller/checkout/cart.php or via AJAX response:

$data['gtm_add_to_cart'] = json_encode([
'event' => 'add_to_cart',
'ecommerce' => [
'items' => [[
'id' => $product_info['model'], // Same match as above
'name' => $product_info['name'],
'price' => $product_info['price'],
'quantity' => $quantity
]]
]
]);


๐Ÿ”น Step 5: Create GTM Variables for ID Matching

In GTM:

  1. DLV – item_id โ†’ ecommerce.items.0.id
  2. DLV – item_name โ†’ ecommerce.items.0.name
  3. DLV – item_price โ†’ ecommerce.items.0.price

โœ… Use these for dynamic remarketing and GA4 event tagging.


๐Ÿ”น Step 6: Setup Google Ads Remarketing Tag in GTM

  1. Tag Type: Google Ads Remarketing
  2. Conversion ID: From your Google Ads account
  3. Custom Parameters:

ecomm_prodid: {{DLV - item_id}},
ecomm_pagetype: 'product',
ecomm_totalvalue: {{DLV - item_price}}

  1. Trigger: Custom Event: view_item

๐Ÿ‘‰ Use different ecomm_pagetype values for cart, category, checkout, etc.


๐Ÿ”น Step 7: Validate Product Feed in Merchant Center

  1. Go to Google Merchant Center โ†’ Products โ†’ Feeds
  2. Download your product feed
  3. Confirm the id column matches the values you’re pushing as ecomm_prodid in GTM
  4. Ensure no mismatch or null values exist

โœ… If youโ€™re using GTIN or SKU as ID in the feed, use the same value in OpenCart events.


๐Ÿ”น Step 8: Test with Google Tag Assistant + GA4 DebugView

  1. Open your product page
  2. In Tag Assistant:
    • Look for view_item event
    • Confirm ecomm_prodid matches your Merchant feed
  3. In GA4 DebugView:
    • Confirm item_id equals Merchant Center product ID


๐Ÿ”„ Bonus: Output Category for Dynamic Audiences

You can add category dynamically too:

$categories = $this->model_catalog_product->getCategories($product_id);
$category_id = $categories[0]['category_id'];
$category_info = $this->model_catalog_category->getCategory($category_id);

$category_name = $category_info['name'];

And then:

'category' => $category_name

โœ… You can later segment audiences in Google Ads based on category pageviews.


๐Ÿง  Best Practices

Practice Tip
Feed ID must match OpenCart ID exactly Including case-sensitivity and format
Test real product examples Validate with Tag Assistant and live feed
Always sanitize null or invalid IDs Prevents tracking errors
Update IDs if feed structure changes Keep events and feed aligned
Add default fallback values For products missing SKU or model


๐Ÿ“ฆ Summary

Step Action
1 Verify Merchant feed ID structure (model/SKU)
2 Output same product ID in OpenCart events
3 Modify product.php and cart.php for consistency
4 Create GTM DLVs for ID, name, price
5 Configure Google Ads Remarketing tag with those values
6 Confirm match in Merchant Center
7 QA via GTM Preview and Google Tag Assistant


Dynamic Remarketing Tag Setup for OpenCart with GA4 eCommerce Data

Standard

Dynamic Remarketing allows you to show personalized ads to users based on their past interactionsโ€”like viewing a product, abandoning the cart, or checking out. For OpenCart, the most scalable way to enable this is using Google Tag Manager (GTM) with GA4 eCommerce data.

โœ… What This Setup Will Track

Event Use in Remarketing
view_item Show product-based ads
add_to_cart Retarget cart abandoners
purchase Exclude converters
view_item_list List engagement-based retargeting


๐Ÿงฐ Requirements

  • OpenCart 3.x or 4.x access
  • GA4 and GTM properly implemented
  • Google Merchant Center linked to Google Ads
  • Dynamic Remarketing feed approved
  • Google Ads tag ID (e.g., AW-123456789)
  • Product IDs in your OpenCart store match those in the Merchant Feed


๐Ÿš€ Step-by-Step: Dynamic Remarketing in OpenCart via GA4 Data


๐Ÿ”น Step 1: Format Product Data in GA4 Events

Update product and cart-related events in OpenCart to match Googleโ€™s dynamic remarketing parameters.

Example: Update catalog/controller/product/product.php

$product_id = (int)$this->request->get['product_id'];
$product_info = $this->model_catalog_product->getProduct($product_id);
$category = $this->model_catalog_category->getCategory($product_info['category_id']);

$data['gtm_view_item'] = json_encode([
'event' => 'view_item',
'ecommerce' => [
'items' => [[
'id' => $product_info['product_id'],
'name' => $product_info['name'],
'category' => $category['name'],
'price' => $product_info['price']
]]
]
]);

In product.twig:

{% if gtm_view_item %}
<script>
window.dataLayer = window.dataLayer || [];
dataLayer.push({{ gtm_view_item|raw }});
</script>
{% endif %}

โœ… This provides GA4-compliant product data that can also fuel remarketing.


๐Ÿ”น Step 2: Push Cart Events (add_to_cart, begin_checkout, etc.)

In catalog/controller/checkout/cart.php (for add_to_cart):

$data['gtm_add_to_cart'] = json_encode([
'event' => 'add_to_cart',
'ecommerce' => [
'items' => [[
'id' => $product_id,
'name' => $product_name,
'price' => $price,
'quantity' => $quantity
]]
]
]);

Then output in the response view (cart.twig or AJAX template):

{% if gtm_add_to_cart %}
<script>
dataLayer.push({{ gtm_add_to_cart|raw }});
</script>
{% endif %}


๐Ÿ”น Step 3: Create Data Layer Variables in GTM

Create GTM Data Layer Variables to access GA4 eCommerce values:

Name Key
DLV - item_id ecommerce.items.0.id
DLV - item_category ecommerce.items.0.category
DLV - item_price ecommerce.items.0.price


๐Ÿ”น Step 4: Setup Google Ads Remarketing Tag in GTM

In GTM:

  1. Go to Tags > New
  2. Tag Type: Google Ads Remarketing
  3. Enter your Google Ads Conversion ID (AW-XXXXXXXXX)
  4. Choose: Use custom parameters
  5. Enter the following key-value pairs:

ecomm_prodid: {{DLV - item_id}},
ecomm_pagetype: 'product',
ecomm_totalvalue: {{DLV - item_price}}

(For cart: pagetype = ‘cart’, for purchase: ‘purchase’)

  1. Trigger: Use Custom Event trigger for view_item


๐Ÿ”น Step 5: Create Triggers for Each Event

GTM Trigger Type Event Name
Trigger - view_item Custom Event view_item
Trigger - add_to_cart Custom Event add_to_cart
Trigger - purchase Custom Event purchase

Link each to its respective Google Ads Remarketing Tag with the correct ecomm_pagetype.


๐Ÿ”น Step 6: (Optional) Send to Google Analytics 4

You can send the same view_item, add_to_cart, and purchase events to GA4 for reporting as well. Just create GA4 Event Tags with mapped parameters like:

items: [{
item_id: {{DLV - item_id}},
item_name: {{DLV - item_name}},
item_category: {{DLV - item_category}},
price: {{DLV - item_price}}
}]


๐Ÿ”น Step 7: QA with GTM Preview and Tag Assistant

  1. Open GTM Preview mode
  2. Navigate through product, cart, and checkout pages
  3. Validate:
    • Correct event is pushed (view_item, add_to_cart, etc.)
    • Google Ads tag fires with right parameters
  4. Use Google Tag Assistant โ†’ check that the ecomm_prodid and pagetype match page context
  5. In Google Ads > Audience Manager > Data Sources, confirm tag is receiving hits


๐Ÿง  Advanced: Page-Level Dynamic Parameters

For more precise control over dynamic remarketing:

Page ecomm_pagetype
Homepage 'home'
Product page 'product'
Category 'category'
Cart 'cart'
Checkout 'checkout'
Purchase 'purchase'

Set this either in dataLayer or directly in tag parameter configuration.


๐Ÿ“ฆ Summary Table

Step Action
1 Push GA4 eCommerce-compatible product data on product pages
2 Track cart interactions using add_to_cart events
3 Create GTM Data Layer Variables for item data
4 Add Google Ads Remarketing Tag using custom parameters
5 Trigger per event type (view_item, add_to_cart, etc.)
6 QA with GTM Preview + Tag Assistant
7 Confirm tag firing in Google Ads โ†’ Audience Sources


Setting Up Google Ads Enhanced Conversions in OpenCart (with Code & GTM)

Standard

Enhanced Conversions in Google Ads enable more accurate conversion tracking by securely sending first-party customer dataโ€”like email, phone number, or nameโ€”from your OpenCart store to Google. This improves attribution, particularly for logged-in users, even if cookies are restricted.

โœ… What Are Enhanced Conversions?

Feature Benefit
Uses hashed first-party data Improves match rate & ROAS accuracy
Works with consent Privacy-compliant with consent mode
Improves attribution More complete conversion path in Ads
Supports offline conversion imports Optional advanced use case


๐Ÿงฐ Requirements

  • GTM web container installed in OpenCart
  • Google Ads conversion action already created
  • Access to OpenCart checkout success page
  • Customer data available on success page (email, phone, name)
  • Consent mode implemented (recommended)


๐Ÿš€ Step-by-Step: Setting Up Enhanced Conversions in OpenCart via GTM


๐Ÿ”น Step 1: Create or Identify Your Google Ads Conversion Action

In your Google Ads account:

  1. Go to Tools & Settings > Conversions
  2. Select your existing Purchase conversion action, or create a new one
  3. Under “Enhanced conversions”, enable enhanced conversions and select Google Tag Manager
  4. Youโ€™ll see instructions and confirmation of Enhanced Conversions being active

โœ… No new Conversion ID/Label is needed.


๐Ÿ”น Step 2: Output Customer Data to dataLayer on Thank You Page

In OpenCart, modify:

File: catalog/controller/checkout/success.php

$order_id = $this->session->data['order_id'];
$this->load->model('checkout/order');
$order_info = $this->model_checkout_order->getOrder($order_id);

$data['gtm_enhanced_conversion'] = json_encode([
'event' => 'purchase',
'email' => $order_info['email'],
'phone' => preg_replace('/\D/', '', $order_info['telephone']), // digits only
'first_name' => $order_info['firstname'],
'last_name' => $order_info['lastname'],
'country' => $order_info['payment_iso_code_2'],
'postal_code' => $order_info['payment_postcode']
]);

File: success.twig (in catalog/view/theme/YOUR_THEME/template/checkout/)

{% if gtm_enhanced_conversion %}
<script>
window.dataLayer = window.dataLayer || [];
dataLayer.push({{ gtm_enhanced_conversion|raw }});
</script>
{% endif %}

โœ… This exposes user data only on the purchase confirmation page.


๐Ÿ”น Step 3: Create GTM Data Layer Variables

In GTM:

Variable Name Type Data Layer Variable
DLV - email Data Layer Variable email
DLV - phone Data Layer Variable phone
DLV - first_name Data Layer Variable first_name
DLV - last_name Data Layer Variable last_name
DLV - country Data Layer Variable country
DLV - postal_code Data Layer Variable postal_code


๐Ÿ”น Step 4: Configure Google Ads Conversion Tag for Enhanced Conversions

In GTM:

  1. Go to Tags > New
  2. Tag Type: Google Ads Conversion Tracking
  3. Use:
    • Conversion ID: e.g. AW-123456789
    • Conversion Label: e.g. XyZAbc1234
  4. Enable Conversion Value Tracking if applicable
  5. Scroll down and enable Enhanced Conversions
  6. Choose: Use data layer
  7. Confirm GTM detects:
    • email
    • phone
    • first_name
    • last_name
    • country
    • postal_code
  8. Trigger: Use Custom Event trigger โ†’ purchase

โœ… This ensures that hashed personal data is sent securely to Google Ads when a purchase happens.


๐Ÿ”น Step 5: Add Consent Mode (Optional but Recommended)

If you’re using a Consent Management Platform (CMP) or cookie banner, configure Consent Mode v2 in GTM before any tag fires.

<script>
window.dataLayer = window.dataLayer || [];
function gtag() { dataLayer.push(arguments); }
gtag("consent", "default", {
ad_storage: "denied",
analytics_storage: "denied"
});
</script>

On consent accept:

gtag("consent", "update", {
ad_storage: "granted",
analytics_storage: "granted"
});

โœ… This keeps your implementation privacy-compliant under GDPR/CCPA.


๐Ÿ”น Step 6: Test Your Setup

  1. Open GTM Preview Mode
  2. Complete a test order on your OpenCart store
  3. Confirm:
    • purchase event fires
    • Email, phone, and name values appear in the dataLayer
    • Google Ads Conversion Tag fires
  4. In Google Ads โ†’ Conversions, check for Enhanced Conversion data within 24โ€“48 hours
  5. You can also use Chrome Tag Assistant to confirm Enhanced Conversions are active


๐Ÿง  Best Practices

Practice Why
Hashing handled by Google No need to manually hash in GTM
Send only on Thank You Page Ensures customer data is not exposed early
Use consent signals To meet legal data processing standards
Avoid hardcoding customer data Always pull from the order object dynamically
Use Timer triggers for backups Ensure tag doesnโ€™t miss on fast redirects


๐Ÿงช Troubleshooting Tips

Issue Fix
Tag not firing Ensure purchase event exists in dataLayer
Missing email Check PHP logic in success.php
Tag fires before user data available Use timer or DOM-ready trigger
Consent not granted Check CMP logic or console warnings


๐Ÿ“ฆ Summary

Step Action
1 Enable Enhanced Conversions in Google Ads
2 Push customer data to dataLayer on order confirmation
3 Create GTM Data Layer Variables
4 Configure Google Ads Tag for Enhanced Conversions
5 Add Consent Mode to stay compliant
6 QA using GTM Preview & Tag Assistant
7 Monitor in Google Ads โ†’ Conversions dashboard


Implementing Google Ads Conversion Tracking in OpenCart via GTM

Standard

To accurately measure ROI from Google Ads campaigns in your OpenCart store, it’s essential to implement conversion tracking using Google Tag Manager (GTM). When users complete a purchase, a conversion should be recorded and tied back to their ad click.

โœ… What This Implementation Tracks

Metric Description
Conversion When a purchase is completed
Conversion Value Total revenue from order
Transaction ID Unique order reference to prevent duplicates
Currency Currency used for the purchase


๐Ÿงฐ Requirements

  • OpenCart admin + FTP access
  • GTM container installed in OpenCart
  • Google Ads account with a conversion action created
  • Google Ads Conversion ID and Label
  • Basic PHP + Twig editing capability


๐Ÿš€ Step-by-Step: Google Ads Conversion Tracking in OpenCart via GTM


๐Ÿ”น Step 1: Create a Google Ads Conversion Action

  1. Go to your Google Ads account
  2. Navigate to Tools & Settings โ†’ Conversions
  3. Click + New Conversion Action
  4. Choose Website
  5. Enter conversion settings:
    • Category: Purchase
    • Conversion name: Purchase Conversion
    • Value: Use different values for each conversion
    • Count: One per conversion
    • Click-through window: 30 days
  6. Click Create and Continue
  7. Select Use Google Tag Manager
  8. Note down:
    • Conversion ID: e.g., AW-123456789
    • Conversion Label: e.g., XyZAbc1234


๐Ÿ”น Step 2: Inject Dynamic Conversion Data into dataLayer in OpenCart

Edit catalog/controller/checkout/success.php:

$order_id = $this->session->data['order_id'];
$this->load->model('checkout/order');
$order_info = $this->model_checkout_order->getOrder($order_id);

$data['google_ads_conversion'] = json_encode([
'event' => 'purchase',
'transaction_id' => $order_info['order_id'],
'value' => $order_info['total'],
'currency' => $order_info['currency_code']
]);

Now edit success.twig (usually located in catalog/view/theme/YOUR_THEME/template/checkout/):

{% if google_ads_conversion %}
<script>
window.dataLayer = window.dataLayer || [];
dataLayer.push({{ google_ads_conversion|raw }});
</script>
{% endif %}

โœ… This pushes the conversion event into the dataLayer only after a successful purchase.


๐Ÿ”น Step 3: Create GTM Data Layer Variables

In your GTM container, go to Variables โ†’ New โ†’ Data Layer Variable and create:

Name Data Layer Variable
DLV - transaction_id transaction_id
DLV - value value
DLV - currency currency


๐Ÿ”น Step 4: Create the Conversion Trigger

Go to Triggers โ†’ New

  • Trigger Type: Custom Event
  • Event Name: purchase
  • Trigger fires on: All Custom Events
  • Name it: Event - Purchase


๐Ÿ”น Step 5: Add Google Ads Conversion Tag in GTM

  1. Go to Tags โ†’ New
  2. Tag Type: Google Ads Conversion Tracking
  3. Fill in:
    • Conversion ID: from Step 1
    • Conversion Label: from Step 1
  4. Click Enable value tracking
  5. Set:
    • Conversion Value: {{DLV - value}}
    • Transaction ID: {{DLV - transaction_id}}
    • Currency Code: {{DLV - currency}}
  6. Trigger: Event - Purchase
  7. Save and name: Google Ads Conversion - Purchase

โœ… This tag fires when the purchase event is pushed to the dataLayer with value and transaction ID.


๐Ÿ”น Step 6: (Optional) Setup Enhanced Conversions via CSS Selectors

If you want to enhance conversion data using email or phone number from checkout, you can add Enhanced Conversions:

  1. In GTM, create a variable:
    • Type: DOM Element
    • Selector: input[name="email"]
    • Attribute: value
  2. In your Google Ads Conversion Tag:
    • Enable Enhanced Conversions
    • Select Email variable

This is optional but improves attribution accuracy.


๐Ÿ”น Step 7: Test Everything in GTM & GA

  1. Enable GTM Preview Mode
  2. Place a test order in your OpenCart store
  3. Confirm the purchase event appears in Preview mode
  4. Confirm Google Ads Conversion Tag fires
  5. Use Google Tag Assistant to validate tag
  6. In Google Ads โ†’ Conversions โ†’ Status: check for incoming conversions within 24 hours


๐Ÿ”„ Optional: Deduplicate Conversion Events in GA4 + Google Ads

If youโ€™re also sending purchase data to GA4 and importing conversions, deduplicate using:

  • Matching transaction_id
  • Mark one conversion source as primary


๐Ÿ“Š Summary Table

Step Action
1 Create conversion in Google Ads
2 Inject conversion data in dataLayer on success page
3 Create GTM variables for transaction_id, value, currency
4 Add custom event trigger for purchase
5 Configure Google Ads conversion tag with dynamic values
6 (Optional) Add Enhanced Conversions
7 Test with Tag Assistant and debug tools


Setting Up Scroll & Engagement Tracking in GA4 for Product Pages

Standard

In todayโ€™s eCommerce experience, scroll behavior and engagement are strong indicators of product interest and purchase intent. Google Analytics 4 (GA4) provides automatic engagement metrics, but to unlock page-specific scroll depth tracking and custom engagement events on product pages, you need to enhance your implementation using Google Tag Manager (GTM).

โœ… Why Track Scroll & Engagement?

Insight Action
Users scroll <50% Optimize page layout/above-the-fold content
High scroll + no add to cart Add urgency or testimonials
Scroll 100% = high interest Trigger retargeting or lead gen
Monitor drop-off zones A/B test product placement and page length


๐Ÿงฐ Prerequisites

  • Google Tag Manager (Web) container installed
  • GA4 property with measurement ID
  • Product detail page structure (HTML access or platform like OpenCart)
  • jQuery or vanilla JavaScript availability


๐Ÿš€ Step-by-Step Implementation: Scroll + Engagement in GA4


๐Ÿ”น Step 1: Enable GA4 Enhanced Measurement (Optional)

In GA4:

  • Go to Admin โ†’ Data Streams โ†’ Web
  • Under Enhanced Measurement, make sure Scrolls is enabled
    โœ… This tracks when a user reaches 90% scroll depth, but lacks mid-point detail.

To get 50%, 25%, and custom thresholds, follow the next steps.


๐Ÿ”น Step 2: Create a Scroll Depth Trigger in GTM

In GTM:

  1. Go to Triggers > New
  2. Choose Scroll Depth
  3. Select:
    • Vertical Scroll Depths: 25, 50, 75, 100
    • Trigger on Pages: Page Path contains /product/ (or your product URL pattern)
  4. Name it: Scroll Depth - Product Page

โœ… This detects % of page viewed.


๐Ÿ”น Step 3: Create GA4 Scroll Event Tag

In GTM:

  1. Go to Tags > New
  2. Tag Type: GA4 Event
  3. Configuration Tag: Select your GA4 config tag
  4. Event Name: scroll_depth
  5. Parameters:
    • percent_scrolled: {{Scroll Depth Threshold}}
    • page_path: {{Page Path}}
    • item_id or product_name: if available from dataLayer or meta tag
  6. Trigger: Scroll Depth - Product Page

โœ… Youโ€™ll now capture granular scroll behavior across product pages.


๐Ÿ”น Step 4: Push product_id or item_name into dataLayer

In OpenCart or your eCommerce platform, modify the product page:

In product.twig:

<script>
window.dataLayer = window.dataLayer || [];
dataLayer.push({
event: 'product_page_view',
item_id: '{{ product_id }}',
item_name: '{{ product_name }}'
});
</script>

Then create Data Layer Variables:

Variable Name Data Layer Key
item_id item_id
item_name item_name

โœ… Use these in your scroll tag parameters to bind engagement with products.


๐Ÿ”น Step 5: Add Engagement Trigger (Time on Page)

To track user engagement beyond scroll, set up:

Trigger: Timer

  1. Type: Timer Trigger
  2. Interval: 15000 (15 seconds)
  3. Limit: 1
  4. Trigger on Product Pages Only:
    • Condition: Page Path contains /product/

GA4 Tag:

  • Event Name: product_engagement
  • Parameters:
    • item_id: {{item_id}}
    • engaged_time_ms: 15000

โœ… You now track time-based engagement independent of scroll.


๐Ÿ”น Step 6: (Optional) Track Key Element Views

To track if users see specific product features like reviews, FAQs, or shipping info, use GTMโ€™s Element Visibility trigger.

Trigger: Element Visibility

  1. Selection Method: ID or CSS Selector
  2. Example: #product-review, .product-faq
  3. Minimum Percent Visible: 50%
  4. Set as: Once per page
  5. Condition: Product page URL match

GA4 Tag:

  • Event Name: section_viewed
  • Parameters:
    • section_name: "product_reviews"
    • item_id: {{item_id}}

Repeat for:

  • section_name: product_faq, size_guide, related_items

โœ… This gives a micro-view into which product features hold attention.


๐Ÿ”น Step 7: QA with GTM Preview & GA4 DebugView

  • Go to GTM Preview and load a product page
  • Scroll to various thresholds (25%, 50%, etc.)
  • Validate event firing in Preview Summary
  • Open GA4 โ†’ Admin โ†’ DebugView to ensure scroll_depth and product_engagement events appear with correct parameters


๐Ÿง  Advanced Use Cases

Use Case GA4 Event Parameters
Segment users who scroll 100% but don’t purchase scroll_depth = 100% item_id, page_path
Trigger retargeting for long-scrollers product_engagement time > 30s
Analyze which sections improve add-to-cart rate section_viewed โ†’ correlated with add_to_cart ย 
Create audiences Users who scroll 75%+ but bounce ย 


๐Ÿงช Reporting in GA4

Use Explore โ†’ Free Form:

  • Rows: item_id, percent_scrolled
  • Metrics: engagement time, scroll_depth, purchase
  • Filters: event_name = scroll_depth OR product_engagement


๐Ÿ“ฆ Summary Table

Step Action
1 Enable GA4 scroll (optional)
2 Create 25โ€“100% scroll trigger in GTM
3 Fire GA4 scroll_depth event
4 Push product info to dataLayer
5 Add time-based engagement event
6 Track section visibility (e.g., reviews)
7 QA with GTM Preview and GA4 DebugView
8 Analyze with GA4 Explore or build audiences


Using GTM Lookup Tables to Handle Product Variants & Categories in OpenCart

Standard

In OpenCart, products often come in variants (like size or color), and belong to nested categories. For granular insights in Google Analytics 4 (GA4), your tracking should capture and report these dynamically.

Using Google Tag Manager (GTM) Lookup Tables, we can normalize raw data from OpenCart (like internal category IDs or variant slugs) into human-readable, GA4-optimized valuesโ€”without hardcoding in PHP.

โœ… Why Use GTM Lookup Tables?

Problem Solution
Variant codes (e.g. color=12) Map to Red, Blue, etc. in GTM
Category IDs (e.g. cat_002) Normalize to readable names
Reduce PHP logic Decouple category mapping from server code
Update mappings without code deployment Update directly in GTM


๐Ÿงฐ Prerequisites

  • OpenCart 3.x or 4.x
  • Web GTM container installed and working
  • GA4 Configuration Tag setup
  • Product and category IDs available in your OpenCart database
  • Basic access to modify .twig and PHP controller files


๐Ÿ”น Step 1: Capture Product Variant & Category Data in dataLayer

In catalog/controller/product/product.php:

$product_id = (int)$this->request->get['product_id'];
$product_info = $this->model_catalog_product->getProduct($product_id);
$options = $this->model_catalog_product->getProductOptions($product_id);
$categories = $this->model_catalog_product->getCategories($product_id);

// Flatten category ID list
$category_ids = array_column($categories, 'category_id');

$data['gtm_view_item'] = json_encode([
'event' => 'view_item',
'ecommerce' => [
'currency' => $this->session->data['currency'],
'value' => $product_info['price'],
'items' => [[
'item_id' => $product_info['product_id'],
'item_name' => $product_info['name'],
'price' => $product_info['price'],
'variant_id' => isset($this->request->get['variant']) ? $this->request->get['variant'] : '',
'category_id' => !empty($category_ids) ? $category_ids[0] : ''
]]
]
]);

In product.twig:

{% if gtm_view_item %}
<script>
window.dataLayer = window.dataLayer || [];
dataLayer.push({{ gtm_view_item|raw }});
</script>
{% endif %}

โœ… You now have variant_id and category_id in the dataLayer.


๐Ÿ”น Step 2: Create Data Layer Variables in GTM

Variable Name Type Data Layer Key
DLV - variant_id Data Layer Variable ecommerce.items.0.variant_id
DLV - category_id Data Layer Variable ecommerce.items.0.category_id


๐Ÿ”น Step 3: Create Lookup Table for Variants

In GTM:

  1. Variable Type: Lookup Table
  2. Input Variable: DLV - variant_id
  3. Map Examples:

Input Output
12 Red
13 Blue
14 Green

  1. Name it: Lookup - Variant Label

Repeat this for categories:

Input Output
5 Shoes
7 Electronics > Cameras
12 Clothing > Men > Shirts

Name it: Lookup - Category Path


๐Ÿ”น Step 4: Update GA4 view_item Tag in GTM

  1. Create GA4 Event Tag: view_item
  2. Event Parameters:

Parameter Value
item_id {{ecommerce.items.0.item_id}}
item_name {{ecommerce.items.0.item_name}}
price {{ecommerce.items.0.price}}
variant {{Lookup - Variant Label}}
item_category {{Lookup - Category Path}}

โœ… You now report clean, readable variant/category values to GA4.


๐Ÿ”น Step 5: (Optional) Add Variant Selection Click Tracking

In GTM:

  • Trigger: Click โ†’ CSS Selector .product-option select
  • Tag: GA4 Event select_item
    • variant_id: {{Click Element}}.value
    • Use another lookup table to resolve variant label

dataLayer.push({
event: 'select_item',
variant_id: this.value
});

โœ… This helps analyze which variants users engage with most before purchase.


๐Ÿ”น Step 6: Reporting in GA4

Go to GA4 โ†’ Explore:

  • Use item_category, variant, item_id as dimensions
  • Use view_item, add_to_cart, purchase as metrics
  • Build a funnel comparison: Variant engagement โ†’ Purchase rate


๐Ÿ” Bonus: Keep Lookup Tables Future-Proof

  • Use default value like “Unknown” to prevent data loss
  • Update only in GTM without changing code
  • For >50 mappings, consider using GTM custom templates or BigQuery JOINs


๐Ÿงช Debug & QA

  • Open product page and inspect dataLayer
  • In GTM Preview, confirm Lookup - Variant Label resolves correctly
  • Use GA4 DebugView to validate correct values for variant/category


๐Ÿง  Summary

Step Action
1 Push variant_id and category_id to dataLayer
2 Create GTM variables for raw values
3 Build Lookup Tables for clean labels
4 Use Lookup outputs in GA4 Event Tags
5 Track clicks for variant selection (optional)
6 Report on variant/category performance in GA4
7 Maintain mappings easily inside GTM


Custom Dimensions & Metrics in GA4 for OpenCart Performance Analysis

Standard

While Google Analytics 4 (GA4) provides a powerful foundation for eCommerce tracking, relying solely on default dimensions and metrics can limit your insight into store performance, customer behavior, and marketing ROI.

To unlock deeper, customized analysis in OpenCart, you should configure Custom Dimensions and Metrics in GA4. With the flexibility of Google Tag Manager (GTM) and OpenCartโ€™s PHP-based architecture, you can pass dynamic store-specific values like user type, SKU margin, discount source, or payment method.

๐ŸŽฏ What Youโ€™ll Achieve

Type Examples
Custom Dimensions User type, shipping method, product brand, coupon source
Custom Metrics Product margin, return rate, shipping cost, loyalty points


๐Ÿงฐ Prerequisites

  • OpenCart Admin access
  • GTM Web container installed
  • GA4 property created
  • Ability to modify OpenCart PHP & Twig templates
  • Optional: Server-Side GTM for extended privacy control


๐Ÿš€ Step-by-Step: Implementing Custom Dimensions & Metrics in OpenCart


๐Ÿ”น Step 1: Identify Data Points to Send

Decide what store-specific attributes are useful for performance segmentation.

Name Type Scope Use Case
user_type Dimension user Compare guest vs. logged-in behavior
brand Dimension item Filter by brand performance
shipping_cost Metric event Understand true revenue
product_margin Metric item Analyze profitability by product


๐Ÿ”น Step 2: Create Custom Dimensions & Metrics in GA4

In GA4 Admin โ†’ Custom definitions:

Create Custom Dimensions:

Name Scope Parameter Name
User Type User user_type
Brand Item brand

Create Custom Metrics:

Name Scope Parameter Name Unit
Shipping Cost Event shipping_cost Currency
Product Margin Item product_margin Currency

โœ… These definitions must match exact parameter names used in GTM.


๐Ÿ”น Step 3: Inject Data from OpenCart Backend

Example 1: Add user_type on all pages

In catalog/controller/common/header.php:

$data['user_type'] = $this->customer->isLogged() ? 'logged_in' : 'guest';

In header.twig:

<script>
window.dataLayer = window.dataLayer || [];
dataLayer.push({
user_type: '{{ user_type }}'
});
</script>


Example 2: Add brand and product_margin to product pages

In catalog/controller/product/product.php:

$data['gtm_product_details'] = json_encode([
'event' => 'view_item',
'ecommerce' => [
'currency' => $this->session->data['currency'],
'value' => $product_info['price'],
'items' => [[
'item_id' => $product_info['product_id'],
'item_name' => $product_info['name'],
'price' => $product_info['price'],
'brand' => $product_info['manufacturer'], // Custom Dimension
'product_margin' => $product_info['price'] - $product_info['cost'] // Custom Metric
]]
]
]);

In product.twig:

{% if gtm_product_details %}
<script>
dataLayer.push({{ gtm_product_details|raw }});
</script>
{% endif %}

โœ… This enriches view_item events with brand and margin data.


๐Ÿ”น Step 4: Push Custom Metrics on Purchase Event

In checkout/success.php:

$items = [];
foreach ($order_products as $product) {
$items[] = [
'item_id' => $product['product_id'],
'item_name' => $product['name'],
'price' => $product['price'],
'quantity' => $product['quantity'],
'brand' => $product['model'],
'product_margin' => $product['price'] - 10 // Use real cost field if available
];
}

$data['gtm_purchase'] = json_encode([
'event' => 'purchase',
'ecommerce' => [
'transaction_id' => $order_info['order_id'],
'value' => $order_info['total'],
'currency' => $order_info['currency_code'],
'shipping_cost' => $order_info['shipping'], // Custom Metric
'items' => $items
]
]);

In success.twig:

{% if gtm_purchase %}
<script>
dataLayer.push({{ gtm_purchase|raw }});
</script>
{% endif %}


๐Ÿ”น Step 5: Create GTM Variables

In GTM Web Container:

  1. Data Layer Variables:

Name Variable Scope
DLV - user_type user_type User
DLV - brand ecommerce.items.0.brand Item
DLV - product_margin ecommerce.items.0.product_margin Item
DLV - shipping_cost ecommerce.shipping_cost Event


๐Ÿ”น Step 6: Configure GA4 Tags with Custom Parameters

Example: GA4 Event Tag for view_item

  • Event Name: view_item
  • Parameters:
    • currency: {{DLV - ecommerce.currency}}
    • value: {{DLV - ecommerce.value}}
    • items: {{DLV - ecommerce.items}}
  • Custom Parameters:
    • brand: {{DLV - brand}}
    • product_margin: {{DLV - product_margin}}

โœ… Repeat similar logic for add_to_cart, purchase, etc.


๐Ÿ”น Step 7: Use Custom Dimensions & Metrics in GA4 Reports

In GA4 Explore โ†’ Free Form / Funnel:

  • Add custom dimension: brand or user_type
  • Use metrics like product_margin or shipping_cost
  • Segment users by login state or high-margin product buyers
  • Build comparison between logged-in vs guest conversion rates


๐Ÿ”น Step 8: Consent-Safe Data Collection (Optional)

Only push custom metrics if consent is granted:

{% if consent_analytics %}
<script>
dataLayer.push({
user_type: '{{ user_type }}'
});
</script>
{% endif %}

Use CMP or cookie-based consent control.


๐Ÿ“Š Reporting Use Cases with Custom Dimensions/Metrics

Use Case Dimensions Metrics
Track guest vs. logged-in conversion rate user_type purchase count
Compare margin vs revenue by product brand product_margin, revenue
Analyze shipping cost impact on abandonment shipping_cost begin_checkout, purchase
Segment product performance by brand brand items purchased, revenue


๐Ÿงช Testing & Debugging

  • Use GTM Preview Mode
  • Check dataLayer values via browser console
  • Use GA4 DebugView to validate parameter transmission
  • Validate metrics appear in Explore under custom dimensions


๐Ÿ“ฆ Summary Table

Step Action
1 Choose dimensions/metrics aligned with business goals
2 Register them in GA4 Custom Definitions
3 Extract values dynamically in PHP
4 Inject into dataLayer via Twig
5 Create DLVs in GTM
6 Map them to GA4 Event Tags
7 Use in Explore, Funnels, and Audience reports
8 QA with GTM Preview and GA4 DebugView