Skip to content

feat: add Meta Pixel to docs site#890

Open
dhananjay6561 wants to merge 4 commits into
keploy:mainfrom
dhananjay6561:add-meta-pixel
Open

feat: add Meta Pixel to docs site#890
dhananjay6561 wants to merge 4 commits into
keploy:mainfrom
dhananjay6561:add-meta-pixel

Conversation

@dhananjay6561

@dhananjay6561 dhananjay6561 commented Jul 13, 2026

Copy link
Copy Markdown
Member

What

Installs the Meta (Facebook) Pixel (2006330080011702) site-wide on the docs.

  • Base snippet injected into <head> on every page via headTags (docusaurus.config.js): loads fbevents.js, runs fbq('init', ...), and fires the initial PageView. fbq is defined synchronously by the snippet, so the first PageView can never race the loader.
  • SPA route tracking (src/metaPixelRouteTracker.js, registered as a clientModule): re-fires PageView on client-side navigation via Docusaurus's onRouteDidUpdate lifecycle hook. Docusaurus is a single-page app, so without this the base snippet would only ever report the first page a visitor lands on.
  • Includes the <noscript> tracking-pixel fallback for JS-disabled clients.

Events tracked

  • PageView only.
  • No other events (ViewContent, Lead, CompleteRegistration, custom, etc.) are tracked in this PR. Those can be added later on specific CTAs/flows.

When does the event fire?

The first PageView is fired synchronously by the base script (where fbq is guaranteed defined), and subsequent PageViews are fired by the client module on route changes. This split avoids both an fbq-not-ready race on the first load and double-counting the initial page.

User action What happens PageView fired?
Lands on the site / full reload <head> snippet runs fbq('init') + fbq('track','PageView') ✅ 1 (base script)
onRouteDidUpdate runs on first render previousLocation is null → guard skips it ⏭️ skipped (avoids double-count)
Clicks an internal link (SPA nav) location.pathname differs from previousLocation.pathname → fires fbq('track','PageView') ✅ 1 per navigation
Navigation where only the query/hash changes (same path) pathname unchanged → guard skips ❌ none
Ad blocker / tracking protection on, or JS disabled fbevents.js blocked (the <noscript> <img> covers the JS-off case with a single beacon) ⚠️ browser pixel dropped

How the pixel leads to an ad (flow)

flowchart TD
    A[User opens keploy.io/docs] --> B[Meta Pixel runs on page load<br/>fbq init + PageView]
    B --> C[Browser sends beacon to Meta<br/>facebook.com/tr + Facebook cookies]
    C --> D[Meta identifies the visitor via cookie<br/>Facebook account XYZ]
    D --> E[Meta adds the user to Keploy's audience]
    E --> F[Later the user scrolls Instagram / Facebook]
    F --> G[Meta serves the user a Keploy ad]
Loading

The site never sends personal data — it only says "a PageView happened." Identity is matched on Meta's side via the Facebook cookies the browser attaches to the /tr request. This depends on third-party cookies, so it's weaker/absent for logged-out users, Safari/Firefox, private mode, and ad blockers (a future Conversions API would recover some of that).

How to test (for reviewers)

Important: disable ad blockers / tracking protection first, or test in an Incognito window with the ad blocker set to not run in Incognito. Blockers drop fbevents.js (shows as blocked:other) and you'll see zero events even though the code is correct.

  1. Install the Meta Pixel Helper Chrome extension.
  2. Run the docs locally: yarn start, then open http://localhost:3000/docs/.
  3. Open DevTools → Network tab, check "Preserve log", and type facebook in the filter bar.
  4. Reload the page. Expected:
    • fbevents.js200 (not blocked:other / 0 kB)
    • tr/?id=2006330080011702&ev=PageView200
    • Meta Pixel Helper shows the pixel Active with 1 PageView.
  5. Click an internal link (SPA navigation, no full reload). Expected:
    • a new tr/?...ev=PageView beacon appears → PageView count goes 1 → 2.
  6. Click a link to a same-path URL (query/hash only). Expected: no new beacon (pathname-guarded).
  7. (Optional, end-to-end) In Meta Events Manager → Test Events, enter pixel 2006330080011702 and browse the local site to watch the same PageViews land on Meta's side.

Pass criteria: 1 PageView on load, +1 per SPA path change, 0 on same-path clicks — all beacons 200.

Verify (author)

  • Ran a full yarn build locally; compiles clean and the generated static HTML contains the pixel (fbq("init","2006330080011702"),fbq("track","PageView"), the connect.facebook.net/en_US/fbevents.js loader, and the <noscript> beacon).
  • onRouteDidUpdate guard reviewed: fires only on an actual pathname change, skips the initial load (previousLocation === null) and same-path updates — so no double-count on landing and one PageView per SPA navigation.
  • No CSP changes needed for docs (no enforcing Content-Security-Policy blocks Facebook's domains here); this PR touches only docusaurus.config.js and src/metaPixelRouteTracker.js.

Note on the hardcoded pixel ID

The pixel ID is inlined, matching every other tracker in this repo — Microsoft Clarity (static/scripts/clarity.js), Apollo (apollo-init.js), and Google Analytics/gtag (docusaurus.config.js) are all hardcoded, and the repo has no .env files or process.env usage to read from. The preview/staging-pollution concern is valid but applies equally to those existing trackers, so moving all of them behind env config (with preview/staging skipped) is proposed as a dedicated repo-wide follow-up rather than gating the pixel alone here.

Docs deploys separately from the landing page (keploy/landing#245 adds the same snippet there) — this PR gives the docs site the equivalent coverage.

Signed-off-by: dhananjay6561 <dhananjayaggarwal6561@gmail.com>
Copilot AI review requested due to automatic review settings July 13, 2026 14:47

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

Signed-off-by: dhananjay6561 <dhananjayaggarwal6561@gmail.com>
Signed-off-by: dhananjay6561 <dhananjayaggarwal6561@gmail.com>

@amaan-bhati amaan-bhati left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Build not verified locally

The PR description calls out that a full Docusaurus build was not run due to disk space. Worth someone on the team doing a quick npm run build on this branch before merging, or at minimum checking the Network tab for the tr?...ev=PageView beacon after the preview deploy lands.

Comment thread docusaurus.config.js
Comment thread docusaurus.config.js Outdated
Comment thread src/metaPixelRouteTracker.js Outdated
…t pixel

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@amaan-bhati
amaan-bhati self-requested a review July 14, 2026 10:44

@amaan-bhati amaan-bhati left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM

@dhananjay6561

Copy link
Copy Markdown
Member Author

cc: @nehagup

@dhananjay6561 dhananjay6561 self-assigned this Jul 16, 2026
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.

3 participants