Skip to content

Analytics & Tracking

How to Find Your Pixel, GA4 and PostHog Codes (and Add Them to Your Site)

Every ad platform and analytics tool asks for a code, an ID or a snippet to paste somewhere. Here's exactly where to find the Meta Pixel ID, the GA4 Measurement ID and the PostHog project API key, and how to get each one onto your website or store without breaking anything.

Why These Three Codes Matter

Meta Pixel tracks visitors who come from Facebook and Instagram ads, so you can measure conversions and build retargeting audiences. GA4 (Google Analytics 4) tracks where your traffic comes from and what people do on your site overall. PostHog tracks product behavior in more detail, including session recordings and feature usage, and is more common with SaaS products and apps. Most businesses only need one or two of these, but if you've been asked for all three, each one has its own ID to find and its own place to paste it.

What Each Code Actually Looks Like

  • Meta Pixel IDA string of 15-16 digits, found in Meta Events Manager. It's never your ad account ID or your Business ID, which look similar but are used for different things.
  • GA4 Measurement IDStarts with "G-" followed by 10 characters, for example G-ABC1234XYZ. Don't confuse it with the older Universal Analytics ID, which started with "UA-" and is no longer used.
  • PostHog Project API KeyStarts with "phc_" followed by a long string. Found under your PostHog project settings, not under your personal account settings.

Where to Find Your Meta Pixel ID

In Meta Events Manager

Get there
  • Go to business.facebook.com/events_manager
  • Select the pixel you want, or create one if none exists
  • Click "Settings" in the left-hand menu
Find the ID
  • Your Pixel ID is shown at the top of the Settings page
  • It's also visible on the main Events Manager overview, under the pixel's name
  • Copy the number, not the full tracking name

Where to Find Your GA4 Measurement ID

In Google Analytics

Get there
  • Go to analytics.google.com and select your property
  • Click the gear icon for "Admin" in the bottom left
  • Under the Property column, click "Data Streams"
Find the ID
  • Click your website's data stream
  • The Measurement ID is shown at the top right, starting with "G-"
  • If you don't have a data stream yet, create one by adding your site's URL

Where to Find Your PostHog Project API Key

In PostHog

Get there
  • Log in to app.posthog.com, or your self-hosted instance
  • Click your project name in the top left, then "Project settings"
Find the key
  • Scroll to "Project API Key" near the top of the settings page
  • Copy the key starting with "phc_"
  • Use the "Project API Key", not the personal API key used for the PostHog API itself

Two Ways to Install Any of These Codes

Once you have the ID, there are two common ways to get it live on your site. Which one makes sense depends on how your site is built and who manages it.

  • Pasting the code directly into your themeYou add the snippet straight into your site's header, usually in a file called header.liquid, header.php or similar, so it loads on every page. This works, but every future change means editing theme code again.
  • Using Google Tag Manager (recommended)You install one GTM container once, then add, remove or update any tracking code, Meta Pixel, GA4, PostHog or anything else, from the GTM dashboard without touching your site's code again.

Installing on Shopify

In Shopify Admin

Built-in pixel support
  • Go to Settings > Customer events (or Online Store > Preferences on older themes)
  • Click "Add custom pixel" for Meta Pixel or a similar third-party pixel
  • Paste the pixel code Meta provides, Shopify loads it on every page automatically
For GTM or anything else
  • Go to Online Store > Themes > Edit code
  • Open theme.liquid and paste the GTM snippet right after the opening <head> tag
  • Save, then preview your store to confirm it loads

Installing on WordPress

On a WordPress Site

Easiest: a plugin
  • Install a plugin like "Insert Headers and Footers" or "Site Kit by Google" for GA4
  • Paste your Meta Pixel, GA4 or GTM snippet into the header field
  • Save, this avoids editing theme files directly
Without a plugin
  • Go to Appearance > Theme File Editor > header.php
  • Paste the snippet just before the closing </head> tag
  • A child theme is safer here, a theme update can overwrite header.php and remove your code

Confirm It's Actually Working

  • Install the "Meta Pixel Helper" browser extension and visit your site, it should show the pixel firing with the Pixel ID matching
  • Open GA4's Realtime report and browse your own site in another tab, you should appear as an active user within a minute
  • Open PostHog's live events view and refresh your site, your own pageview should appear immediately
  • If nothing shows up, check for typos in the ID and make sure no cookie or consent banner is blocking the script before you interact with it

Frequently Asked Questions

Working on a similar digital challenge?

Tell us what you are trying to build, improve, or grow.