On this page
The Meta Pixel is a small piece of JavaScript from Meta that records what visitors do on your website, such as viewing a product, submitting a lead form or buying, so you can measure Facebook and Instagram ads, build audiences and optimize for sales. To set it up with Google Tag Manager, add the Pixel base code as one tag on all pages, then add a tag for each event, fed by your data layer.
What Is the Meta Pixel?
Meta’s developer guide describes the Pixel as a snippet of JavaScript that loads a small library of functions for tracking ad-driven visitor activity, measuring conversions, building custom audiences and running catalog ads. Its base code also records a PageView every time a page loads.
Everything Meta’s ad system learns about your website comes through the Pixel or its server-side partner, the Conversions API. If the Pixel misses purchases or counts them twice, your reported results and your campaign optimization both suffer. That’s why a clean setup matters more than a fast one.
Should You Install the Pixel With GTM or Directly on the Site?
Either works. Meta recommends placing the base code in the head of every page but notes the Pixel works in most tag managers. GTM is the better choice if you already use it, because every event, trigger and consent rule sits in one place you can test and roll back.
| Platform | Simplest route | When to use GTM |
| WordPress / WooCommerce | Meta plugin or GTM | You already run GTM with a data layer |
| Shopify | Facebook & Instagram channel | Only for events the channel doesn’t send |
| Custom site or web app | GTM | Almost always |
| Landing page builders | Builder’s Pixel field | When you need custom events |
On Shopify, the Facebook & Instagram sales channel already installs the Pixel and can add the Conversions API, as covered in our Conversions API setup guide. Adding a second Pixel through GTM on the same store usually creates duplicate events, so remove one before you add the other.
What You Need Before You Start
Should You Use the Meta Pixel Tag Template or Custom HTML in GTM?
A tag template is easier to read and harder to break; Custom HTML gives you full control and works with code straight from Meta. Both send the same data if they’re set up correctly.
Tag templates come from GTM’s Community Template Gallery. Google’s help page is clear that gallery templates are made by third-party developers, not Google, and that you should review each template’s permissions before adding it. If you edit a template, it stops receiving updates from its publisher. Custom HTML has no such dependency, but every tag is code that someone has to maintain.
Step 1: Add the Base Code Tag
Template route: in GTM go to Templates, choose Search Gallery in the Tag Templates section, search for the Meta (Facebook) Pixel, check the publisher and permissions, and click Add to workspace. Create a tag from it with your Pixel ID and the PageView event.
Custom HTML route: copy the base code from Events Manager into a Custom HTML tag. It includes your Pixel ID twice, in the init call and in the noscript image URL. Meta advises leaving the PageView call in place.
Tag: Meta - Base Code - Tag
Trigger: Initialization - All Pages
fbq('init', 'XXXXXXXXXXXXXXX');
fbq('track', 'PageView');Firing the base code on an early trigger, and making sure event tags only fire after it (for example with tag sequencing), avoids the common error where an event tag runs before fbq exists.
Step 2: Turn On Advanced Matching (Optional)
Advanced matching sends customer details such as email or phone with the Pixel so Meta can match more events to people. Meta’s guide says you can turn on automatic advanced matching in Events Manager, or pass the details yourself in the init call, where the Pixel hashes them with SHA-256 before sending.
fbq('init', 'XXXXXXXXXXXXXXX', {
em: '{{Customer Email}}',
ph: '{{Customer Phone}}'
});Meta’s guide warns that manual values must sit in the base code’s init call to count as advanced matching. Email should be lowercase and phone digits only, including country code. Only send these when you have the visitor’s details and their consent where it’s required.
How Do You Send Purchase Value, Currency and Product IDs From the Data Layer?
Push the order details into the data layer on the confirmation page, read them into GTM variables, and pass them to the Purchase event. Meta’s Pixel reference lists currency and value as required for Purchase, and product IDs (contents or content_ids) as required if you run Advantage+ catalog ads.
Step 3: Push Order Details to the Data Layer
dataLayer.push({
event: 'purchase',
ecommerce: {
transaction_id: 'ORDER-1001',
value: 120.00,
currency: 'USD',
items: [{ item_id: 'SKU-123', quantity: 1 }]
}
});Most WooCommerce and Shopify tracking setups already push a GA4-style ecommerce object like this, so you can reuse it for Meta instead of building a second one.
Step 4: Create the Purchase Event Tag
Create Data Layer Variables for the value, currency, transaction ID and item IDs, then a tag that fires on the purchase custom event. Pass the order ID as the event ID: that’s what lets Meta match this browser event with the same order sent through the Conversions API.
Tag: Meta - Purchase - Tag
Trigger: Purchase (Custom Event: purchase)
Variables: Purchase Value, Currency, Transaction ID, Item IDs
fbq('track', 'Purchase', {
value: {{Purchase Value}},
currency: '{{Currency}}',
content_ids: {{Item IDs}},
content_type: 'product'
}, { eventID: '{{Transaction ID}}' });Use the same pattern for AddToCart, InitiateCheckout and ViewContent. Keep value numeric (120.00, not “$120”) and currency as a three-letter code such as USD, or the event’s value can’t be used in reporting and optimization.
How Do You Track Form Submissions, Button Clicks and Leads?
Fire Meta’s Lead (or Schedule, or Contact) standard event when the action actually succeeds, not when the button is clicked. Meta’s standard events include Lead, Schedule, Contact, CompleteRegistration and SubmitApplication, so pick the one that matches the action.
| Action | Meta standard event | Best GTM trigger |
| Quote or contact form | Lead | Form success message or thank-you page |
| Booking widget | Schedule | Booking confirmation event |
| Click-to-call or email link | Contact | Click on tel: or mailto: link |
| Account sign-up | CompleteRegistration | Success page or data layer event |
When there’s no thank-you page, ask your developer or form plugin to push a data layer event on success (for example form_submit_success) and trigger the tag on that. Button-click triggers fire even when validation fails, which inflates leads. Our GTM event tracking guide covers click and form triggers in more depth, and if you collect leads inside Facebook itself, see setting up Facebook Lead Ads.
Tag: Meta - Lead - Tag
Trigger: Form Submit Success (Custom Event: form_submit_success)
fbq('track', 'Lead', {}, { eventID: '{{Event ID}}' });How Do You Make the Meta Pixel Work With Your Cookie Consent Banner?
In GTM, set each Meta tag to require consent before it fires. Google’s Tag Manager help describes this under Advanced Settings > Consent Settings, where “Require additional consent for tag to fire” means the tag only fires if all the consent types you list, such as ad_storage, are granted.
- Make sure your consent banner’s GTM template runs on the Consent Initialization trigger, which Google says fires before all other tags.
- On every Meta tag, set Consent Settings to require ad_storage (add ad_user_data too if your banner sets it).
- Check Consent Overview in GTM to confirm no Meta tag is left as “not set”.
- Test three paths: no choice made, Accept all, and Reject all.
Unless your tag template says it handles consent itself, assume the Meta tag doesn’t react to Google’s consent signals on its own; this tag-level setting is what stops it from firing early. If tags fire after a visitor accepts, consented visitors are still tracked from that point. For the banner side, see our Consent Mode v2 guide.
How Do You Test the Meta Pixel?
Use GTM Preview to confirm the tags fire, then confirm Meta receives them. Meta’s browser extension, Meta Ads Data Advisor (it replaced Meta Pixel Helper automatically), shows which Pixels load on a page, their status and the events with their parameters. Meta’s get-started guide also suggests checking for new events in Events Manager, waiting a few minutes if they don’t appear.
| Problem | Likely cause | Fix |
| Two PageViews on every page | Pixel installed twice (plugin + GTM) | Remove one installation |
| Purchase fires twice | Tag fires on page reload or two triggers | One trigger; dedupe by order ID |
| “fbq is not defined” | Event tag fired before base code | Fire base code first (tag sequencing) |
| Invalid currency or NaN value | Value has symbols or variable is empty | Send a number and a 3-letter code |
| GTM fires, Meta sees nothing | Consent blocked it, ad blocker, wrong ID | Check consent state and Pixel ID |
| Lead counted without a real lead | Trigger on button click | Trigger on form success |
If purchases still look wrong after these checks, our guide to a Pixel that isn’t tracking purchases goes through the deeper causes.
What Should You Do After the Pixel Works?
Add the Conversions API, so events still reach Meta when the browser blocks the Pixel, and keep the same event IDs on both sides so nothing is counted twice. That step is covered in our Conversions API setup guide.
Then review your setup every time the site changes: a new checkout, form plugin or theme is the most common reason a working Pixel quietly breaks. If you’d like the Pixel and events set up or audited for you, our Meta Ads management runs month-to-month with no lock-in, and our Tracking & Analytics service can handle the tracking alone. Both start with a free audit.
FAQ
Frequently asked questions
Do I Need to Remove My WordPress or Shopify Pixel Plugin Before Installing the Pixel Through GTM?
Yes, for any event both would send. Two installations of the same Pixel send every PageView and Purchase twice. On Shopify it's usually simpler to keep the Facebook & Instagram channel and use GTM only for events the channel doesn't cover. On WordPress, choose either the plugin or GTM as the single source.
Why Does GTM Show the Tag Fired but Meta's Browser Extension Finds No Pixel?
Usually the base code never loaded: the tag fired on a trigger that runs after the page, consent blocked it, or an ad blocker or privacy extension stopped the Meta script. It can also mean the tag fired in GTM Preview but the container version with that tag hasn't been published. Test in a clean browser profile with extensions other than Meta's turned off.
Why Is the Purchase Event Firing Twice in GTM Preview?
The tag is attached to two triggers, the purchase event is pushed twice to the data layer, or the confirmation page reloads and pushes it again. Check that only one trigger fires the tag, and that your site pushes the purchase event once per order. Sending the order ID as the event ID also helps Meta remove repeats.
My GTM Tag Fires in Preview Mode, So Why Aren't Events Showing in Events Manager?
Events can take a few minutes to appear, so wait and refresh first. If they still don't show, check that the Pixel ID in the tag matches the Pixel you're viewing, that the GTM container is published, and that the test browser had granted consent. A test event code left in a server setup can also send events to the test view only.
Should Advanced Matching Be Set Up in GTM or at Checkout?
Either can work, but the data has to be available when the base code's init call runs, because Meta only treats details in init as manual advanced matching. Many stores turn on automatic advanced matching in Events Manager and send customer details through the Conversions API from checkout, where email and phone are reliably known.
Which Meta Pixel Events Should a Small Business Track?
Track the few actions that mean money: Purchase for stores, Lead or Schedule for service businesses, plus AddToCart and InitiateCheckout if you sell online. PageView comes with the base code. Adding many custom events rarely helps; what matters is that the events you optimize for fire once, at the right moment, with the right values.
6 sources & references
- Meta for Developers Get started with the Meta Pixel developers.facebook.com
- Meta for Developers Meta Pixel API reference developers.facebook.com
- Meta for Developers Advanced matching developers.facebook.com
- Meta for Developers Meta Ads Data Advisor developers.facebook.com
- Tag Manager Help Community Template Gallery support.google.com
- Tag Manager Help Tag Manager consent mode support support.google.com
Official pages we checked when writing this article.







