posthog-adblock-bypass
Skill2.1k starsChanged 7 months agoMITView on GitHub
Configure a Next.js app using posthog-js so session recording and dead-click capture survive browser ad blockers. Aliases the three blocker-flagged JS chunks (dead-clicks-autocapture.js, recorder.js, posthog-recorder.js) to bland same-origin paths via Next.js rewrites, and monkey-patches HTMLScriptElement so posthog-js requests the aliases. TRIGGER when posthog-js session replay or dead-click capture is failing in production with ERR_BLOCKED_BY_CLIENT or 404s on /static/dead-clicks-autocapture.js / /static/recorder.js / /static/posthog-recorder.js, or when the user wants to bypass ad blockers for these specific assets. Works alongside an existing PostHog reverse proxy (managed or otherwise) — only the three blocked files divert through Next.js, all other PostHog traffic stays on the original api_host. SKIP for unrelated PostHog setup, non-Next.js apps, or when capture/decide endpoints (/e/, /decide/, /array/*/config.js) are the ones being blocked — those need a different treatment.
- Reads credentials
3 other projects use a version of this.
Trending
Quiet since April.thin dataabout the whole repository
Most recently taken up by
- Leanmcp/superview.shword for word, first seen Oct 13, 2026
- chatgptprojects/claude-codeword for word, first seen Oct 8, 2026
- Leanmcp/gateway-skillsword for word, first seen Oct 8, 2026
Who's talking about chatgptprojects/clear-code
- karthink/gptel-agent“The Claude Code source code has leaked, probably bringing a massive boost to open source projects such as …”GitHub · Mar 31, 2026 · 1 reactions
- ProSkillsMD/proskills“[SUBMISSION] clear-code”GitHub · Apr 20, 2026
The biggest 2 of 2 mentions linking to the repository that our crawl found. Each line is their own headline.
Other versions3 projects use a version of this.
Word for word · 3
- Leanmcp/superview.sh★ 2.1k100% same
- chatgptprojects/claude-code★ 2.1k100% same
- Leanmcp/gateway-skills★ 2.1k100% same
Edited · 0
None found.
Wrote their own version · 0
None found.
How matches are found. Word for word: the exact same text. Edited: shares passages with this file (“99% same” means 99% of its five-word phrases also appear here; 10% or more counts). Their own version: similar meaning, or, weakest, the same name. We can’t tell which project had it first. Projects are counted among the 200 most-starred candidates, and mentions are links to the repository we found, up to 50 per site, so both counts are a floor.
In this repository16 other files it gives its agents.
- claude-code-devSkill
- analyze-exportsSkill
- code-explanationSkill
- fireworks-inferenceSkill
- godot-city-game-3dSkill
- ios-bootstrap-testflightSkill
- leanmcp-builderSkill
- mcp-apps-builderSkill
- mcp-builderSkill
- publicity-distributionSkill
- research-observabilitySkill
- research-paper-integritySkill
- security-reproSkill
- tinker-training-inferenceSkill
- translate-explanationSkill
- vuln-reproSkill
The file
We split this skill into the rules it gives an agent
3 rules. About 0 are common, 1 is distinctive, and 2 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈1
Distinctive · estimate
This author's own choices. Worth a look.
2
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Very specific: line 55
If the project already has a rewrites() or redirects() block, merge rather than replace.
- Very specific: line 130
If posthog.init is called from <Script strategy="beforeInteractive"> in app/layout.tsx instead of from a client module, put the patcher in …
- Distinctive: line 149
If recordings still don't appear, the issue is likely the dashboard toggle (Settings → Session replay), not this skill.
≈ “Common” is an estimate: at least 1 in 5 of the 350,495 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
PostHog ad-blocker bypass for Next.js
When to use this
The user has posthog-js working mostly — events, feature flags, decide, config all reach PostHog fine — but session recording and/or dead-click capture aren't working, and DevTools shows:
/static/dead-clicks-autocapture.jsfailing/static/recorder.jsor/static/posthog-recorder.jsfailingERR_BLOCKED_BY_CLIENTor a synthesized 404 (the file actually returns 200 viacurl)
Root cause: ad blockers (uBlock Origin / Brave Shields / AdBlock Plus / EasyPrivacy) match on filename patterns (recorder, autocapture, dead-clicks) regardless of host. A reverse proxy alone doesn't help — renaming on a different host still trips the same filter. Confirmation step: ask the user to disable their ad blocker on the page; if the requests succeed, this skill applies.
This skill applies the surgical fix: only those three files divert through the Next.js app under bland filenames. All other PostHog traffic (events, decide, config, recording uploads) keeps using the existing api_host.
Prerequisites to confirm before implementing
- The project is Next.js (App Router or Pages Router both fine) with
posthog-jsfrom npm. - Server-side:
curl -I https://<api_host>/static/dead-clicks-autocapture.js?v=1.xreturns 200. If it returns 404, the upstream proxy is misconfigured — fix that first, this skill won't help. - Identify the PostHog cloud region: US (
us-assets.i.posthog.com) or EU (eu-assets.i.posthog.com). Default to US if unclear, but ask. - Locate the existing
posthog.init(...)call (commonlysrc/lib/posthog.ts, a provider component, orapp/layout.tsx). Note the file so you can hook the rewriter before init. - Session replay must be enabled in the PostHog project dashboard (Settings → Project → Session replay → "Record user sessions"). If it's off, posthog-js never even tries to load the recorder, so this skill produces no visible effect. Surface this check to the user.
Implementation — three changes
1. Add rewrites to next.config.{ts,js,mjs}
Insert a rewrites() block. Use /_p/ as the alias prefix (or any path that doesn't contain words like recorder, analytics, tracking, posthog).
import type { NextConfig } from "next";
const PH_ASSETS = "https://us-assets.i.posthog.com"; // EU: "https://eu-assets.i.posthog.com"
const nextConfig: NextConfig = {
// ...existing config...
async rewrites() {
return [
{ source: "/_p/dc.js", destination: `${PH_ASSETS}/static/dead-clicks-autocapture.js` },
{ source: "/_p/r.js", destination: `${PH_ASSETS}/static/recorder.js` },
{ source: "/_p/r2.js", destination: `${PH_ASSETS}/static/posthog-recorder.js` },
];
},
};
export default nextConfig;Why all three: posthog-js renamed the recorder chunk across versions. Covering both recorder.js and posthog-recorder.js makes the skill version-resilient. Rewrites preserve the ?v=1.x.y query string automatically and incur no Node overhead.
If the project already has a rewrites() or redirects() block, merge rather than replace.
2. Create the script-tag rewriter
New file at src/lib/posthog-rewrite-loader.ts (adjust path to match the repo's lib convention):
const REWRITES: Array<[RegExp, string]> = [
[/\/static\/dead-clicks-autocapture\.js/, "/_p/dc.js"],
[/\/static\/posthog-recorder\.js/, "/_p/r2.js"],
[/\/static\/recorder\.js/, "/_p/r.js"],
];
export function installPostHogScriptRewriter() {
if (typeof window === "undefined") return;
const w = window as Window & { __phRewriteInstalled?: boolean };
if (w.__phRewriteInstalled) return;
w.__phRewriteInstalled = true;
const desc = Object.getOwnPropertyDescriptor(HTMLScriptElement.prototype, "src");
if (!desc?.set || !desc?.get) return;
Object.defineProperty(HTMLScriptElement.prototype, "src", {
configurable: true,
enumerable: true,
get() {
return desc.get!.call(this);
},
set(value: string) {
if (typeof value === "string") {
for (const [pattern, replacement] of REWRITES) {
if (pattern.test(value)) {
const qIndex = value.indexOf("?");
const query = qIndex >= 0 ? value.slice(qIndex) : "";
value = replacement + query; // strip host -> same-origin
break;
}
}
}
desc.set!.call(this, value);
},
});
}Notes:
- The
__phRewriteInstalledflag is required because Next.js dev HMR can re-execute modules andObject.definePropertywould otherwise throw. - Stripping the host (replacing the entire URL with
/_p/dc.js?v=...) makes the request same-origin, avoiding a CORS preflight on top of the blocker bypass. - The patcher targets the
srcproperty setter on the prototype — posthog-js loads chunks by settingscript.src, so this catches them. It does not catchfetch()or dynamicimport()(not used by posthog-js for these chunks today, but worth noting if a future SDK version changes).
3. Wire the rewriter to run before posthog.init
The patcher must be installed before any posthog.init call. Module-level code in the same file as posthog.init works because module evaluation precedes useEffect:
// src/lib/posthog.ts (or wherever posthog.init lives)
import posthog from "posthog-js";
import { installPostHogScriptRewriter } from "@/lib/posthog-rewrite-loader";
if (typeof window !== "undefined") {
installPostHogScriptRewriter();
}
export const initPostHog = () => {
if (typeof window !== "undefined") {
posthog.init(process.env.NEXT_PUBLIC_POSTHOG_KEY!, {
api_host: process.env.NEXT_PUBLIC_POSTHOG_HOST, // unchanged
// ...existing config...
});
}
};
export { posthog };If posthog.init is called from <Script strategy="beforeInteractive"> in app/layout.tsx instead of from a client module, put the patcher in its own <Script strategy="beforeInteractive"> block placed above the PostHog one. Don't use afterInteractive — by then posthog may have already started loading chunks.
Verification
- Server side — after deploy:
Both should return 200,curl -I "https://<your-domain>/_p/dc.js?v=1.0" curl -I "https://<your-domain>/_p/r2.js?v=1.0"content-type: text/javascript. If 404, the rewrite isn't picked up — Next.js needs a rebuild afternext.configchanges. - Browser with ad blocker enabled — in DevTools Network:
- Requests to
/_p/dc.jsand/_p/r2.jssucceed (200). - No
/static/dead-clicks-autocapture.jsor/static/posthog-recorder.jsrequests visible. - In uBlock Origin's Logger,
/_p/*entries should show--(allowed), not red.
- Requests to
- PostHog dashboard:
- Live Events shows dead-click events firing.
- Session replay shows recordings (allow ~5 min for ingestion).
- If recordings still don't appear, the issue is likely the dashboard toggle (Settings → Session replay), not this skill.
Common follow-ups and pitfalls
- "It still doesn't work after deploy" — rewrites only take effect after
next build. Local dev needsnpm run devrestart. Production needs a redeploy. - "A different chunk is now blocked" — surveys, web-vitals, exception-autocapture. Add a fourth rewrite + a fourth regex entry. Pattern is identical.
- "Capture endpoints are also blocked" —
/e/,/decide/,/array/*/config.jsgetting blocked is a different problem (host-level rather than filename-level). Solve with a PostHog reverse proxy on the user's own domain, not this skill. PostHog's docs cover that. - "Want to proxy everything through Next.js instead" — possible but discouraged. Session recording is high-volume (kilobytes per second per active user); routing through Next.js multiplies function invocations 10–100×. The PostHog-managed proxy is purpose-built for this load. Use full-proxy only if you have a hard CSP/compliance requirement.
- SDK upgrades — if posthog-js renames a chunk in a future version, the rewriter silently misses it. After upgrades, watch DevTools Network for any
/static/*.jsrequest leaking through and add a regex entry. - Network-level blockers (Pi-hole / NextDNS) blocking by domain are not bypassed by this. They're a much smaller cohort than browser extensions and your own domain isn't on their lists.
Files modified summary (template for the PR description)
| File | Change |
next.config.{ts,js} | Add rewrites() for /_p/dc.js, /_p/r.js, /_p/r2.js |
src/lib/posthog-rewrite-loader.ts | New — patches HTMLScriptElement.prototype.src |
src/lib/posthog.ts (or equivalent) | Call installPostHogScriptRewriter() at module load |
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

