Meta Pixel (formerly Facebook Pixel) enables you to track conversions, optimize ads, and build targeted audiences for Facebook and Instagram campaigns. This guide shows you how to implement it on your CS-Cart store.
What is Meta Pixel?
Meta Pixel is a piece of code that tracks visitor actions on your CS-Cart store. It helps you:
- Track conversions from Facebook and Instagram ads
- Build custom audiences for retargeting
- Optimize ad delivery to people likely to convert
- Measure cross-device conversions
- Access detailed analytics in Meta Events Manager
Prerequisites
Before you begin:
- Admin access to your CS-Cart store
- Meta Business Manager account
- Meta Pixel created (or ability to create one)
- Your Pixel ID
Step 1: Create Meta Pixel
If you don't have a Meta Pixel yet:
- Go to Meta Events Manager
- Click Connect Data Sources
- Select Web
- Choose Meta Pixel
- Name your pixel
- Enter your website URL
- Click Continue
- Copy your Pixel ID (format: 16 digits)
Step 2: Install Meta Pixel Base Code
Method 1: Manual Installation (Recommended)
Add the Meta Pixel base code to your CS-Cart theme.
File: design/themes/[your_theme]/templates/blocks/head_scripts.tpl
{* Meta Pixel Base Code *}
{literal}
<!-- 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>
<!-- End Meta Pixel Code -->
{/literal}
Replace YOUR_PIXEL_ID with your actual 16-digit Pixel ID.
Method 2: Using Google Tag Manager (Recommended for Flexibility)
If you have GTM installed, use it to manage Meta Pixel.
In GTM:
- Go to Tags → New
- Name: "Meta Pixel - Base Code"
- Tag Type: Custom HTML
- Paste the Meta Pixel code
- Triggering: All Pages
- Click Save
- Submit and Publish the container
Benefits of using GTM:
- Easy to update without code changes
- Better testing with Preview mode
- Manage multiple pixels from one interface
Method 3: Using CS-Cart Add-on
CS-Cart's official Marketplace includes a Facebook Pixel add-on:
- Go to Add-ons → Manage add-ons → Browse all available add-ons
- Search for "Facebook Pixel" — the official add-on supports base pixel installation and standard ecommerce events (ViewContent, AddToCart, Purchase)
- Install the add-on and enter your Pixel ID in its settings
- The add-on handles base code injection and fires ecommerce events automatically based on CS-Cart's checkout flow
Step 3: Clear Cache
After installation:
- Go to Administration → Storage → Clear cache
- Select All
- Click Clear
Step 4: Verify Installation
Using Meta Pixel Helper
- Install Meta Pixel Helper Chrome extension
- Navigate to your CS-Cart store
- Click the Pixel Helper icon
- Verify your pixel is detected and firing
Successful installation shows:
Using Events Manager
- Go to Meta Events Manager
- Select your Pixel
- Click Test Events
- Enter your store URL
- Navigate your site
- Verify events appear in real-time
Check Browser Console
- Open Developer Tools (F12)
- Go to Network tab
- Filter by "facebook"
- Reload the page
- Look for requests to
facebook.com/tr
Advanced Setup Options
Advanced Matching (Recommended)
Advanced Matching improves attribution by matching website visitors to Facebook users.
fbq('init', 'YOUR_PIXEL_ID', {
em: 'email@example.com', // Email (hashed)
fn: 'john', // First name
ln: 'doe', // Last name
ph: '1234567890', // Phone number
external_id: 'user_id' // Your internal user ID
});
For CS-Cart with user data:
{if $auth.user_id}
{literal}
<script>
fbq('init', '{/literal}YOUR_PIXEL_ID{literal}', {
{/literal}
{if $user_info.email}
em: '{$user_info.email|escape:javascript}',
{/if}
{if $user_info.firstname}
fn: '{$user_info.firstname|escape:javascript|lower}',
{/if}
{if $user_info.lastname}
ln: '{$user_info.lastname|escape:javascript|lower}',
{/if}
{if $user_info.phone}
ph: '{$user_info.phone|regex_replace:"/[^0-9]/":""}',
{/if}
{literal}
external_id: '{/literal}{$auth.user_id}{literal}'
});
</script>
{/literal}
{else}
{literal}
<script>
fbq('init', 'YOUR_PIXEL_ID');
</script>
{/literal}
{/if}
Important: Ensure this complies with your privacy policy and GDPR requirements.
Automatic Advanced Matching
Enable in Meta Events Manager:
- Go to Settings → Advanced Matching
- Toggle on Automatic Advanced Matching
- Meta will automatically match common form fields
Multiple Pixels
If tracking for multiple accounts (marketplace + vendors):
// Initialize multiple pixels
fbq('init', 'MAIN_PIXEL_ID');
fbq('init', 'VENDOR_PIXEL_ID');
// Track events to both
fbq('track', 'PageView');
For CS-Cart Multi-Vendor:
{literal}
<script>
// Main marketplace pixel
fbq('init', 'MAIN_PIXEL_ID');
{/literal}
{if $company_data.company_id && $company_data.fb_pixel_id}
// Vendor-specific pixel
fbq('init', '{$company_data.fb_pixel_id}');
{/if}
{literal}
// Track to all pixels
fbq('track', 'PageView');
</script>
{/literal}
Conversion API (Server-Side Tracking)
For improved accuracy and iOS 14+ privacy changes, implement Conversions API.
Why Use Conversions API?
- Bypass browser tracking limitations (iOS 14+, ad blockers)
- Improve attribution accuracy
- Deduplicate events with browser pixel
- Better data quality
Implementation Steps
Option 1: Using CS-Cart Webhook
Create a custom add-on to send events server-side:
<?php
// File: app/addons/meta_conversions_api/func.php
use Tygh\Registry;
function fn_meta_conversions_api_place_order_post($order_id, $action, $order_status, $cart, $auth) {
if ($order_status == 'P') { // Paid status
$order_info = fn_get_order_info($order_id);
// Build Conversions API event
$event_data = [
'data' => [
[
'event_name' => 'Purchase',
'event_time' => time(),
'action_source' => 'website',
'event_source_url' => Registry::get('config.current_location'),
'user_data' => [
'em' => hash('sha256', strtolower($order_info['email'])),
'ph' => hash('sha256', preg_replace('/[^0-9]/', '', $order_info['phone'])),
'fn' => hash('sha256', strtolower($order_info['b_firstname'])),
'ln' => hash('sha256', strtolower($order_info['b_lastname'])),
'ct' => hash('sha256', strtolower($order_info['b_city'])),
'st' => hash('sha256', strtolower($order_info['b_state'])),
'zp' => hash('sha256', $order_info['b_zipcode']),
'country' => hash('sha256', strtolower($order_info['b_country'])),
],
'custom_data' => [
'currency' => $order_info['currency'],
'value' => $order_info['total'],
'content_type' => 'product',
'contents' => array_map(function($product) {
return [
'id' => $product['product_id'],
'quantity' => $product['amount'],
'item_price' => $product['price']
];
}, $order_info['products'])
],
'event_id' => 'order_' . $order_id // For deduplication
]
]
];
// Send to Meta Conversions API
$access_token = 'YOUR_CONVERSIONS_API_ACCESS_TOKEN';
$pixel_id = 'YOUR_PIXEL_ID';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://graph.facebook.com/v18.0/$pixel_id/events");
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query([
'data' => json_encode($event_data['data']),
'access_token' => $access_token
]));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
curl_close($ch);
}
}
Option 2: Using GTM Server-Side
- Set up GTM Server-Side container
- Configure Meta Conversions API tag
- Send events from CS-Cart to GTM server
- GTM forwards to Meta Conversions API
Event Deduplication
Use event_id to prevent duplicate tracking:
Browser Pixel:
fbq('track', 'Purchase', {
value: 99.99,
currency: 'USD'
}, {
eventID: 'order_12345'
});
Conversions API:
{
"event_id": "order_12345",
"event_name": "Purchase"
}
Privacy and Compliance
GDPR Compliance
Respect user consent preferences:
// Don't initialize pixel until consent is granted
function initMetaPixel() {
fbq('init', 'YOUR_PIXEL_ID');
fbq('track', 'PageView');
}
// Check CS-Cart cookie consent
if (typeof Tygh !== 'undefined' && Tygh.consent_accepted) {
initMetaPixel();
}
// Listen for consent changes
$(document).on('click', '.cm-btn-cookie-consent', function() {
if (typeof fbq === 'undefined') {
initMetaPixel();
}
});
Limited Data Use (LDU)
For California users (CCPA compliance):
fbq('dataProcessingOptions', ['LDU'], 1, 1000); // California
Revoke Consent
fbq('consent', 'revoke');
Testing Your Installation
Test Events Tool
- In Events Manager, click Test Events
- Open your CS-Cart store
- Perform actions (view product, add to cart, etc.)
- Verify events appear in Test Events
- Check for errors or warnings
Pixel Helper Diagnostics
Common issues shown in Pixel Helper:
- No Pixel Found - Installation failed
- Pixel Did Not Load - JavaScript error
- Encoded Characters - Check escaping in Smarty templates
- Duplicate Pixel - Multiple pixel codes installed
Browser Console Debugging
Enable debug mode:
// Add before fbq('init')
fbq('set', 'autoConfig', false, 'YOUR_PIXEL_ID');
fbq('set', 'debug', true);
Check console for:
- Pixel initialization
- Event firing
- Parameter values
Troubleshooting
Pixel Not Firing
Check:
- Pixel code is in
<head>section - Pixel ID is correct
- No JavaScript errors in console
- Cache is cleared
- Ad blockers disabled for testing
Events Not Tracking
Solutions:
- Verify event code syntax
- Check if events are after pixel initialization
- Ensure parameters are formatted correctly
- Test with Pixel Helper
Duplicate Events
Common causes:
- Multiple pixel installations
- Pixel code in multiple templates
- Both manual and GTM implementation
Fix:
- Remove duplicate installations
- Use only one implementation method
- Search templates for
fbq(
Advanced Matching Not Working
Verify:
- User data is available when pixel initializes
- Email is in valid format
- Names are lowercase
- Phone numbers contain only digits
- Data is properly hashed (if manually hashing)
iOS 14+ Attribution Issues
Solutions:
- Implement Conversions API
- Use Aggregated Event Measurement
- Verify domain in Business Manager
- Configure 8 priority events
Performance Optimization
Lazy Loading
For non-critical pages, lazy load Meta Pixel:
// Load pixel after page load
window.addEventListener('load', function() {
// Meta Pixel code here
});
Async Loading
Pixel loads asynchronously by default, but ensure other scripts don't block it.
Next Steps
Now that Meta Pixel is installed:
- Configure Event Tracking - Track conversions and custom events
- Set up Catalog Sales - Dynamic product ads
- Create Custom Audiences - Retargeting campaigns
- Configure Conversions API - Server-side tracking