Skip to content

Install the Meta pixel - #66

Merged
mikaalnaik merged 1 commit into
mainfrom
mikaal/meta-pixel
Aug 20, 2026
Merged

Install the Meta pixel#66
mikaalnaik merged 1 commit into
mainfrom
mikaal/meta-pixel

Conversation

@mikaalnaik

Copy link
Copy Markdown
Contributor

Adds the Meta (Facebook) pixel (1782353696227901) to the site.

What's here

  • src/components/MetaPixel.tsx — the base snippet (fbq('init', ...) + initial PageView), the <noscript> fallback image, and a PageViewTracker that re-fires fbq('track', 'PageView') on client-side navigations. fbevents.js installs no history listener, so App Router route changes would otherwise go unreported.
  • src/app/layout.tsx — renders <MetaPixel /> alongside <XPixel />.

This mirrors the XPixel component added in #59, including two deliberate carry-overs:

  • Gated to NODE_ENV === "production", so localhost and preview deployments stay out of the ad data.
  • The first effect run is skipped so the inline snippet's initial PageView isn't double-counted (this also covers strict-mode effect re-runs).

Notes

The pixel ID is hardcoded, matching X_PIXEL_ID. Happy to move both to env vars in a follow-up if preferred.

Testing

tsc --noEmit and eslint both clean. The pixel can't fire locally without temporarily dropping the NODE_ENV guard — worth verifying in Meta Events Manager once this is on production.

🤖 Generated with Claude Code

Add the Meta (Facebook) pixel alongside the existing X pixel, following the
same pattern: the base snippet reports the initial page load, and a client
tracker re-fires PageView on App Router navigations since fbevents.js
installs no history listener. Production only, so localhost and preview
deployments stay out of the ad data.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
@greptile-apps

greptile-apps Bot commented Aug 20, 2026

Copy link
Copy Markdown

Greptile Summary

Adds a production-only Meta pixel to the root layout, including initial and client-navigation PageView tracking plus a noscript fallback.

  • Introduces a client component that initializes pixel 1782353696227901 through fbevents.js.
  • Tracks App Router pathname and query-string changes without duplicating the initial PageView.
  • Mounts the component alongside the existing analytics integrations.

Confidence Score: 4/5

The Content Security Policy must permit the new Meta script and beacon hosts before merging, or the pixel will not function on deployments that apply public/_headers.

The tracking lifecycle and navigation handling are consistent with existing integrations, but the configured browser policy blocks both delivery paths introduced for Meta PageViews.

Files Needing Attention: src/components/MetaPixel.tsx and public/_headers

Important Files Changed

Filename Overview
src/components/MetaPixel.tsx Implements Meta initialization and navigation tracking, but its external script and fallback beacon are blocked by the configured CSP.
src/app/layout.tsx Mounts the new production-gated tracking component alongside the existing integrations.

Sequence Diagram

sequenceDiagram
    participant Browser
    participant Layout as RootLayout
    participant Pixel as MetaPixel
    participant Meta as Meta endpoints
    Browser->>Layout: Load production page
    Layout->>Pixel: Render tracker
    Pixel->>Meta: Request fbevents.js
    Note over Browser,Meta: CSP blocks connect.facebook.net on configured Pages deployments
    Pixel--xMeta: PageView remains queued
    Browser->>Pixel: Client-side navigation
    Pixel--xMeta: Track PageView cannot be delivered
Loading

Fix all with Greploop Fix All in Codex Fix All in Claude Code

Prompt To Fix All With AI
### Issue 1
src/components/MetaPixel.tsx:65
**CSP blocks Meta event delivery**

If the deployment applies `public/_headers`, its CSP blocks `connect.facebook.net` from loading `fbevents.js` and blocks the `www.facebook.com` fallback image, causing the new pixel to report no PageView events.

---

For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.

Reviews (1): Last reviewed commit: "Install the Meta pixel" | Re-trigger Greptile

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');

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 CSP blocks Meta event delivery

If the deployment applies public/_headers, its CSP blocks connect.facebook.net from loading fbevents.js and blocks the www.facebook.com fallback image, causing the new pixel to report no PageView events.

Prompt To Fix With AI
This is a comment left during a code review.
Path: src/components/MetaPixel.tsx
Line: 65

Comment:
**CSP blocks Meta event delivery**

If the deployment applies `public/_headers`, its CSP blocks `connect.facebook.net` from loading `fbevents.js` and blocks the `www.facebook.com` fallback image, causing the new pixel to report no PageView events.

---

For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.

Fix in Codex Fix in Claude Code

@mikaalnaik
mikaalnaik merged commit 7c3e687 into main Aug 20, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant