How to set up the Facebook Pixel with Google Tag Manager (any website)
To set up the Facebook Pixel with Google Tag Manager, install a Google Tag Manager container on your site, add a data layer that describes what visitors do, and then create one Meta Pixel tag for each event: PageView, ViewContent, AddToCart, InitiateCheckout and Purchase. Each tag reads the product and order details from the data layer, sends customer details through advanced matching, and carries an event ID. Test it in Preview mode and in Meta's Test events, then publish.
The video above shows the whole setup on a store in about 16 minutes. This post is the written version: the steps in the same order, what to put in each tag, and the mistakes to check for. It works on any website. If your store runs on a specific platform, I also have step-by-step versions on Shopify and on WooCommerce.
Why use Google Tag Manager for the Meta Pixel
You can paste Meta's pixel code into your site or let a plugin install it. Both work, but you get little control over what each event sends, and every change means touching code.
With Google Tag Manager, every Meta event lives in one container. You decide which details go with each event, you can test changes in Preview mode before anyone sees them, and you can roll back to an older version if something breaks. It's also the base you need for the Conversions API later, which sends the same events from a server.
What you need
- A Meta Pixel ID. Meta now calls a pixel a dataset; the ID is the same number. This guide shows where it is in Events Manager.
- A Google Tag Manager account with a Web container.
- Access to your site's code or theme, to add the container once.
- A data layer. It pushes what happens on your site (product viewed, added to cart, checkout started, order placed) into Google Tag Manager, with the product, order and customer details. Without it, your tags fire with empty or incomplete data. How you add one depends on your platform.
The events in the video are the five most stores need:
- PageView on every page.
- ViewContent when someone views a product.
- AddToCart when someone adds a product to the cart.
- InitiateCheckout when someone starts checkout.
- Purchase when an order is completed.
All five are Meta standard events (Meta, Pixel reference). Use the standard names, not your own, so Meta knows what each event means.
Step 1: create a Google Tag Manager container
Go to tagmanager.google.com and click Create account. Enter your business name as the account name and pick your country. For the container, use your website's name and choose Web. Accept the terms, and Google Tag Manager shows you the container code and an ID that starts with GTM-.
Step 2: add the container code to your site
Google Tag Manager gives you two pieces of code. Google says to put the first one as high in the <head> of every page as you can, and the second one right after the opening <body> tag (Google, Get started with Tag Manager).
In the video I add it to the theme's head section, but the idea is the same on every platform: find the place where your site's <head> code lives, paste, save. Then check that the container loads, for example by opening Preview mode in Google Tag Manager and connecting to your site.
Remove any Meta pixel code that's already in your theme, and turn off any plugin or app that sends the same pixel. If two things send PageView to one pixel, Meta counts it twice.
Step 3: create the triggers
Triggers decide when a tag fires. Your data layer pushes an event name each time something happens, and you make one trigger for each name.
In Google Tag Manager, go to Triggers → New → Custom Event, enter the event name exactly as your data layer pushes it, and save. With a data layer that uses Google's ecommerce names, the triggers are view_item, add_to_cart, begin_checkout and purchase. PageView uses the built-in All Pages trigger.
The names must match exactly. Purchase and purchase are two different events to Google Tag Manager. If you're not sure what your data layer pushes, open Preview mode, click through your site, and read the event names in the left column.
Step 4: create the variables
Variables read the values your tags send. Make these:
- Pixel ID: a Constant variable holding your Pixel ID. If the ID ever changes, you change it in one place.
- External ID: your own ID for the visitor. In the video I make it with a Custom JavaScript variable. Sending it helps Meta match events to people, which helps retargeting.
- Product and order values: Data Layer Variables for value, currency, transaction ID and the items array.
- An event ID: a variable that makes a new unique ID for each event. Community templates for this exist in the Template Gallery. You'll want it for the Conversions API later.
There's one catch. A data layer built for GA4 sends products as an items array, but Meta wants content_ids, content_name, content_category and contents. In the video I use a variable template from the Community Template Gallery that converts the GA4 items array into Meta's fields. You point it at your items variable, tell it which keys to read (item ID, name, category, price, quantity), and choose which field it returns. Make one variable per field.
Step 5: create the Meta Pixel tags
Make one tag per event. In the video I use the Facebook Pixel tag template from the Community Template Gallery instead of a Custom HTML tag. It keeps every field in a form, which is easier to read and harder to break.
Start with PageView:
- Pixel ID: your constant variable.
- Event: standard event, PageView.
- Advanced matching: turn it on and add the customer details you have, at least the external ID. Meta's documentation says the pixel hashes these values with SHA-256 before they're sent (Meta, advanced matching).
- Event ID: your event ID variable.
- Trigger: All Pages.
Then ViewContent, on the view_item trigger, with the same fields plus these object properties:
content_ids,content_name,content_categoryandcontents.content_type: product if your IDs are single products, or product_group if your products have variants such as size or colour. Meta's reference explains the difference (Meta, Pixel reference).valueandcurrency, from the data layer.
AddToCart follows the same pattern on the add_to_cart trigger. InitiateCheckout adds num_items on begin_checkout.
Purchase is the most important tag, so give it everything: the product fields above, value (the real order total, never a fixed number), currency, num_items, and order_id set to the transaction ID. Add every customer detail your data layer has on the thank-you page to advanced matching: email, phone, name, city, country and external ID. Trigger it on purchase.
Don't skip contents on any event. In the video I forgot it at first and had to go back and add it to every tag. Catalog ads use it to match events to products in your catalog.
Why the event ID matters. The pixel works without one today. But when you add the Conversions API, Meta pairs a browser event and a server event only when both have the same event name and the same event ID (Meta, handling duplicate pixel and Conversions API events). Add it now and the next step is much easier.
Step 6: test the setup
Don't publish yet. Click Preview, enter your site's address and connect. Then go through the site the way a buyer would: open a product, add it to the cart, start checkout and place a test order.
Check three places:
- Tag Assistant (Preview mode). Each Meta tag should fire on its own event. Click a tag to see the values it sent.
- Meta Pixel Helper. It's a free Chrome extension from Meta. On each page it shows the events the pixel sent and their parameters: content name, contents, value, currency, order ID and external ID.
- Events Manager → Test events. Open your pixel, go to Test events, enter your site's address, and repeat the journey. Click each event to see what Meta received. This is the source of truth.
If a field shows as empty or "not set", the data layer didn't have it. In the video, content_category is empty because the test product has no category. That's a data problem, not a tag problem.
When everything looks right, click Submit, name the version (for example "Meta Pixel setup v1") and Publish. Preview mode only tests on your own browser. Nothing goes live until you publish.
Step 7: import a ready-made container (optional)
If you've built this setup once, you don't have to build it again. Export the container from Admin → Export container, then in the new one go to Admin → Import container, choose the file and a workspace, and pick Merge if the container already has tags you want to keep. Google Tag Manager shows a preview of what it will add before you confirm.
After importing, change the Pixel ID constant to the new pixel and check that the trigger names match the new site's data layer. Then test again before you publish.
Next step: add the Conversions API
What you've built runs in the browser only. Ad blockers, browser privacy rules and iOS settings stop some of these events from reaching Meta. The Conversions API sends the same events from a server, and because every tag already has an event ID, Meta can count each event once. Here's how: set up the Facebook Conversion API with Google Tag Manager.
Common mistakes
The pixel is installed twice. Old pixel code in the theme, a plugin or a platform app, plus your Google Tag Manager tags, means two copies of every event. Keep one source per pixel.
The trigger name doesn't match the data layer. If a tag never fires, compare the trigger's event name with what the data layer pushes in Preview mode. Case matters.
A fixed value on Purchase. The value and currency must come from the data layer, so each order sends its real total.
contents is missing. Easy to forget, as I did in the video. Add it to every product event.
The wrong content_type. If your catalog uses variant groups, send product_group. If it lists each variant, send product.
Tested but never published. Preview mode works only for you. Submit and publish the container.
No event ID. Fine for now, but you'll get doubled purchases when you add the Conversions API.
Questions people ask
Is the Facebook Pixel the same as the Meta Pixel?
Yes. Facebook renamed itself Meta, and the pixel became the Meta Pixel. In Events Manager it's now called a dataset. The ID and the code are the same.
Do I need a data layer to use the Meta Pixel in Google Tag Manager?
For PageView, no. For every ecommerce event, yes. Without a data layer, Google Tag Manager doesn't know what product was viewed or what the order was worth, so your events reach Meta with no value or products.
Can I use a Custom HTML tag instead of a template?
You can paste Meta's code into Custom HTML tags, and it will work. A tag template is easier to maintain, because every field is a form instead of code, and it's harder to break by accident.
Why don't my events show in Events Manager yet?
Use Test events while you set up; events show there within seconds. The Overview tab can take a while to update. Check that the container is published, not only previewed.
Does this work on Shopify and WooCommerce?
Yes. The triggers, variables and tags are the same. What changes is how you add the container and the data layer, so follow the platform version of this post if you're on one of them.
Where KiteTrack fits
KiteTrack takes this setup the rest of the way. It runs your own tracking server on your store's subdomain and sends your events to Meta through the Conversions API, next to the pixel, with one event ID so each sale counts once. The same server sends to Google Ads, GA4 and TikTok, customer details are hashed before they leave it, and your tracking is checked every 30 minutes, so a broken event becomes an alert. See how it works for Meta on Shopify and for Meta on WooCommerce.
Not sure whether your pixel is sending what it should? Start with the free Tracking Check. It looks at your site in about two minutes, no signup. If you'd rather talk it through, book a call with me.
Sources
- Google, Get started with Tag Manager: https://support.google.com/tagmanager/answer/14847097
- Meta, Pixel reference (standard events and parameters): https://developers.facebook.com/docs/meta-pixel/reference
- Meta, Advanced matching (Meta Pixel): https://developers.facebook.com/documentation/meta-pixel/advanced/advanced-matching
- Meta, Handling duplicate pixel and Conversions API events: https://developers.facebook.com/docs/marketing-api/conversions-api/deduplicate-pixel-and-server-events/
Get tracking tips by email
Short, practical fixes for Meta, Google Ads and GA4, from Abir.
You’re in. First tip lands soon.