Posthog Adblock Bypass logo

Posthog Adblock Bypass

OrganizationPopular
Leanmcp
posthog-adblock-bypass

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.

Overview

PublisherLeanmcp
Repositorygateway-skills
Skill nameposthog-adblock-bypass
Stars
2.1K
Forks
2.1K
Bundled files
2
LicenseMIT
Links
  • Markdown instructions

    A SKILL.md file the model loads on demand, so it only costs tokens when a request actually matches.

  • Works with any LLM

    AI skills are plain Markdown, not provider-specific code, so this works with GPT, Claude, Gemini, Grok, or a local model.

  • 2 bundled files

    Scripts, templates, and references the model can read while it works. Files are read-only and never executed.

  • Open source

    Published by Leanmcp on GitHub. Read the source before you install it.

Installation

Install the Posthog Adblock Bypass AI skill in TypingMind to use it with any LLM, or drop it into another agent that reads SKILL.md.

1

Install in TypingMind

TypingMind installs a skill straight from its GitHub folder — it reads SKILL.md, bundles the resource files, and stores the result locally.

  1. Open the app and go to Plugins → Skills.
  2. Choose "Install from GitHub".
  3. Paste the skill folder URL below and confirm.
    https://github.com/Leanmcp/gateway-skills/tree/main/skills/posthog-adblock-bypass
  4. Enable the skill in any chat where you want it available.
Plugins → Skills → Add skill → From GitHub URL, then paste the folder URL and press Continue.
2

Install in another agent

Any agent that reads the Agent Skills format can use this skill — copy the folder into that agent's skills directory.

Claude Code — .claude/skills
git clone --depth 1 https://github.com/Leanmcp/gateway-skills.git /tmp/gateway-skills
mkdir -p .claude/skills
cp -r /tmp/gateway-skills/skills/posthog-adblock-bypass .claude/skills/posthog-adblock-bypass
Restart Claude Code after copying so it picks up the new skill.

Use it in TypingMind

Enable Posthog Adblock Bypass in any TypingMind chat and the model takes it from there. Its name and description sit in the system prompt, and the moment a request matches, the model loads the full instructions itself — you never invoke it by hand, and it costs no tokens until it is actually used.

The model loads Posthog Adblock Bypass on its own as soon as a request matches it.

Works with any AI model

AI skills are plain Markdown instructions rather than provider-specific code, so Posthog Adblock Bypass is not tied to the model it was written for. Install it once in TypingMind and use it with GPT-5, Claude, Gemini, Grok, DeepSeek, Mistral, Llama, or a local model you run yourself — all on your own API keys.

  • Loaded only when it is needed

    The system prompt carries just the name and description. The instructions are fetched on the first matching request, so an idle skill costs nothing.

  • Switch models mid-chat

    Because the skill is instructions rather than code, changing model does not break it — the next model reads the same SKILL.md.

Skill instructions

This is the SKILL.md content the model loads. Read it before installing — a skill is instructions your model will follow.

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.js failing
  • /static/recorder.js or /static/posthog-recorder.js failing
  • ERR_BLOCKED_BY_CLIENT or a synthesized 404 (the file actually returns 200 via curl)

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

  1. The project is Next.js (App Router or Pages Router both fine) with posthog-js from npm.
  2. Server-side: curl -I https://<api_host>/static/dead-clicks-autocapture.js?v=1.x returns 200. If it returns 404, the upstream proxy is misconfigured — fix that first, this skill won't help.
  3. 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.
  4. Locate the existing posthog.init(...) call (commonly src/lib/posthog.ts, a provider component, or app/layout.tsx). Note the file so you can hook the rewriter before init.
  5. 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).

ts
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):

ts
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 __phRewriteInstalled flag is required because Next.js dev HMR can re-execute modules and Object.defineProperty would 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 src property setter on the prototype — posthog-js loads chunks by setting script.src, so this catches them. It does not catch fetch() or dynamic import() (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:

ts
// 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

  1. Server side — after deploy:

    bash
    curl -I "https://<your-domain>/_p/dc.js?v=1.0"
    curl -I "https://<your-domain>/_p/r2.js?v=1.0"

    Both should return 200, content-type: text/javascript. If 404, the rewrite isn't picked up — Next.js needs a rebuild after next.config changes.

  2. Browser with ad blocker enabled — in DevTools Network:

    • Requests to /_p/dc.js and /_p/r2.js succeed (200).
    • No /static/dead-clicks-autocapture.js or /static/posthog-recorder.js requests visible.
    • In uBlock Origin's Logger, /_p/* entries should show -- (allowed), not red.
  3. 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 needs npm run dev restart. 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.js getting 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/*.js request 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)

FileChange
next.config.{ts,js}Add rewrites() for /_p/dc.js, /_p/r.js, /_p/r2.js
src/lib/posthog-rewrite-loader.tsNew — patches HTMLScriptElement.prototype.src
src/lib/posthog.ts (or equivalent)Call installPostHogScriptRewriter() at module load

Bundled files

The model reads these on demand while the skill is loaded. They are exposed as readable files and are never executed.

Frequently asked questions

What does the Posthog Adblock Bypass AI skill do?

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 blocke...

Why use Posthog Adblock Bypass on TypingMind?

Because you install it once and use it with any model. Posthog Adblock Bypass is plain Markdown rather than provider-specific code, so the same skill runs on GPT-5, Claude, Gemini, Grok, or a local model — and you can switch model mid-chat without it breaking. TypingMind runs on your own API keys, so you pay providers directly instead of a per-seat subscription, and your skills and chats stay in your own storage.

How do I install Posthog Adblock Bypass in TypingMind?

Open Plugins → Skills → Install from GitHub in TypingMind and paste https://github.com/Leanmcp/gateway-skills/tree/main/skills/posthog-adblock-bypass. TypingMind reads its SKILL.md and bundles its files and installs it as a skill you can enable per chat.

Which AI models can use Posthog Adblock Bypass?

Any model you connect in TypingMind. AI skills are plain Markdown instructions rather than provider-specific code, so GPT, Claude, Gemini, Grok, and local models can all load this skill when a request matches it.

How many AI models can I use with Posthog Adblock Bypass?

As many as you like. As long as a model supports skills, you can use Posthog Adblock Bypass with it — GPT, Claude, Gemini, Grok, DeepSeek, Mistral, Llama and more — all on TypingMind with your own API keys.

Is the Posthog Adblock Bypass AI skill free?

Yes. It is published on GitHub by Leanmcp under the MIT license. You only pay your own AI provider for the tokens you use.

What are AI skills?

An AI skill is a reusable instruction bundle that teaches an AI model how to do one specific task. It follows the open Agent Skills format: a SKILL.md file with a name and description, plus any scripts, templates or reference files the model may need. The model reads the instructions only when your request matches the skill, so an installed skill costs nothing until it is used.

How are AI skills different from plugins or MCP servers?

A plugin or MCP server gives a model new tools to call — code that runs somewhere and returns a result. An AI skill gives the model knowledge and process instead: how to approach a task, which steps to follow, what good output looks like. Skills are plain Markdown, so they need no server, no API key and no runtime, and they work with any model.

View all

Set up your own AI workspace now

Get notified about new features and future giveaways by subscribing to our newsletter 👇