Shopify Facebook Pixel PageView tracking with GTM
Track Shopify page_viewed as Meta PageView through Customer events and GTM. Keep page context separate and check for overlapping page-view tags.
Shahzada Ali Hassan, founder of Crisperchecked against 11 sources
The short answer
Track Shopify PageView through Customer events and GTM by mapping page_viewed to Meta's PageView event. Shopify documentsshopify.dev the viewed page URL in event.context.document.location.href. This guide helps store owners and implementers maintain a custom pixel and check the data it sends.
- GTM listens for
page_view; Meta receivesPageView. - Use Standard for
PageViewin the Meta templateraw.githubusercontent.com. - If an existing sender already covers this event, inspect it before adding another.
- Steps and settings checked against Shopify documentation and Meta's template on 25 October 2026.
FREE CALL
30 MINMeta stopped counting your leads? Get them counted again.
- Pick a time
Check your Meta account with Hassan- See what to do next
On a free 30-minute call, Hassan checks your Meta account with you and shows you what to do next.
Not ready to talk? Run a free check
01How do I track Shopify PageView with GTM?
Subscribe to page_viewed inside the custom pixel and use it to trigger Meta's standard PageView. Keep this tag separate from product views and cart actions.
Read page details from the page_viewed contextshopify.dev, which describes the browser at the time of the event. This event has no product or checkout payload to turn into ecommerce properties.
The accompanying video uses an earlier version of this Customer events walkthrough; use the written steps below for the revised code, privacy choices and testing sequence.
Use this setup when you need a custom event mapping and can maintain its JavaScript. If the store already uses Facebook and Instagram by Metahelp.shopify.com, inspect its events first; Shopify warns that overlapping installations can produce duplicate or incorrect reports.
Work in a development store with a GTM web container reserved for testing and a test Meta pixel. Have access to Customer events, the container and Meta Events Manager. Shopify describes custom pixels as an advanced, unsupported featurehelp.shopify.com; use an app integration if you need a maintained installation.
02How do I add a custom pixel in Shopify?
Create or reuse a custom pixel in Settings > Customer events. Keep this event subscription with the GTM loader that will receive it.
1. Name the pixel and review Customer privacy
- Select Add custom pixel.
- Name the pixel for this setup and select Add pixel.
- Review Permission and Data sale using Shopify's privacy settingshelp.shopify.com rather than copying a blanket permission choice.
Done when the editor is open and the saved settings match the store's consent plan.
03What code sends PageView to the data layer?
The page-view referenceshopify.dev exposes the top-frame URL, title and referrer through event.context.document. The snippet stores those fields in page_data for inspection; storing them there does not configure Meta's received event URL.
The data layer is the queue of named events and values GTM reads, as described in Google's guidedevelopers.google.com. Shopify passes event datashopify.dev, called a payload, to the function inside analytics.subscribe. This example keeps the original page_view event name and nested payload paths.
2. Add the loader and subscription
- Paste the JavaScript below into the test pixel. It includes the loader, following Shopify's GTM custom-pixel patternhelp.shopify.com; do not add a second loader if your existing pixel already has one.
- Replace
GTM-EXAMPLEwith the ID of a test container that only your development store loads. - Save and connect the pixel.
// Initialize the dataLayerwindow.dataLayer = window.dataLayer || [];(function (w, d, s, l, i) { w[l] = w[l] || []; w[l].push({ "gtm.start": new Date().getTime(), event: "gtm.js" }); var f = d.getElementsByTagName(s)[0], j = d.createElement(s), dl = l != "dataLayer" ? "&l=" + l : ""; j.async = true; j.src = "https://www.googletagmanager.com/gtm.js?id=" + i + dl; f.parentNode.insertBefore(j, f);})(window, document, "script", "dataLayer", "GTM-EXAMPLE");function logEventToConsole(dataLayerEvent) { const customStyle01 = "color: #FFFF00; background-color: #000000; font-size: 10px; font-weight: bold; padding: 2px 0;"; console.log("%cDataLayer Event: page_view ", customStyle01, dataLayerEvent);}analytics.subscribe("page_viewed", (event) => {
28 more lines of JavaScript
- Copy and download
- Emailed to you
Unlock this snippet
Two details, and the full code is yours
No account needed. Unlock once and every snippet on the blog opens.
Done when Customer events shows Connected and the saved code contains the intended ID and one page_viewed subscription.
It no longer calls history.pushState: Meta's template documents automatic PageViews from history changesraw.githubusercontent.com, so this subscription does not create an extra history change.
04Which GTM variables does PageView need?
Create variables for the values your tag will send. A Data Layer Variablesupport.google.com reads a named path from the data layer; a Constant stores a fixed value such as the test pixel ID. A trigger tells GTM when to run a tag.
3. Create the variables and exact event trigger
- In GTM, create a Constant variable named Meta Pixel ID with your test pixel ID.
- Create each Data Layer Variable in the table below, using Version 2 for nested paths.
- Add a Custom Event trigger whose event name is exactly
page_view, with regular-expression matching off, and save it.
Meta Pixel ID
- Value or data layer path
- Constant: your test pixel ID
- Use in this setup
- Pixel ID
DLV - Event ID
- Value or data layer path
- event_data.id
- Use in this setup
- Event ID
DLV - Page URL
- Value or data layer path
- page_data.url
- Use in this setup
- Diagnostic comparison only
Done when the saved variables match the table and the trigger listens for page_view.
05How do I configure the Meta PageView tag?
Use the Meta Pixel template from Meta's official GTM repositorygithub.com. Select Standard and choose PageView, following the template's event-name controlsraw.githubusercontent.com.
4. Map the properties and save the tag
- Create a tag from the Meta Pixel template, select Standard and choose PageView.
- Enter Meta Pixel ID as the pixel ID.
- Set Event ID to DLV - Event ID, and leave automatic ecommerce mapping off for this example.
- Leave ecommerce object properties empty for PageView.
- Clear the template's Opt in to a Meta-enabled Conversions API integration boxraw.githubusercontent.com. It is ticked by default, and while it is ticked the tag opts the pixel in to that integration. This guide sets up the browser tag only, so clear it on this tag and on any other Meta Pixel tag that uses the same pixel.
- Enable Disable History Event Tracking for this PageView setup so your explicit
page_viewtrigger owns navigation events; the template settingraw.githubusercontent.com controls automatic history-based PageViews. - Attach only the
page_viewtrigger and save.
Done when reopening the tag shows PageView, the test pixel ID, the specified fields, the exact trigger, the opt-in box cleared and the Disable History Event Tracking checkbox enabled, and the navigation test produces no unexplained second PageView.
The Event ID fieldraw.githubusercontent.com can support browser/server deduplication, which counts matching copies as one event. This walkthrough configures a browser sender only. If you also send events from a server, use the same ID for the same action.
06How do I test Shopify PageView tracking?
Follow the event through Shopify Pixel Helper and then Meta Events Manager. A green dot in Shopify Pixel Helperhelp.shopify.com means the subscription code ran successfully; verify Meta receipt and parameter values separately.
5. Publish the version in the test container
Changes saved in a workspace do not run yet. Google sayssupport.google.com you need to publish workspace changes to make them operational.
- Open the test container that only your development store loads.
- Select Submit, then choose Publish and Create Version.
- Name the version and publish.
Do not publish to a container your live store loads; move the tested setup there through your normal release process.
Done when the test container's Versions list shows your version as published and the pixel code loads that container's ID.
6. Follow a test action through both systems
- Open the connected pixel and select Test, following Shopify's testing procedurehelp.shopify.com.
- Exercise the store's consent flow and check that Pixel Helper's consent status matches your choice.
- Open the home page.
- Visit a collection page, then a product page.
- In Pixel Helper, expand
page_viewedand check that each visited page has the expected URL and title in event.context.document. - In the browser console, check that the logged
page_viewobject's event name and mapped values agree with the Shopify payload, with no unexplained errors. - In Meta Events Manager Test Events, inspect
PageViewon the intended test pixel: its time and properties should match your action, its received URL should be appropriate, and there should be no unexplained second send. - Save the tested container version, pixel ID, action time, observed fields and any failures.
Done when every comparison above matches and your notes distinguish the Shopify subscription check from the Meta receipt check.
Shopify says Tag Assistant's Troubleshoot tag feature is incompatible with custom pixelshelp.shopify.com. If the test container cannot load the saved tag version, stop and resolve the test environment with its owner; changing a live container is not a debugging step.
07How do I add AddToCart after PageView?
Use a separate product-added subscription rather than a generic click trigger. Follow the Add to Cart guide for its payload and keep PageView on page_view.
08Why is my PageView event missing or duplicated?
Check the event source, tag mapping and test environment before adding another sender.
- Adding an All Pages tag alongside the page_view trigger: two tags can send the same visit. Choose one PageView path and test each navigation.
- Copying the loader or subscription twice: the same action can be processed twice. Keep one loader per custom pixel and one subscription for this mapping.
- Accepting a sandbox URL as the viewed page: the visit can be recorded against the wrong location. Compare the received Meta URL with Shopify's page context and resolve any mismatch before rollout.
09What should I check after PageView?
Test the next part of the journey with the Shopify view content guide and Shopify add to cart guide. Record the source event, mapped fields and Meta receipt for each stage.
10What changed in this guide
- 25 October 2026: Checked the page_viewed payload against Shopify's reference, corrected the data mapping and Meta event settings, and replaced blanket privacy and live-publish instructions with development-store checks. Added the test-container publish step and the Conversions API opt-in setting.
Sources
11 sources
- 1Meta templateraw.githubusercontent.com↩
- 2Shopify documentsshopify.dev↩
- 3Facebook and Instagram by Metahelp.shopify.com↩
- 4Shopify describes custom pixels as an advanced, unsupported featurehelp.shopify.com↩
- 5Google's guidedevelopers.google.com↩
- 6Shopify's GTM custom-pixel patternhelp.shopify.com↩
- 7Shopify pixels run in a sandboxhelp.shopify.com↩
- 8Data Layer Variablesupport.google.com↩
- 9Meta's official GTM repositorygithub.com↩
- 10green dot in Shopify Pixel Helperhelp.shopify.com↩
- 11Google sayssupport.google.com↩

