The default postHogAdapter singleton in @flags-sdk/posthog calls assertEnv("NEXT_PUBLIC_POSTHOG_KEY")
|
postHogKey: assertEnv('NEXT_PUBLIC_POSTHOG_KEY'), |
, but the Vercel PostHog integration provisions
NEXT_PUBLIC_POSTHOG_PROJECT_TOKEN. This means installing both the integration and using the Flags SDK in your project doesn't produce a working setup. Flags silently fail to evaluate.
I was able to workaround this using the createPostHogAdapter explicitly instead of letting the default singleton do its job.
import { createPostHogAdapter } from "@flags-sdk/posthog";
const postHogAdapter = createPostHogAdapter({
postHogKey: process.env.NEXT_PUBLIC_POSTHOG_PROJECT_TOKEN!,
postHogOptions: {
host: process.env.NEXT_PUBLIC_POSTHOG_HOST ?? "https://us.posthog.com",
},
});
I suggest the SDK try NEXT_PUBLIC_POSTHOG_PROJECT_TOKEN when NEXT_PUBLIC_POSTHOG_KEY is not set as it would provide the most seamless experience for implementers. However, this does make assumptions that the PostHog integration won't change on you in the future.
The default
postHogAdaptersingleton in@flags-sdk/posthogcallsassertEnv("NEXT_PUBLIC_POSTHOG_KEY")flags/packages/adapter-posthog/src/index.ts
Line 113 in f4b2ec2
NEXT_PUBLIC_POSTHOG_PROJECT_TOKEN. This means installing both the integration and using the Flags SDK in your project doesn't produce a working setup. Flags silently fail to evaluate.I was able to workaround this using the
createPostHogAdapterexplicitly instead of letting the default singleton do its job.I suggest the SDK try
NEXT_PUBLIC_POSTHOG_PROJECT_TOKENwhenNEXT_PUBLIC_POSTHOG_KEYis not set as it would provide the most seamless experience for implementers. However, this does make assumptions that the PostHog integration won't change on you in the future.