mirror of
https://github.com/LukeHagar/website.git
synced 2025-12-09 12:57:48 +00:00
fix: posthog api key issues.
This commit is contained in:
@@ -10,5 +10,4 @@ PUBLIC_POSTHOG_API_KEY=
|
|||||||
APPWRITE_DB_INIT_ID=
|
APPWRITE_DB_INIT_ID=
|
||||||
APPWRITE_COL_INIT_ID=
|
APPWRITE_COL_INIT_ID=
|
||||||
APPWRITE_API_KEY_INIT=
|
APPWRITE_API_KEY_INIT=
|
||||||
SENTRY_AUTH_TOKEN=
|
SENTRY_AUTH_TOKEN=
|
||||||
PUBLIC_POSTHOG_API_KEY=
|
|
||||||
@@ -1,10 +1,12 @@
|
|||||||
import { PUBLIC_POSTHOG_API_KEY } from '$env/static/public';
|
import { PUBLIC_POSTHOG_API_KEY } from '$env/static/public';
|
||||||
import { PostHog } from 'posthog-node';
|
import { PostHog } from 'posthog-node';
|
||||||
|
|
||||||
export const posthogServerClient = new PostHog(PUBLIC_POSTHOG_API_KEY, {
|
export const posthogServerClient = PUBLIC_POSTHOG_API_KEY
|
||||||
host: 'https://eu.i.posthog.com',
|
? new PostHog(PUBLIC_POSTHOG_API_KEY, {
|
||||||
persistence: 'memory'
|
host: 'https://eu.i.posthog.com',
|
||||||
});
|
persistence: 'memory'
|
||||||
|
})
|
||||||
|
: null;
|
||||||
|
|
||||||
export const experiments = {
|
export const experiments = {
|
||||||
'sticky-navigation_ab-test': ['control', 'sticky-nav']
|
'sticky-navigation_ab-test': ['control', 'sticky-nav']
|
||||||
@@ -24,7 +26,8 @@ export const getFeatureFlag = async <K extends Key>(
|
|||||||
variant: (typeof experiments)[K][number],
|
variant: (typeof experiments)[K][number],
|
||||||
distinctId: string
|
distinctId: string
|
||||||
) => {
|
) => {
|
||||||
const flagData = await posthogServerClient.getFeatureFlag(key, distinctId);
|
/* experiments won't work on previews or on local if api key is not available */
|
||||||
|
const flagData = (await posthogServerClient?.getFeatureFlag(key, distinctId)) ?? false;
|
||||||
|
|
||||||
return isFlagEqualTo(variant, flagData);
|
return isFlagEqualTo(variant, flagData);
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ import { PUBLIC_POSTHOG_API_KEY } from '$env/static/public';
|
|||||||
import posthog from 'posthog-js';
|
import posthog from 'posthog-js';
|
||||||
|
|
||||||
export const load = async ({ data }) => {
|
export const load = async ({ data }) => {
|
||||||
if (browser) {
|
if (browser && PUBLIC_POSTHOG_API_KEY) {
|
||||||
posthog.init(PUBLIC_POSTHOG_API_KEY, {
|
posthog.init(PUBLIC_POSTHOG_API_KEY, {
|
||||||
api_host: 'https://eu.i.posthog.com',
|
api_host: 'https://eu.i.posthog.com',
|
||||||
persistence: 'memory',
|
persistence: 'memory',
|
||||||
|
|||||||
Reference in New Issue
Block a user