From 2c6fed99ad72627dfe652863660c43acccc48c31 Mon Sep 17 00:00:00 2001 From: JovannMC Date: Mon, 17 Feb 2025 20:21:03 +0300 Subject: [PATCH] feat: allow opting out of plausible also fixes build errors if .env isn't available hides privacy section if url isn't set --- src/lib/animation/index.ts | 2 + src/lib/sections/settings/Privacy.svelte | 64 +++++++++++++++++++++++ src/lib/sections/settings/index.svelte.ts | 3 ++ src/routes/+layout.svelte | 18 +++++-- src/routes/settings/+page.svelte | 4 ++ 5 files changed, 86 insertions(+), 5 deletions(-) create mode 100644 src/lib/sections/settings/Privacy.svelte diff --git a/src/lib/animation/index.ts b/src/lib/animation/index.ts index df4a72b..0c44dd0 100644 --- a/src/lib/animation/index.ts +++ b/src/lib/animation/index.ts @@ -12,6 +12,8 @@ import { let effectsEnabled = true; let isMobileDevice = false; +// FIXME: there is sometimes an issue in dev where subscribing to the store just breaks everything? (.subscribe() not existing on effects, somehow) +// you gotta restart the dev server to fix and it only seems to happen in dev. somehow effects being called before its defined? effects.subscribe((value) => { effectsEnabled = value; }); diff --git a/src/lib/sections/settings/Privacy.svelte b/src/lib/sections/settings/Privacy.svelte new file mode 100644 index 0000000..4d29288 --- /dev/null +++ b/src/lib/sections/settings/Privacy.svelte @@ -0,0 +1,64 @@ + + + +
+

+ + Privacy +

+
+
+
+

Plausible analytics

+

+ We use Plausible, a privacy-focused analytics tool, to gather + completely anonymous statistics. All data is anonymized + and aggregated, and no identifiable information is ever + sent or stored. You can choose to opt-out below. +

+
+
+
+ + + +
+
+
+
+
diff --git a/src/lib/sections/settings/index.svelte.ts b/src/lib/sections/settings/index.svelte.ts index b4e3c55..9d42dfc 100644 --- a/src/lib/sections/settings/index.svelte.ts +++ b/src/lib/sections/settings/index.svelte.ts @@ -3,9 +3,11 @@ import type { ConversionSpeed } from "$lib/converters/vertd.svelte"; export { default as Appearance } from "./Appearance.svelte"; export { default as Conversion } from "./Conversion.svelte"; export { default as Vertd } from "./Vertd.svelte"; +export { default as Privacy } from "./Privacy.svelte"; export interface ISettings { filenameFormat: string; + plausible: boolean; vertdURL: string; vertdSpeed: ConversionSpeed; } @@ -15,6 +17,7 @@ export class Settings { public settings: ISettings = $state({ filenameFormat: "VERT_%name%", + plausible: true, vertdURL: "", vertdSpeed: "slow", }); diff --git a/src/routes/+layout.svelte b/src/routes/+layout.svelte index 91ca891..f128d3e 100644 --- a/src/routes/+layout.svelte +++ b/src/routes/+layout.svelte @@ -2,7 +2,7 @@ import { onMount } from "svelte"; import { goto } from "$app/navigation"; - import { PUB_HOSTNAME, PUB_PLAUSIBLE_URL } from "$env/static/public"; + import { env } from "$env/dynamic/public"; import { VERT_NAME } from "$lib/consts"; import * as Layout from "$lib/components/layout"; import * as Navbar from "$lib/components/layout/Navbar"; @@ -18,6 +18,7 @@ import "../app.scss"; let { children } = $props(); + let enablePlausible = $state(false); const dropFiles = (e: DragEvent) => { e.preventDefault(); @@ -45,6 +46,11 @@ Settings.instance.load(); }); + + $effect(() => { + // Enable plausible if enabled + enablePlausible = !!env.PUB_PLAUSIBLE_URL && Settings.instance.settings.plausible; + }); @@ -79,11 +85,13 @@ /> - {#if PUB_PLAUSIBLE_URL}{/if} + data-domain={env.PUB_HOSTNAME || "vert.sh"} + src="{env.PUB_PLAUSIBLE_URL}/js/script.pageview-props.tagged-events.js" + > + {/if} diff --git a/src/routes/settings/+page.svelte b/src/routes/settings/+page.svelte index c8ab691..68bd3df 100644 --- a/src/routes/settings/+page.svelte +++ b/src/routes/settings/+page.svelte @@ -3,6 +3,7 @@ import { log } from "$lib/logger"; import * as Settings from "$lib/sections/settings/index.svelte"; import { addToast } from "$lib/store/ToastProvider"; + import { env } from "$env/dynamic/public"; import { SettingsIcon } from "lucide-svelte"; import { onMount } from "svelte"; @@ -62,6 +63,9 @@
+ {#if env.PUB_PLAUSIBLE_URL} + + {/if}