Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Post Hog for A/B tests #1564

Merged
merged 12 commits into from
Jan 14, 2025
1 change: 1 addition & 0 deletions .github/workflows/production.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ jobs:
"PUBLIC_APPWRITE_FN_TLDR_ID=${{ vars.PUBLIC_APPWRITE_FN_TLDR_ID }}"
"PUBLIC_APPWRITE_PROJECT_INIT_ID=${{ vars.PUBLIC_APPWRITE_PROJECT_INIT_ID }}"
"PUBLIC_GROWTH_ENDPOINT=${{ vars.PUBLIC_GROWTH_ENDPOINT }}"
"PUBLIC_POSTHOG_API_KEY=${{ vars.PUBLIC_POSTHOG_API_KEY }}"
"APPWRITE_DB_INIT_ID=${{ secrets.APPWRITE_DB_INIT_ID }}"
"APPWRITE_COL_INIT_ID=${{ secrets.APPWRITE_COL_INIT_ID }}"
"APPWRITE_API_KEY_INIT=${{ secrets.APPWRITE_API_KEY_INIT }}"
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/staging.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ jobs:
"PUBLIC_APPWRITE_FN_TLDR_ID=${{ vars.PUBLIC_APPWRITE_FN_TLDR_ID }}"
"PUBLIC_APPWRITE_PROJECT_INIT_ID=${{ vars.PUBLIC_APPWRITE_PROJECT_INIT_ID }}"
"PUBLIC_GROWTH_ENDPOINT=${{ vars.PUBLIC_GROWTH_ENDPOINT }}"
"PUBLIC_POSTHOG_API_KEY=${{ vars.PUBLIC_POSTHOG_API_KEY }}"
"APPWRITE_DB_INIT_ID=${{ secrets.APPWRITE_DB_INIT_ID }}"
"APPWRITE_COL_INIT_ID=${{ secrets.APPWRITE_COL_INIT_ID }}"
"APPWRITE_API_KEY_INIT=${{ secrets.APPWRITE_API_KEY_INIT }}"
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ jobs:
PUBLIC_APPWRITE_FN_TLDR_ID: ${{ secrets.PUBLIC_APPWRITE_FN_TLDR_ID }}
PUBLIC_APPWRITE_PROJECT_INIT_ID: ${{ secrets.PUBLIC_APPWRITE_PROJECT_INIT_ID }}
PUBLIC_GROWTH_ENDPOINT: ${{ secrets.PUBLIC_GROWTH_ENDPOINT }}
PUBLIC_POSTHOG_API_KEY: ${{ vars.PUBLIC_POSTHOG_API_KEY }}
APPWRITE_DB_INIT_ID: ${{ secrets.APPWRITE_DB_INIT_ID }}
APPWRITE_COL_INIT_ID: ${{ secrets.APPWRITE_COL_INIT_ID }}
APPWRITE_API_KEY_INIT: ${{ secrets.APPWRITE_API_KEY_INIT }}
Expand Down
3 changes: 3 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ ENV GITHUB_TOKEN ${GITHUB_TOKEN}
ARG SENTRY_AUTH_TOKEN
ENV SENTRY_AUTH_TOKEN ${SENTRY_AUTH_TOKEN}

ARG PUBLIC_POSTHOG_API_KEY
ENV PUBLIC_POSTHOG_API_KEY ${PUBLIC_POSTHOG_API_KEY}

ENV PNPM_HOME="/pnpm"
ENV PATH="$PNPM_HOME:$PATH"

Expand Down
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@
"openapi-types": "^12.1.3",
"oslllo-svg-fixer": "^3.0.0",
"plausible-tracker": "^0.3.9",
"posthog-js": "^1.174.2",
"posthog-node": "^4.2.1",
"postcss": "^8.4.49",
"prettier": "^3.3.3",
"prettier-plugin-svelte": "^3.2.8",
Expand Down
106 changes: 106 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 6 additions & 1 deletion src/lib/system.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { dev } from '$app/environment';
import { PUBLIC_GROWTH_ENDPOINT } from '$env/static/public';
import { PUBLIC_GROWTH_ENDPOINT, PUBLIC_POSTHOG_API_KEY } from '$env/static/public';
import { PostHog } from 'posthog-node';

export const VARS = {
GROWTH_ENDPOINT: PUBLIC_GROWTH_ENDPOINT ?? undefined
Expand All @@ -11,3 +12,7 @@ export const ENV = {
PREVIEW: import.meta.env?.VERCEL === '1',
TEST: !!import.meta.env?.VITEST
};

export const posthog = new PostHog(PUBLIC_POSTHOG_API_KEY, {
host: 'https://eu.i.posthog.com'
});
11 changes: 11 additions & 0 deletions src/routes/+layout.server.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,20 @@
import posthog from 'posthog-js';
import { browser } from '$app/environment';

import { getAllChangelogEntries } from './changelog/utils';
import { PUBLIC_POSTHOG_API_KEY } from '$env/static/public';

export const prerender = true;
export const trailingSlash = 'never';

export const load = async () => {
if (browser) {
posthog.init(PUBLIC_POSTHOG_API_KEY, {
api_host: 'https://eu.i.posthog.com',
person_profiles: 'identified_only'
});
}

return {
changelogEntries: (await getAllChangelogEntries()).length
};
Expand Down
18 changes: 18 additions & 0 deletions src/routes/+page.server.ts
ernstmul marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// import { posthog } from '$lib/system';

// export const load = async () => {
// let ctaText = 'No variant';
// try {
// const distinctId = 'placeholder-user-id2';
// const enabledVariant = await posthog.getFeatureFlag('homepage_test', distinctId);
// if (enabledVariant === 'control') {
// ctaText = 'Control Variant';
// } else if (enabledVariant === 'test') {
// ctaText = 'Test Variant';
// }
// } catch (error) {
// ctaText = 'Error';
// console.error('Error fetching feature flag', error);
// }
// return { ctaText };
// };
3 changes: 1 addition & 2 deletions src/routes/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,6 @@
<span class="text-caption shrink-0 font-medium">New</span>
<div class="web-hero-banner-button-sep" />
<span class="text-caption web-u-trim-1">Introducing Database Backups</span>

<span class="web-icon-arrow-right shrink-0" aria-hidden="true" />
</a>
<Hero>
Expand Down Expand Up @@ -161,7 +160,7 @@
</section>
</div>
<div class="mb-12 lg:my-[7.5rem]">
<section class="container web-u-padding-block-0" style="--container-size:78.75rem">
<section class="web-u-padding-block-0 container" style="--container-size:78.75rem">
<div class="web-media-container">
<img
class="block"
Expand Down
Loading