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)
- Go to GTM β New Tag β Custom HTML
- 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
- Use the Facebook Conversions API Template
- Tag Settings:
Field | Value |
---|---|
Pixel ID | YOUR_PIXEL_ID |
Access Token | From Meta Events Manager |
Event Name | Purchase |
Event ID | {{event_id}} |
{{email}} |
|
Phone | {{phone}} |
Value | {{value}} |
Currency | {{currency}} |
Content IDs | {{content_ids}} |
Transaction ID | {{transaction_id}} |
Action Source | website |
- 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]