From 841cc2ac4d80e66895217b31e85e67a11a8a757d Mon Sep 17 00:00:00 2001 From: kaaps Date: Mon, 18 Dec 2023 11:41:44 +0000 Subject: [PATCH 1/3] feat: posthog --- .vscode/settings.json | 2 +- package-lock.json | 14 ++++++++++++++ package.json | 1 + src/routes/+layout.svelte | 10 +++++++++- 4 files changed, 25 insertions(+), 2 deletions(-) diff --git a/.vscode/settings.json b/.vscode/settings.json index 27281fd4..d6a7f1db 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -6,7 +6,7 @@ }, "editor.formatOnSave": true, "editor.codeActionsOnSave": { - "source.fixAll": true + "source.fixAll": "explicit" }, "eslint.validate": ["svelte"] } diff --git a/package-lock.json b/package-lock.json index a346fc34..a6de4d6c 100644 --- a/package-lock.json +++ b/package-lock.json @@ -16,6 +16,7 @@ "@significa/svelte-ui": "^0.0.28", "@storyblok/js": "^2.3.0", "matter-js": "^0.19.0", + "posthog-js": "^1.96.1", "prism-svelte": "^0.5.0", "svelte-confetti": "^1.3.0" }, @@ -4881,6 +4882,11 @@ "reusify": "^1.0.4" } }, + "node_modules/fflate": { + "version": "0.4.8", + "resolved": "https://registry.npmjs.org/fflate/-/fflate-0.4.8.tgz", + "integrity": "sha512-FJqqoDBR00Mdj9ppamLa/Y7vxm+PRmNWA67N846RvsoYVMKB4q3y/de5PA7gUmRMYK/8CMz2GDZQmCRN1wBcWA==" + }, "node_modules/file-entry-cache": { "version": "6.0.1", "resolved": "https://registry.npmjs.org/file-entry-cache/-/file-entry-cache-6.0.1.tgz", @@ -6216,6 +6222,14 @@ "resolved": "https://registry.npmjs.org/postcss-value-parser/-/postcss-value-parser-4.2.0.tgz", "integrity": "sha512-1NNCs6uurfkVbeXG4S8JFT9t19m45ICnif8zWLd5oPSZ50QnwMfK+H3jv408d4jw/7Bttv5axS5IiHoLaVNHeQ==" }, + "node_modules/posthog-js": { + "version": "1.96.1", + "resolved": "https://registry.npmjs.org/posthog-js/-/posthog-js-1.96.1.tgz", + "integrity": "sha512-kv1vQqYMt2BV3YHS+wxsbGuP+tz+M3y1AzNhz8TfkpY1HT8W/ONT0i0eQpeRr9Y+d4x/fZ6M4cXG5GMvi9lRCA==", + "dependencies": { + "fflate": "^0.4.1" + } + }, "node_modules/prelude-ls": { "version": "1.2.1", "resolved": "https://registry.npmjs.org/prelude-ls/-/prelude-ls-1.2.1.tgz", diff --git a/package.json b/package.json index 1ebd1a5f..717f6349 100644 --- a/package.json +++ b/package.json @@ -64,6 +64,7 @@ "@significa/svelte-ui": "^0.0.28", "@storyblok/js": "^2.3.0", "matter-js": "^0.19.0", + "posthog-js": "^1.96.1", "prism-svelte": "^0.5.0", "svelte-confetti": "^1.3.0" } diff --git a/src/routes/+layout.svelte b/src/routes/+layout.svelte index 824bc65c..ae034056 100644 --- a/src/routes/+layout.svelte +++ b/src/routes/+layout.svelte @@ -10,12 +10,20 @@ import Footer from '$components/footer.svelte'; import { toast, Toaster, ToastNotification } from '@significa/svelte-ui'; import { beforeNavigate } from '$app/navigation'; - import { dev } from '$app/environment'; + import { browser, dev } from '$app/environment'; + import posthog from 'posthog-js'; export let data; beforeNavigate(() => { toast.clearAll(); }); + + if (browser) { + posthog.init('phc_8ukJJpl6XE0i5TWJmvzkgt9bluU8Uur4n3FkxjT0knL', { + api_host: 'https://eu.posthog.com', + persistence: 'localStorage' + }); + } From b756c2fadd93ea1fefbf7002c47a207f65bf4105 Mon Sep 17 00:00:00 2001 From: kaaps Date: Mon, 18 Dec 2023 11:43:35 +0000 Subject: [PATCH 2/3] fix: undo settings --- .vscode/settings.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.vscode/settings.json b/.vscode/settings.json index d6a7f1db..27281fd4 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -6,7 +6,7 @@ }, "editor.formatOnSave": true, "editor.codeActionsOnSave": { - "source.fixAll": "explicit" + "source.fixAll": true }, "eslint.validate": ["svelte"] } From 234a45e3a648cb9e7d4dd46398bab4a95f35ecfe Mon Sep 17 00:00:00 2001 From: Nuno Polonia Date: Mon, 8 Jan 2024 12:51:34 +0000 Subject: [PATCH 3/3] refactor: change posthog token to an env var --- .env.example | 4 +++- src/routes/+layout.svelte | 10 +++++++--- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/.env.example b/.env.example index 9583bb09..9316406b 100644 --- a/.env.example +++ b/.env.example @@ -16,4 +16,6 @@ BYPASS_TOKEN= VITE_HTTPS_ENABLED=true -SESSION_SECRET_KEY= \ No newline at end of file +SESSION_SECRET_KEY= + +PUBLIC_POSTHOG_PROJECT_TOKEN= \ No newline at end of file diff --git a/src/routes/+layout.svelte b/src/routes/+layout.svelte index ae034056..890221eb 100644 --- a/src/routes/+layout.svelte +++ b/src/routes/+layout.svelte @@ -2,16 +2,20 @@ import '$styles/index.css'; import { page } from '$app/stores'; + import { beforeNavigate } from '$app/navigation'; + import { browser, dev } from '$app/environment'; import DraftMode from '$components/draft-mode.svelte'; import ImageGallery from '$components/image-gallery.svelte'; import TopNavigation from '$components/top-navigation.svelte'; import PageDrawer from '$components/page-drawer.svelte'; import Footer from '$components/footer.svelte'; + + import { PUBLIC_POSTHOG_PROJECT_TOKEN } from '$env/static/public'; + import { toast, Toaster, ToastNotification } from '@significa/svelte-ui'; - import { beforeNavigate } from '$app/navigation'; - import { browser, dev } from '$app/environment'; import posthog from 'posthog-js'; + export let data; beforeNavigate(() => { @@ -19,7 +23,7 @@ }); if (browser) { - posthog.init('phc_8ukJJpl6XE0i5TWJmvzkgt9bluU8Uur4n3FkxjT0knL', { + posthog.init(PUBLIC_POSTHOG_PROJECT_TOKEN, { api_host: 'https://eu.posthog.com', persistence: 'localStorage' });