Meta Pixel Setup | OpsBlu Docs

Meta Pixel Setup

Install and configure Meta (Facebook) Pixel on OpenCart for advertising and conversion tracking

Overview

Meta Pixel (formerly Facebook Pixel) enables:

Prerequisites

  • Active Facebook Business Manager account
  • Meta Pixel ID (format: 15-16 digit number)
  • OpenCart admin access
  • Basic understanding of Facebook Ads Manager

Installation Methods

Premium extensions provide automated Meta Pixel integration with ecommerce events.

1. Facebook Pixel Pro by iSenseLabs

  • Automatic standard event tracking
  • Dynamic product catalogs
  • Conversion API integration
  • GDPR consent management

2. Meta Pixel & Conversions API by Opencart.Expert

Installation Steps

  1. Purchase Extension

    Visit OpenCart Marketplace
    Search: "Facebook Pixel" or "Meta Pixel"
    Purchase and download extension
    
  2. Upload to OpenCart

    Admin Panel > Extensions > Installer
    Click Upload button
    Select downloaded extension file (.ocmod.zip)
    Wait for upload confirmation
    
  3. Install Extension

    Admin Panel > Extensions > Extensions
    Select extension type: Analytics or Marketing
    Find Meta Pixel extension
    Click Install (+ icon)
    
  4. Configure Extension

    Click Edit (pencil icon)
    Enter your Meta Pixel ID
    Enable desired events
    Configure Conversions API (if supported)
    Set Status: Enabled
    Save configuration
    
  5. Refresh Modifications

    Admin Panel > Extensions > Modifications
    Click Refresh button (blue circular arrow)
    
  6. Clear Cache

    Admin Panel > Dashboard
    Click blue gear icon (top-right)
    Select cache options
    Click Clear button
    

Method 2: Manual Template Integration

For custom implementations or when extensions aren't suitable:

1. Add Base Pixel Code

File: catalog/view/theme/[your-theme]/template/common/header.twig

Add before the closing </head> tag:

{# Meta Pixel Code #}
<script>
!function(f,b,e,v,n,t,s)
{if(f.fbq)return;n=f.fbq=function(){n.callMethod?
n.callMethod.apply(n,arguments):n.queue.push(arguments)};
if(!f._fbq)f._fbq=n;n.push=n;n.loaded=!0;n.version='2.0';
n.queue=[];t=b.createElement(e);t.async=!0;
t.src=v;s=b.getElementsByTagName(e)[0];
s.parentNode.insertBefore(t,s)}(window, document,'script',
'https://connect.facebook.net/en_US/fbevents.js');
fbq('init', 'YOUR_PIXEL_ID');
fbq('track', 'PageView');
</script>
<noscript>
  <img height="1" width="1" style="display:none"
       src="https://www.facebook.com/tr?id=YOUR_PIXEL_ID&ev=PageView&noscript=1"/>
</noscript>

Replace YOUR_PIXEL_ID with your actual Pixel ID.

2. Create Configuration Setting

Store Pixel ID in OpenCart settings for easy management.

File: admin/controller/extension/analytics/facebook_pixel.php

<?php
class ControllerExtensionAnalyticsFacebookPixel extends Controller {
    private $error = array();

    public function index() {
        $this->load->language('extension/analytics/facebook_pixel');

        $this->document->setTitle($this->language->get('heading_title'));

        $this->load->model('setting/setting');

        if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validate()) {
            $this->model_setting_setting->editSetting('analytics_facebook_pixel', $this->request->post);

            $this->session->data['success'] = $this->language->get('text_success');

            $this->response->redirect($this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=analytics', true));
        }

        $data['heading_title'] = $this->language->get('heading_title');
        $data['text_edit'] = $this->language->get('text_edit');
        $data['entry_pixel_id'] = $this->language->get('entry_pixel_id');
        $data['entry_status'] = $this->language->get('entry_status');
        $data['button_save'] = $this->language->get('button_save');
        $data['button_cancel'] = $this->language->get('button_cancel');

        if (isset($this->request->post['analytics_facebook_pixel_id'])) {
            $data['analytics_facebook_pixel_id'] = $this->request->post['analytics_facebook_pixel_id'];
        } else {
            $data['analytics_facebook_pixel_id'] = $this->config->get('analytics_facebook_pixel_id');
        }

        if (isset($this->request->post['analytics_facebook_pixel_status'])) {
            $data['analytics_facebook_pixel_status'] = $this->request->post['analytics_facebook_pixel_status'];
        } else {
            $data['analytics_facebook_pixel_status'] = $this->config->get('analytics_facebook_pixel_status');
        }

        $data['action'] = $this->url->link('extension/analytics/facebook_pixel', 'user_token=' . $this->session->data['user_token'], true);
        $data['cancel'] = $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=analytics', true);

        $data['header'] = $this->load->controller('common/header');
        $data['column_left'] = $this->load->controller('common/column_left');
        $data['footer'] = $this->load->controller('common/footer');

        $this->response->setOutput($this->load->view('extension/analytics/facebook_pixel', $data));
    }

    protected function validate() {
        if (!$this->user->hasPermission('modify', 'extension/analytics/facebook_pixel')) {
            $this->error['warning'] = $this->language->get('error_permission');
        }

        if (!$this->request->post['analytics_facebook_pixel_id']) {
            $this->error['pixel_id'] = $this->language->get('error_pixel_id');
        }

        return !$this->error;
    }
}

3. Load Pixel Dynamically

File: catalog/controller/common/header.php

Add to index() method:

// Meta Pixel
if ($this->config->get('analytics_facebook_pixel_status')) {
    $data['facebook_pixel_id'] = $this->config->get('analytics_facebook_pixel_id');
} else {
    $data['facebook_pixel_id'] = '';
}

Update header.twig:

{% if facebook_pixel_id %}
{# Meta Pixel Code #}
<script>
!function(f,b,e,v,n,t,s)
{if(f.fbq)return;n=f.fbq=function(){n.callMethod?
n.callMethod.apply(n,arguments):n.queue.push(arguments)};
if(!f._fbq)f._fbq=n;n.push=n;n.loaded=!0;n.version='2.0';
n.queue=[];t=b.createElement(e);t.async=!0;
t.src=v;s=b.getElementsByTagName(e)[0];
s.parentNode.insertBefore(t,s)}(window, document,'script',
'https://connect.facebook.net/en_US/fbevents.js');
fbq('init', '{{ facebook_pixel_id }}');
fbq('track', 'PageView');
</script>
<noscript>
  <img height="1" width="1" style="display:none"
       src="https://www.facebook.com/tr?id={{ facebook_pixel_id }}&ev=PageView&noscript=1"/>
</noscript>
{% endif %}

Method 3: OCMOD Installation

Create an OCMOD for clean, update-safe installation:

File: facebook-pixel.ocmod.xml

<?xml version="1.0" encoding="utf-8"?>
<modification>
    <name>Facebook Pixel Base Code</name>
    <code>facebook_pixel</code>
    <version>1.0</version>
    <author>Your Name</author>
    <link>https://yourwebsite.com</link>

    <!-- Add Facebook Pixel to header -->
    <file path="catalog/view/theme/*/template/common/header.twig">
        <operation>
            <search><![CDATA[</head>]]></search>
            <add position="before"><![CDATA[
<!-- Meta Pixel Code -->
<script>
!function(f,b,e,v,n,t,s)
{if(f.fbq)return;n=f.fbq=function(){n.callMethod?
n.callMethod.apply(n,arguments):n.queue.push(arguments)};
if(!f._fbq)f._fbq=n;n.push=n;n.loaded=!0;n.version='2.0';
n.queue=[];t=b.createElement(e);t.async=!0;
t.src=v;s=b.getElementsByTagName(e)[0];
s.parentNode.insertBefore(t,s)}(window, document,'script',
'https://connect.facebook.net/en_US/fbevents.js');
fbq('init', 'YOUR_PIXEL_ID');
fbq('track', 'PageView');
</script>
<noscript><img height="1" width="1" style="display:none"
src="https://www.facebook.com/tr?id=YOUR_PIXEL_ID&ev=PageView&noscript=1"/></noscript>
            ]]></add>
        </operation>
    </file>
</modification>

Install:

  1. Upload via Admin Panel > Extensions > Installer
  2. Refresh modifications
  3. Clear cache

Advanced Matching

Enhance conversion attribution with customer data:

File: catalog/view/theme/[your-theme]/template/common/header.twig

<script>
{% if customer_id %}
{# Customer logged in - send advanced matching data #}
fbq('init', '{{ facebook_pixel_id }}', {
    em: '{{ customer_email|lower|hash('sha256') }}',
    fn: '{{ customer_firstname|lower|hash('sha256') }}',
    ln: '{{ customer_lastname|lower|hash('sha256') }}',
    ph: '{{ customer_telephone|hash('sha256') }}',
    external_id: '{{ customer_id }}'
});
{% else %}
{# Guest user #}
fbq('init', '{{ facebook_pixel_id }}');
{% endif %}
fbq('track', 'PageView');
</script>

Enable in controller:

File: catalog/controller/common/header.php

if ($this->customer->isLogged()) {
    $data['customer_id'] = $this->customer->getId();
    $data['customer_email'] = $this->customer->getEmail();
    $data['customer_firstname'] = $this->customer->getFirstName();
    $data['customer_lastname'] = $this->customer->getLastName();
    $data['customer_telephone'] = $this->customer->getTelephone();
} else {
    $data['customer_id'] = '';
}

Note: OpenCart doesn't have built-in hash filter. Install Twig extension or hash server-side:

$data['customer_email_hash'] = hash('sha256', strtolower($this->customer->getEmail()));

Then in template:

em: '{{ customer_email_hash }}',

Verification

1. Facebook Pixel Helper

Install Meta Pixel Helper Chrome Extension

  1. Visit your OpenCart store
  2. Click the extension icon
  3. Verify Pixel ID appears
  4. Check for PageView event
  5. Look for warnings or errors

2. Events Manager

Check in Facebook Events Manager:

Business Manager > Events Manager > [Your Pixel]
Data Sources > [Your Pixel] > Overview

Verify:

  • Pixel Status: Active
  • Recent Activity: PageView events appearing
  • Event Match Quality: Score (higher is better)

3. Test Events

Use Facebook's Test Events tool:

Events Manager > [Your Pixel] > Test Events
  1. Enter your website URL
  2. Click "Open Website"
  3. Browse your store
  4. Events appear in real-time

4. Browser Console

Check Pixel loading:

// Open browser console (F12)
console.log(typeof fbq);  // Should output: "function"
console.log(_fbq.instance.pixelsByID);  // Shows loaded pixels

Respect user privacy with consent management:

File: catalog/view/theme/[your-theme]/template/common/header.twig

<script>
// Wait for consent before initializing Pixel
function initFacebookPixel() {
    fbq('init', '{{ facebook_pixel_id }}');
    fbq('track', 'PageView');
}

// Check if consent library exists (e.g., Cookiebot, OneTrust)
{% if consent_mode %}
window.addEventListener('load', function() {
    if (typeof Cookiebot !== 'undefined') {
        if (Cookiebot.consent.marketing) {
            initFacebookPixel();
        }

        // Listen for consent changes
        window.addEventListener('CookiebotOnAccept', function() {
            if (Cookiebot.consent.marketing) {
                initFacebookPixel();
            }
        });
    } else {
        // No consent management - init immediately
        initFacebookPixel();
    }
});
{% else %}
// Consent mode disabled - init immediately
initFacebookPixel();
{% endif %}
</script>

Simple cookie-based consent:

<script>
// Check for marketing consent cookie
var marketingConsent = document.cookie.match(/marketing_consent=true/);

if (marketingConsent) {
    fbq('init', '{{ facebook_pixel_id }}');
    fbq('track', 'PageView');
}

// Function to enable when user accepts
function enableFacebookPixel() {
    document.cookie = "marketing_consent=true; path=/; max-age=31536000";
    fbq('init', '{{ facebook_pixel_id }}');
    fbq('track', 'PageView');
}
</script>

Multi-Store Configuration

For OpenCart multi-store setups:

Different Pixels Per Store

File: catalog/controller/common/header.php

// Get store-specific Pixel ID
if ($this->config->get('config_store_id')) {
    $store_id = $this->config->get('config_store_id');
    $data['facebook_pixel_id'] = $this->config->get('facebook_pixel_id_store_' . $store_id);
} else {
    // Default store
    $data['facebook_pixel_id'] = $this->config->get('facebook_pixel_id');
}

Multiple Pixels (Same Store)

Track to multiple pixels simultaneously:

<script>
fbq('init', 'PIXEL_ID_1');
fbq('init', 'PIXEL_ID_2');
fbq('track', 'PageView');
</script>

All subsequent events will fire to both pixels.

Troubleshooting

Pixel Not Loading

Problem: Meta Pixel Helper shows no pixel detected

Solutions:

  1. Check JavaScript console for errors
  2. Verify Pixel ID is correct (15-16 digits)
  3. Clear OpenCart cache
  4. Check extension status is "Enabled"
  5. Verify theme file modifications saved

PageView Not Firing

Problem: Pixel loads but PageView event doesn't fire

Solutions:

  1. Check for JavaScript errors blocking execution
  2. Verify fbq('track', 'PageView') is after fbq('init')
  3. Check consent management isn't blocking
  4. Test in incognito mode (extensions might block)

Events Not Appearing in Events Manager

Problem: Pixel Helper shows events but Events Manager doesn't

Solutions:

  1. Wait 20 minutes (Events Manager has delay)
  2. Check Test Events for real-time verification
  3. Verify Pixel isn't in "restricted" status
  4. Check for ad blockers on your test device

Duplicate Pixels

Problem: Multiple pixels detected on page

Solutions:

  1. Check for multiple extensions enabled
  2. Search theme files for additional Pixel code
  3. Review active OCMODs for duplicates
  4. Check parent theme if using child theme

Next Steps

Additional Resources