Facebook Ads Enhanced Conversion Tracking Strategy in OpenCart (Web + Server-Side GTM)

Standard

Enhanced Conversions for Facebook Ads is essential in today’s privacy-constrained ad environment. By sending hashed first-party data (email, phone, name) alongside your conversions, you dramatically improve match rates and campaign performanceβ€”even with limited browser-based tracking.

🧰 Prerequisites

Item Requirement
Facebook Pixel & CAPI Access From Facebook Events Manager
OpenCart 3.x / 4.x With theme & controller access
Web + Server GTM Installed GTM snippet in OpenCart header
HTTPS Active For privacy compliance
Consent Mode (Optional) For GDPR/CCPA use cases


πŸ” What Are Enhanced Conversions?

Enhanced conversions send hashed customer data (e.g. email, phone) alongside the purchase event to Facebookβ€”either via Pixel or CAPI. This helps Facebook match the event to real users, even if cookies are blocked.

βœ… We’ll implement both Web Pixel and Server-Side CAPI for reliable deduplication.


πŸ›’ Step 1: Capture Purchase + Customer Data in OpenCart

Edit: catalog/controller/checkout/success.php

Add this PHP logic:

$order_id = $this->session->data['order_id'];
$order_info = $this->model_checkout_order->getOrder($order_id);
$products = $this->model_checkout_order->getOrderProducts($order_id);

$email = strtolower(trim($order_info['email']));
$phone = preg_replace('/\D/', '', $order_info['telephone']);

$items = [];
foreach ($products as $product) {
$items[] = [
'id' => $product['model'],
'name' => $product['name'],
'quantity' => $product['quantity'],
'price' => $product['price']
];
}

$data['fb_enhanced'] = json_encode([
'event' => 'fb_purchase',
'email' => hash('sha256', $email),
'phone' => hash('sha256', $phone),
'value' => $order_info['total'],
'currency' => $order_info['currency_code'],
'transaction_id' => $order_info['order_id'],
'content_ids' => array_column($items, 'id'),
'content_type' => 'product',
'event_id' => uniqid('fb_', true)
]);


πŸ“¦ Step 2: Push Data to Web GTM on Success Page

Edit: catalog/view/theme/*/template/checkout/success.twig

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

βœ… Now GTM has access to all hashed user data + transaction ID.


🎯 Step 3: Setup Facebook Pixel with Enhanced Conversions (Web GTM)

  1. Go to GTM β†’ New Tag β†’ Custom HTML
  2. Use the following code for the Purchase Event:

<script>
fbq('track', 'Purchase', {
value: {{DL - value}},
currency: '{{DL - currency}}',
content_ids: {{DL - content_ids}},
content_type: 'product'
}, {
eventID: '{{DL - event_id}}'
});

fbq('init', 'YOUR_PIXEL_ID', {
em: '{{DL - email}}',
ph: '{{DL - phone}}'
});
</script>

Trigger: Custom Event = fb_purchase

βœ… This sends both purchase and enhanced data to Meta.


πŸ›°οΈ Step 4: Forward to Server-Side GTM (Optional)

To strengthen tracking even further, forward this data to your Server GTM container:

<script>
fetch('https://gtm.yoursite.com/event', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
event_name: 'Purchase',
event_id: '{{DL - event_id}}',
email: '{{DL - email}}',
phone: '{{DL - phone}}',
value: '{{DL - value}}',
currency: '{{DL - currency}}',
transaction_id: '{{DL - transaction_id}}',
content_ids: {{DL - content_ids}},
content_type: 'product',
action_source: 'website'
})
});
</script>


🌐 Step 5: Configure Facebook CAPI Tag in Server-Side GTM

  1. Use the Facebook Conversions API Template
  2. Tag Settings:

Field Value
Pixel ID YOUR_PIXEL_ID
Access Token From Meta Events Manager
Event Name Purchase
Event ID {{event_id}}
Email {{email}}
Phone {{phone}}
Value {{value}}
Currency {{currency}}
Content IDs {{content_ids}}
Transaction ID {{transaction_id}}
Action Source website

  1. Trigger: Event Name equals Purchase


πŸ” Step 6: Deduplicate Client & Server Events

To avoid duplicate events in Meta:

  • Use identical event_id for both Pixel and CAPI
  • Meta will deduplicate automatically


πŸ§ͺ Step 7: QA and Testing

Tool Purpose
Facebook Test Events Tool Debug CAPI/Pixels
Server GTM Preview Mode Verify request payload
Chrome DevTools β†’ Network Check event firing
Meta Events Manager Review deduplication success


βœ… Tips for Optimization

Tip Benefit
SHA256 hash in PHP More secure than client-side hashing
Use event_id for deduplication Accurate reporting
Add fbc and fbp cookies in fetch payload Further matching accuracy
Implement consent checks if needed Compliant with GDPR/CCPA


πŸ“Š Performance Impact

Metric Before EC After EC
Match Rate ~40–60% 80–95%
Conversion Accuracy Low (cookies only) High (cookies + hashed PII)
Attribution Lag Higher Lower
Retargeting Unreliable More precise


πŸ“¦ Architecture Overview

[OpenCart Checkout Success]
↓
[dataLayer Push β†’ GTM Web]
↓ β†˜
[Pixel with EC] [Forwarded to ssGTM]
↓
[Facebook Conversions API]


Leave a Reply

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