From 656b08c786fc955c16547259e067f74a6d9d7932 Mon Sep 17 00:00:00 2001 From: Jesse Winton Date: Fri, 18 Oct 2024 16:09:04 -0400 Subject: [PATCH 01/31] implement --- package.json | 2 + pnpm-lock.yaml | 106 +++++++++++++++++++++++++++ src/lib/components/InitBanner.svelte | 1 + src/lib/components/IsLoggedIn.svelte | 7 +- src/lib/system.ts | 7 +- src/routes/+layout.server.ts | 11 +++ src/routes/+page.server.ts | 17 +++++ src/routes/+page.svelte | 8 +- 8 files changed, 152 insertions(+), 7 deletions(-) create mode 100644 src/routes/+page.server.ts diff --git a/package.json b/package.json index 541099ba98..483ecdaa02 100644 --- a/package.json +++ b/package.json @@ -68,6 +68,8 @@ "oslllo-svg-fixer": "^3.0.0", "plausible-tracker": "^0.3.9", "postcss": "^8.4.39", + "posthog-js": "^1.174.2", + "posthog-node": "^4.2.1", "prettier": "^3.3.3", "prettier-plugin-svelte": "^3.2.5", "prettier-plugin-tailwindcss": "^0.6.6", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 09f5c6318d..d0ff6db7dc 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -138,6 +138,12 @@ importers: postcss: specifier: ^8.4.39 version: 8.4.47 + posthog-js: + specifier: ^1.174.2 + version: 1.174.2 + posthog-node: + specifier: ^4.2.1 + version: 4.2.1 prettier: specifier: ^3.3.3 version: 3.3.3 @@ -1966,10 +1972,16 @@ packages: async@3.2.6: resolution: {integrity: sha512-htCUDlxyyCLMgaM3xXg0C0LW2xqfuQ6p05pCEIsXuyQ+a1koYKTuBMzRNwmybfLgvJDMd0r1LTn4+E0Ti6C2AA==} + asynckit@0.4.0: + resolution: {integrity: sha512-Oei9OH4tRh0YqU3GxhX79dM/mwVgvbZJaSNaRk+bshkj0S5cfHcgYakreBjrHwatXKbz+IoIdYLxrKim2MjW0Q==} + auto-config-loader@1.7.7: resolution: {integrity: sha512-PdqcwqgJGRGU9itaMt5IAVTQODHaleUapMljNQeRt0q/qXVxru7sQa/t545XazsGn80ipZ4rp+cFUsTHP0FuBQ==} engines: {node: '>=16.0.0'} + axios@1.7.7: + resolution: {integrity: sha512-S4kL7XrjgBmvdGut0sN3yJxqYzrDOnivkBiN0OFs6hLiUam3UPvswUo0kqGyhqUZGEOytHyumEdXsAkgCOUf3Q==} + axobject-query@4.1.0: resolution: {integrity: sha512-qIj0G9wZbMGNLjLmg1PT6v2mE9AH2zlnADJD/2tC6E00hgmhUOfEB6greHPAfLRSufHqROIUTkw6E+M3lH0PTQ==} engines: {node: '>= 0.4'} @@ -2135,6 +2147,10 @@ packages: resolution: {integrity: sha512-PWGsmoJFdOB0t+BeHgmtuoRZUQucOLl5ii81NBzOOGVxlgE04muFNHlR5j8i8MKbOPELBl3243AI6lGBTj5ICQ==} hasBin: true + combined-stream@1.0.8: + resolution: {integrity: sha512-FQN4MRfuJeHf7cBbBMJFXhKSDq+2kAArBlmRBvcvFE5BB1HZKXtSFASDhdlz9zOYwxh8lDdnvmMOe/+5cdoEdg==} + engines: {node: '>= 0.8'} + commander@4.1.1: resolution: {integrity: sha512-NOKm8xhkzAjzFx8B2v5OAHT+u5pRQc2UCa2Vq9jYL/31o2wi9mxBA7LIFs3sV5VSC49z6pEhfbMULvShKj26WA==} engines: {node: '>= 6'} @@ -2173,6 +2189,9 @@ packages: resolution: {integrity: sha512-U71cyTamuh1CRNCfpGY6to28lxvNwPG4Guz/EVjgf3Jmzv0vlDp1atT9eS5dDjMYHucpHbWns6Lwf3BKz6svdw==} engines: {node: '>= 0.6'} + core-js@3.38.1: + resolution: {integrity: sha512-OP35aUorbU3Zvlx7pjsFdu1rGNnD4pgw/CWoYzRY3t2EzoVT7shKHY1dlAy3f41cGIO7ZDPQimhGFTlEYkG/Hw==} + core-util-is@1.0.3: resolution: {integrity: sha512-ZQBvi1DcpJ4GDqanjucZ2Hj3wEO5pZDS89BWbkcrvdxksJorwUDDZamX9ldFkp9aw2lmBDLgkObEA4DWNJ9FYQ==} @@ -2243,6 +2262,10 @@ packages: resolution: {integrity: sha512-ua8BhapfP0JUJKC/zV9yHHDW/rDoDxP4Zhn3AkA6/xT6gY7jYXJiaeyBZznYVujhZZET+UgcbZiQ7sN3WqcImg==} engines: {node: '>=10'} + delayed-stream@1.0.0: + resolution: {integrity: sha512-ZySD7Nf91aLB0RxL4KGrKHBXl7Eds1DAmEdcoVawXnLD7SDhpNgtuII2aAkg7a7QS41jxPSZ17p4VdGnMHk3MQ==} + engines: {node: '>=0.4.0'} + delegates@1.0.0: resolution: {integrity: sha512-bd2L678uiWATM6m5Z1VzNCErI3jiGzt6HGY8OVICs40JQq/HALfbyNJmp0UDakEY4pMMaN0Ly5om/B1VI/+xfQ==} @@ -2482,6 +2505,9 @@ packages: fastq@1.17.1: resolution: {integrity: sha512-sRVD3lWVIXWg6By68ZN7vho9a1pQcN/WBFaAAsDDFzlJjvoGx0P8z7V1t72grFJfJhu3YPZBuu25f7Kaw2jN1w==} + fflate@0.4.8: + resolution: {integrity: sha512-FJqqoDBR00Mdj9ppamLa/Y7vxm+PRmNWA67N846RvsoYVMKB4q3y/de5PA7gUmRMYK/8CMz2GDZQmCRN1wBcWA==} + file-entry-cache@6.0.1: resolution: {integrity: sha512-7Gps/XWymbLk2QLYK4NzpMOrYjMhdIxXuIvy2QBsLE6ljuodKvdkWs/cpyJJ3CVIVpH0Oi1Hvg1ovbMzLdFBBg==} engines: {node: ^10.12.0 || >=12.0.0} @@ -2527,6 +2553,10 @@ packages: resolution: {integrity: sha512-Ld2g8rrAyMYFXBhEqMz8ZAHBi4J4uS1i/CxGMDnjyFWddMXLVcDp051DZfu+t7+ab7Wv6SMqpWmyFIj5UbfFvg==} engines: {node: '>=14'} + form-data@4.0.1: + resolution: {integrity: sha512-tzN8e4TX8+kkxGPK8D5u0FNmjPUjw3lwC9lSLxxoB/+GtsJG91CO8bSWy73APlgAZzZbXEYZJuxjkHH2w+Ezhw==} + engines: {node: '>= 6'} + fs-extra@11.2.0: resolution: {integrity: sha512-PmDi3uwK5nFuXh7XDTlVnS17xJS7vW36is2+w3xcv8SVxiB4NyATf4ctkVY5bkSjX0Y4nbvZCq1/EjtEyr9ktw==} engines: {node: '>=14.14'} @@ -3046,6 +3076,14 @@ packages: resolution: {integrity: sha512-PXwfBhYu0hBCPw8Dn0E+WDYb7af3dSLVWKi3HGv84IdF4TyFoC0ysxFd0Goxw7nSv4T/PzEJQxsYsEiFCKo2BA==} engines: {node: '>=8.6'} + mime-db@1.52.0: + resolution: {integrity: sha512-sPU4uV7dYlvtWJxwwxHD0PuihVNiE7TyAbQ5SWxDCB9mUYvOgroQOwYQQOKPJ8CIbE+1ETVlOoK1UC2nU3gYvg==} + engines: {node: '>= 0.6'} + + mime-types@2.1.35: + resolution: {integrity: sha512-ZDY+bPm5zTTF+YpCrAU9nK0UgICYPT0QtT1NZWFv4s++TNkcgVaT0g6+4R2uI4MjQjzysHB1zxuWL50hzaeXiw==} + engines: {node: '>= 0.6'} + mime@1.6.0: resolution: {integrity: sha512-x0Vn8spI+wuJ1O6S7gnbaQg8Pxh4NNHb7KSINmEWKiPE4RKOplvijn+NkmYmmRgP68mc70j2EbeTFRsrswaQeg==} engines: {node: '>=4'} @@ -3479,6 +3517,16 @@ packages: resolution: {integrity: sha512-9ZhXKM/rw350N1ovuWHbGxnGh/SNJ4cnxHiM0rxE4VN41wsg8P8zWn9hv/buK00RP4WvlOyr/RBDiptyxVbkZQ==} engines: {node: '>=0.10.0'} + posthog-js@1.174.2: + resolution: {integrity: sha512-UgS7eRcDVvVz2XSJ09NMX8zBcdpFnPayfiWDNF3xEbJTsIu1GipkkYNrVlsWlq8U1PIrviNm6i0Dyq8daaxssw==} + + posthog-node@4.2.1: + resolution: {integrity: sha512-l+fsjYEkTik3m/G0pE7gMr4qBJP84LhK779oQm6MBzhBGpd4By4qieTW+4FUAlNCyzQTynn3Nhsa50c0IELSxQ==} + engines: {node: '>=15.0.0'} + + preact@10.24.3: + resolution: {integrity: sha512-Z2dPnBnMUfyQfSQ+GBdsGa16hz35YmLmtTLhM169uW944hYL6xzTYkJjC07j+Wosz733pMWx0fgON3JNw1jJQA==} + prelude-ls@1.2.1: resolution: {integrity: sha512-vkcDPrRZo1QZLbn5RLGPpg/WmIQ65qoWWhcGKf/b5eplkkarX0m9z8ppCat4mlOqUsWpyNuYgO3VRyrYHSzX5g==} engines: {node: '>= 0.8.0'} @@ -3676,6 +3724,9 @@ packages: run-parallel@1.2.0: resolution: {integrity: sha512-5l4VyZR86LZ/lDxZTR6jqL8AFE2S0IFLMP26AbjsLVADxHdhB/c0GUsH+y39UfCi3dzz8OlQuPmnaJOMoDHQBA==} + rusha@0.8.14: + resolution: {integrity: sha512-cLgakCUf6PedEu15t8kbsjnwIFFR2D4RfL+W3iWFJ4iac7z4B0ZI8fxy4R3J956kAI68HclCFGL8MPoUVC3qVA==} + sade@1.8.1: resolution: {integrity: sha512-xal3CZX1Xlo/k4ApwCFrHVACi9fBqJ7V+mwhBsuf/1IOKbBy098Fex+Wa/5QMubw09pSZ/u8EY8PWgevJsXp1A==} engines: {node: '>=6'} @@ -4218,6 +4269,9 @@ packages: jsdom: optional: true + web-vitals@4.2.3: + resolution: {integrity: sha512-/CFAm1mNxSmOj6i0Co+iGFJ58OS4NRGVP+AWS/l509uIK5a1bSoIVaHz/ZumpHTfHSZBpgrJ+wjfpAOrTHok5Q==} + webidl-conversions@3.0.1: resolution: {integrity: sha512-2JAn3z8AR6rjK8Sm8orRC0h/bcl/DqL7tRPdGZ4I1CjdF+EaMLmYxBHyXuKL849eucPFhvBoxMsflfOb8kxaeQ==} @@ -6258,6 +6312,8 @@ snapshots: async@3.2.6: {} + asynckit@0.4.0: {} + auto-config-loader@1.7.7: dependencies: ini: 4.1.3 @@ -6268,6 +6324,14 @@ snapshots: toml-eslint-parser: 0.9.3 yaml-eslint-parser: 1.2.3 + axios@1.7.7: + dependencies: + follow-redirects: 1.15.9 + form-data: 4.0.1 + proxy-from-env: 1.1.0 + transitivePeerDependencies: + - debug + axobject-query@4.1.0: {} balanced-match@1.0.2: {} @@ -6480,6 +6544,10 @@ snapshots: colors-cli@1.0.33: {} + combined-stream@1.0.8: + dependencies: + delayed-stream: 1.0.0 + commander@4.1.1: {} commander@7.2.0: {} @@ -6502,6 +6570,8 @@ snapshots: cookie@0.6.0: {} + core-js@3.38.1: {} + core-util-is@1.0.3: {} cross-fetch@3.1.8(encoding@0.1.13): @@ -6575,6 +6645,8 @@ snapshots: rimraf: 3.0.2 slash: 3.0.0 + delayed-stream@1.0.0: {} + delegates@1.0.0: {} dequal@2.0.3: {} @@ -6850,6 +6922,8 @@ snapshots: dependencies: reusify: 1.0.4 + fflate@0.4.8: {} + file-entry-cache@6.0.1: dependencies: flat-cache: 3.2.0 @@ -6894,6 +6968,12 @@ snapshots: cross-spawn: 7.0.3 signal-exit: 4.1.0 + form-data@4.0.1: + dependencies: + asynckit: 0.4.0 + combined-stream: 1.0.8 + mime-types: 2.1.35 + fs-extra@11.2.0: dependencies: graceful-fs: 4.2.11 @@ -7421,6 +7501,12 @@ snapshots: braces: 3.0.3 picomatch: 2.3.1 + mime-db@1.52.0: {} + + mime-types@2.1.35: + dependencies: + mime-db: 1.52.0 + mime@1.6.0: {} mime@3.0.0: {} @@ -7831,6 +7917,22 @@ snapshots: dependencies: xtend: 4.0.2 + posthog-js@1.174.2: + dependencies: + core-js: 3.38.1 + fflate: 0.4.8 + preact: 10.24.3 + web-vitals: 4.2.3 + + posthog-node@4.2.1: + dependencies: + axios: 1.7.7 + rusha: 0.8.14 + transitivePeerDependencies: + - debug + + preact@10.24.3: {} + prelude-ls@1.2.1: {} prettier-plugin-svelte@3.2.7(prettier@3.3.3)(svelte@4.2.19): @@ -7984,6 +8086,8 @@ snapshots: dependencies: queue-microtask: 1.2.3 + rusha@0.8.14: {} + sade@1.8.1: dependencies: mri: 1.2.0 @@ -8568,6 +8672,8 @@ snapshots: - supports-color - terser + web-vitals@4.2.3: {} + webidl-conversions@3.0.1: {} webpack-sources@3.2.3: {} diff --git a/src/lib/components/InitBanner.svelte b/src/lib/components/InitBanner.svelte index df8e9981f4..a0d0a71a81 100644 --- a/src/lib/components/InitBanner.svelte +++ b/src/lib/components/InitBanner.svelte @@ -1,5 +1,6 @@ @@ -10,7 +10,10 @@ trackEvent('Get started/go to console in header')} + on:click={() => { + handleClick(); + trackEvent('Get started/go to console in header'); + }} > Get started diff --git a/src/lib/system.ts b/src/lib/system.ts index d0ecd55fb8..5bdf5f1cc1 100644 --- a/src/lib/system.ts +++ b/src/lib/system.ts @@ -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 @@ -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://us.i.posthog.com' +}); diff --git a/src/routes/+layout.server.ts b/src/routes/+layout.server.ts index b5d99caa3b..e1b43bc061 100644 --- a/src/routes/+layout.server.ts +++ b/src/routes/+layout.server.ts @@ -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://us.i.posthog.com', + person_profiles: 'identified_only' + }); + } + return { changelogEntries: (await getAllChangelogEntries()).length }; diff --git a/src/routes/+page.server.ts b/src/routes/+page.server.ts new file mode 100644 index 0000000000..5740b2529c --- /dev/null +++ b/src/routes/+page.server.ts @@ -0,0 +1,17 @@ +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'; + } + return { ctaText }; +}; diff --git a/src/routes/+page.svelte b/src/routes/+page.svelte index 0b7bf279e9..f59bc53f07 100644 --- a/src/routes/+page.svelte +++ b/src/routes/+page.svelte @@ -17,6 +17,8 @@ import Badge from '$lib/components/ui/Badge.svelte'; import { trackEvent } from '$lib/actions/analytics'; + export let data; + const title = 'Appwrite - Build like a team of hundreds'; const description = DEFAULT_DESCRIPTION; const ogImage = `${DEFAULT_HOST}/images/open-graph/website.png`; @@ -129,9 +131,7 @@
- Introducing Database Backups + Introducing Database Backups @@ -152,7 +152,7 @@ slot="cta" on:click={() => trackEvent('Get started in hero')} > - Get started + {data.ctaText} From a2b128f7806d8bd05beb3c4856c97978a36ac0c9 Mon Sep 17 00:00:00 2001 From: Jesse Winton Date: Mon, 18 Nov 2024 09:34:57 -0500 Subject: [PATCH 02/31] Update +page.server.ts --- src/routes/+page.server.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/src/routes/+page.server.ts b/src/routes/+page.server.ts index 5740b2529c..7e01c01838 100644 --- a/src/routes/+page.server.ts +++ b/src/routes/+page.server.ts @@ -12,6 +12,7 @@ export const load = async () => { } } catch (error) { ctaText = 'Error'; + console.error('Error fetching feature flag', error); } return { ctaText }; }; From ba0f57ea67f13a5c7525d4487f945151683a3fa2 Mon Sep 17 00:00:00 2001 From: Jesse Winton Date: Thu, 19 Dec 2024 09:28:27 -0800 Subject: [PATCH 03/31] rm test experiment --- src/lib/components/InitBanner.svelte | 1 - src/lib/components/IsLoggedIn.svelte | 2 -- src/routes/+page.server.ts | 34 ++++++++++++++-------------- src/routes/+page.svelte | 8 +++---- 4 files changed, 20 insertions(+), 25 deletions(-) diff --git a/src/lib/components/InitBanner.svelte b/src/lib/components/InitBanner.svelte index a0d0a71a81..df8e9981f4 100644 --- a/src/lib/components/InitBanner.svelte +++ b/src/lib/components/InitBanner.svelte @@ -1,6 +1,5 @@ @@ -11,7 +10,6 @@ class={classNames('web-button web-u-inline-width-100-percent-mobile', classes)} href={PUBLIC_APPWRITE_DASHBOARD} on:click={() => { - handleClick(); trackEvent('Get started/go to console in header'); }} > diff --git a/src/routes/+page.server.ts b/src/routes/+page.server.ts index 7e01c01838..6adccc3ab4 100644 --- a/src/routes/+page.server.ts +++ b/src/routes/+page.server.ts @@ -1,18 +1,18 @@ -import { posthog } from '$lib/system'; +// 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 }; -}; +// 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 }; +// }; diff --git a/src/routes/+page.svelte b/src/routes/+page.svelte index 547f354a0a..7969ab5aab 100644 --- a/src/routes/+page.svelte +++ b/src/routes/+page.svelte @@ -17,8 +17,6 @@ import Badge from '$lib/components/ui/Badge.svelte'; import { trackEvent } from '$lib/actions/analytics'; - export let data; - const title = 'Appwrite - Build like a team of hundreds'; const description = DEFAULT_DESCRIPTION; const ogImage = `${DEFAULT_HOST}/images/open-graph/website.png`; @@ -152,7 +150,7 @@ slot="cta" on:click={() => trackEvent('Get started in hero')} > - {data.ctaText} + Get started @@ -305,10 +303,10 @@