Skip to main content

Function: withAnalyticsRewrites()

withAnalyticsRewrites<T>(nextConfig, options?): T
Defined in: next/index.ts:90 Wrap a Next.js config to add reverse-proxy rewrites for @resq-sw/analytics. Adds two rules to the beforeFiles rewrite array:
  1. /<prefix>/static/:path* → assetsUpstream/static/:path* (PostHog snippet bundle).
  2. /<prefix>/:path* → upstream/:path* (everything else: capture, decide, /e/).
Pre-existing user-defined rewrites are preserved — the proxy rules go first so they win when paths overlap. Also forces skipTrailingSlashRedirect: true, which is required for the proxy to work reliably across /ingest and /ingest/.

Type Parameters

T

T extends MinimalNextConfig The user’s full next.config.{js,ts} type.

Parameters

nextConfig

T

options?

AnalyticsRewriteOptions = {}

Returns

T

Example

import { withAnalyticsRewrites } from "@resq-sw/analytics/next";

export default withAnalyticsRewrites({
  reactStrictMode: true,
  // ...rest of your config
});