Back to Guides
Guide
12 min read

How to Set Up Facebook Pixel on Shopify

Facebook Pixel is essential for tracking conversions and building retargeting audiences. This guide covers everything from basic installation to advanced Conversions API setup.

Flex Commerce Team
Updated February 2024

What is Facebook Pixel?

Facebook Pixel (now officially called Meta Pixel) is a piece of JavaScript code that you install on your Shopify store to track visitor behaviour and conversions. It acts as a bridge between your store and Meta's advertising platform, enabling powerful tracking and optimisation capabilities.

When someone visits your store after clicking a Facebook or Instagram ad, the Pixel records their actions. Did they view a product? Add something to cart? Complete a purchase? This data flows back to Meta, allowing the platform to optimise your ad delivery and show ads to people most likely to convert.

Key Capabilities

  • Conversion tracking - See which ads drive actual sales, not just clicks
  • Audience building - Create custom audiences based on site behaviour
  • Dynamic ads - Show personalised product ads to past visitors
  • Optimisation - Let Meta find more customers like your buyers

Without the Pixel, you're flying blind. You might know that your ads generated clicks, but you won't know which campaigns actually drove revenue. The Pixel closes this loop and makes your advertising measurable.

Why You Need It

If you're spending money on Facebook or Instagram ads (or planning to), the Pixel isn't optional. It's the foundation of effective Meta advertising. Here's why it matters so much:

Accurate Attribution

The customer journey is rarely linear. Someone might see your ad on Monday, visit your site on Wednesday, and purchase on Friday from their laptop. Without proper tracking, that sale looks organic when it was actually driven by your ad. The Pixel connects these touchpoints, giving you accurate data on what's working.

Better Ad Performance

Meta's algorithm is remarkably good at finding people likely to take action, but it needs data to learn. The more conversion data your Pixel sends, the better Meta becomes at targeting. Stores with well-configured Pixels typically see 20-30% better ROAS (Return on Ad Spend) compared to those with basic setups.

Retargeting Capabilities

Retargeting is one of the highest-converting ad strategies available. The Pixel enables you to show ads to people who:

  • Viewed specific products but didn't purchase
  • Added items to cart but abandoned checkout
  • Purchased in the past and might buy again
  • Spent significant time browsing your collections

Pro Tip

Install your Pixel even if you're not running ads yet. It starts collecting audience data immediately, so when you do start advertising, you'll have a warm audience ready to target.

Creating Your Pixel

Before connecting to Shopify, you need a Facebook Pixel. If you already have one, skip to the next section. Here's how to create a new Pixel:

  1. 1
    Go to Meta Events Manager

    Visit business.facebook.com and navigate to Events Manager from the menu. You'll need a Business Manager account. If you don't have one, create it first.

  2. 2
    Connect a new data source

    Click the green "Connect Data Sources" button. Select "Web" as your data source type, then choose "Meta Pixel" and click Connect.

  3. 3
    Name your Pixel

    Give your Pixel a clear name, typically your store name. You can only have one Pixel per website, so name it accordingly.

  4. 4
    Enter your website URL

    Add your Shopify store URL (your myshopify.com domain or custom domain). Meta will check if easy setup options are available.

  5. 5
    Copy your Pixel ID

    Once created, you'll see your Pixel ID. It's a 15-16 digit number. Copy this, as you'll need it for the Shopify integration.

Finding an Existing Pixel ID

If you already have a Pixel, find its ID in Events Manager. Click on your Pixel name, then look in the top-left corner or click Settings. The ID appears as a long number like 123456789012345.

You can also find it in your ad account under Settings, then Data Sources, then Pixels.

Shopify Integration

Shopify has a native Facebook integration that makes Pixel setup straightforward. This is the recommended approach, as it handles all standard ecommerce events automatically.

Method 1: Facebook & Instagram Sales Channel (Recommended)

  1. 1
    Install the Facebook & Instagram app

    In your Shopify admin, go to Sales Channels and click the + button. Find "Facebook & Instagram" and install it. This is Shopify's official integration maintained by Meta.

  2. 2
    Connect your Facebook account

    Click "Start setup" and log in with your Facebook account. Make sure you use an account that has admin access to your Business Manager.

  3. 3
    Select your Business Manager

    Choose the Business Manager that contains your Pixel and ad account. If you have multiple, select the correct one.

  4. 4
    Connect your Pixel

    The setup wizard will show available Pixels. Select yours or create a new one. The integration will automatically install the Pixel on all pages.

  5. 5
    Enable data sharing

    Choose your data sharing level. "Maximum" sends the most data including customer email and phone for better matching. This requires compliant privacy policies.

Method 2: Manual Installation (Alternative)

If you can't use the sales channel or need more control, you can add the Pixel code directly to your theme. This is less ideal but sometimes necessary.

<!-- Add this to theme.liquid before </head> -->
<!-- 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_HERE');
fbq('track', 'PageView');
</script>
<noscript><img height="1" width="1" style="display:none"
src="https://www.facebook.com/tr?id=YOUR_PIXEL_ID_HERE&ev=PageView&noscript=1"
/></noscript>
<!-- End Meta Pixel Code -->

