Skip to content

docker: forward NEXT_PUBLIC_POSTHOG_TOKEN into the build stage#21

Merged
xrendan merged 1 commit into
mainfrom
fix/posthog-build-arg
Jun 2, 2026
Merged

docker: forward NEXT_PUBLIC_POSTHOG_TOKEN into the build stage#21
xrendan merged 1 commit into
mainfrom
fix/posthog-build-arg

Conversation

@xrendan
Copy link
Copy Markdown
Member

@xrendan xrendan commented Jun 2, 2026

Summary

PostHog wasn't loading on prod (www.buildcanada.com). Root cause: the Dockerfile's builder stage never declared ARG NEXT_PUBLIC_POSTHOG_TOKEN, and Docker silently drops --build-arg values without a matching ARG. The token therefore never reached next build, so it was never inlined into the client bundles — the posthog.init() guard in instrumentation-client.ts evaluated undefined in the browser and init never ran.

Verified against the deployed bundles: the compiled init is still a runtime process.env lookup (empty polyfill in the browser) and no phc_ token string exists anywhere in the chunks, while NEXT_PUBLIC_SITE_URL (which does have an ARG) took effect on the same rebuild.

Changes

  • Add ARG NEXT_PUBLIC_POSTHOG_TOKEN + ENV forwarding in the builder stage so the deploy's existing --build-arg actually reaches next build.

Testing

After this merges and prod rebuilds (with --build-arg NEXT_PUBLIC_POSTHOG_TOKEN=phc_... passed):

  • Client chunk hashes should change
  • phc_ token should appear inlined in the instrumentation chunk
  • posthog.__loaded === true in the prod console, events visible in PostHog

Docker silently drops --build-arg values without a matching ARG
declaration, so the PostHog token never reached next build and was
never inlined into the client bundles — posthog.init() guard stayed
undefined in prod.
@xrendan xrendan merged commit 59c15c6 into main Jun 2, 2026
1 check 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