Pro Tip

The sales channel method is strongly recommended. It automatically tracks all standard ecommerce events (ViewContent, AddToCart, InitiateCheckout, Purchase) without additional code. Manual installation requires setting up each event separately.

Verifying Installation

After setup, verify that your Pixel is working correctly. A broken Pixel means wasted ad spend and inaccurate data. Use these methods to confirm everything is firing properly.

Meta Pixel Helper Chrome Extension

This free Chrome extension is the quickest way to check your Pixel. Install it from the Chrome Web Store, then visit your store.

  • The extension icon shows a number indicating how many Pixels are on the page
  • Click it to see which events fired (PageView, ViewContent, etc.)
  • Green checkmarks mean events fired successfully
  • Warnings or errors appear if something's wrong

Test Events in Events Manager

For a more thorough test, use Meta's Test Events feature:

  1. 1.Go to Events Manager and select your Pixel
  2. 2.Click the "Test Events" tab
  3. 3.Enter your website URL and click "Open Website"
  4. 4.Browse your store and complete actions (view products, add to cart)
  5. 5.Return to Events Manager to see events appearing in real time

Events to Verify

  • PageView - Fires on every page load
  • ViewContent - Fires on product pages
  • AddToCart - Fires when adding to cart
  • InitiateCheckout - Fires when starting checkout
  • Purchase - Fires on order confirmation (test with a real order)

Conversions API Setup

The Conversions API (CAPI) sends event data directly from your server to Meta, bypassing the browser. This is crucial because browser-based tracking is becoming less reliable due to ad blockers, iOS privacy changes, and cookie restrictions.

With CAPI, you're sending data through two channels: the browser Pixel and your server. Meta deduplicates these events, so you don't double-count conversions. The result is more complete data and better ad optimisation.

Enabling CAPI in Shopify

If you're using the Facebook & Instagram sales channel, CAPI is built in. Here's how to ensure it's enabled:

  1. 1.Go to your Facebook & Instagram sales channel in Shopify
  2. 2.Click Settings, then Data sharing settings
  3. 3.Ensure "Enable customer data sharing" is on
  4. 4.Select "Maximum" for the most complete server-side tracking

Data Sharing Levels

  • Standard - Basic browser Pixel tracking only
  • Enhanced - Adds CAPI with basic customer data
  • Maximum - Full CAPI with email and phone for best matching

Pro Tip

Using "Maximum" data sharing with CAPI typically improves event match quality by 20-40%. This directly impacts how well Meta can optimise your campaigns. Ensure your privacy policy covers this data sharing.

Custom Events

While the Shopify integration handles standard ecommerce events, you might want to track additional actions specific to your business. Custom events let you track anything meaningful.

Common Custom Events for Shopify

  • QuizCompleted - Product finder or quiz completion
  • NewsletterSignup - Email list subscription
  • WishlistAdd - Adding to a wishlist
  • StoreLocator - Using store finder feature
  • ReviewSubmitted - Leaving a product review

Adding Custom Events

To track a custom event, call the fbq function when the action occurs:

// Track a newsletter signup
fbq('track', 'NewsletterSignup', {
  value: 0,
  currency: 'GBP'
});

// Track a quiz completion
fbq('track', 'QuizCompleted', {
  quiz_name: 'Skin Type Finder',
  result: 'Dry Skin'
});

// Track a wishlist addition
fbq('track', 'WishlistAdd', {
  content_name: 'Product Name',
  content_ids: ['SKU123'],
  value: 29.99,
  currency: 'GBP'
});

Custom events appear in Events Manager and can be used for audience building and campaign optimisation just like standard events.

Best Practices for Custom Events

  • Use PascalCase for event names (e.g., QuizCompleted not quiz_completed)
  • Include relevant parameters like value, currency, content_ids
  • Test thoroughly using the Pixel Helper before launching campaigns
  • Document your custom events for your team

Troubleshooting

Pixel issues are common, but most have straightforward solutions. Here are the problems we see most frequently and how to fix them.

Pixel Not Firing at All

If the Pixel Helper shows no Pixel on your site:

  • Verify the sales channel is connected and not paused
  • Check that the correct Pixel ID is selected in settings
  • Clear your browser cache and try again
  • Disable ad blockers temporarily

Duplicate Pixels Firing

Multiple PageView events or duplicate Pixel IDs indicate double installation:

  • Check for manual Pixel code in theme.liquid
  • Look for other Facebook apps that might add their own tracking
  • Remove duplicate code, keep only the sales channel version

Purchase Events Not Tracking

Conversions not appearing in Events Manager:

  • Wait 24-48 hours for data to process
  • Verify with a test purchase (you can refund it)
  • Check that Shopify checkout isn't using a third-party system
  • Ensure CAPI is enabled for server-side tracking

Low Event Match Quality

Events Manager shows "Poor" or "OK" match quality:

  • Enable "Maximum" data sharing in the sales channel
  • Ensure CAPI is sending customer email and phone
  • Encourage customers to log in before purchasing

Need Help With Tracking?

Our team can set up Facebook Pixel, Conversions API, and all your marketing integrations for accurate attribution and better ROAS.