Adding plausible analytics for testing.

This commit is contained in:
Bradley Shellnut 2024-10-03 13:30:23 -07:00
parent ad74bc0f85
commit fba22e7ebd
5 changed files with 82 additions and 67 deletions

View file

@ -95,7 +95,7 @@
"@sveltejs/adapter-node": "^5.2.5",
"@sveltejs/adapter-vercel": "^5.4.4",
"@types/feather-icons": "^4.29.4",
"bits-ui": "^0.21.13",
"bits-ui": "^0.21.16",
"boardgamegeekclient": "^1.9.1",
"bullmq": "^5.15.0",
"class-variance-authority": "^0.7.0",

View file

@ -72,8 +72,8 @@ importers:
specifier: ^4.29.4
version: 4.29.4
bits-ui:
specifier: ^0.21.13
version: 0.21.15(svelte@5.0.0-next.175)
specifier: ^0.21.16
version: 0.21.16(svelte@5.0.0-next.175)
boardgamegeekclient:
specifier: ^1.9.1
version: 1.9.1
@ -2334,8 +2334,8 @@ packages:
bindings@1.5.0:
resolution: {integrity: sha512-p2q/t/mhvuOj/UeLlV6566GD/guowlr0hHxClI0W9m7MWYkL1F0hLo+0Aexs9HSPCtR1SXQ0TD3MMKrXZajbiQ==}
bits-ui@0.21.15:
resolution: {integrity: sha512-+m5WSpJnFdCcNdXSTIVC1WYBozipO03qRh03GFWgrdxoHiolCfwW71EYG4LPCWYPG6KcTZV0Cj6iHSiZ7cdKdg==}
bits-ui@0.21.16:
resolution: {integrity: sha512-XFZ7/bK7j/K+5iktxX/ZpmoFHjYjpPzP5EOO/4bWiaFg5TG1iMcfjDhlBTQnJxD6BoVoHuqeZPHZvaTgF4Iv3Q==}
peerDependencies:
svelte: ^4.0.0 || ^5.0.0-next.118
@ -4121,8 +4121,8 @@ packages:
resolution: {integrity: sha512-hOS089on8RduqdbhvQ5Z37A0ESjsqz6qnRcffsMU3495FuTdqSm+7bhJ29JvIOsBDEEnan5DPu9t3To9VRlMzA==}
engines: {node: '>=8.10.0'}
readdirp@4.0.1:
resolution: {integrity: sha512-GkMg9uOTpIWWKbSsgwb5fA4EavTR+SG/PMPoAY8hkhHfEEY0/vqljY+XHqtDf2cr2IJtoNRDbrrEpZUiZCkYRw==}
readdirp@4.0.2:
resolution: {integrity: sha512-yDMz9g+VaZkqBYS/ozoBJwaBhTbZo3UNYQHNRw1D3UFQB8oHB4uS/tAODO+ZLjGWmUbKnIlOWO+aaIiAxrUWHA==}
engines: {node: '>= 14.16.0'}
redis-errors@1.2.0:
@ -6578,7 +6578,7 @@ snapshots:
dependencies:
file-uri-to-path: 1.0.0
bits-ui@0.21.15(svelte@5.0.0-next.175):
bits-ui@0.21.16(svelte@5.0.0-next.175):
dependencies:
'@internationalized/date': 3.5.6
'@melt-ui/svelte': 0.76.2(svelte@5.0.0-next.175)
@ -6702,7 +6702,7 @@ snapshots:
chokidar@4.0.1:
dependencies:
readdirp: 4.0.1
readdirp: 4.0.2
optional: true
chownr@2.0.0: {}
@ -8416,7 +8416,7 @@ snapshots:
dependencies:
picomatch: 2.3.1
readdirp@4.0.1:
readdirp@4.0.2:
optional: true
redis-errors@1.2.0: {}

View file

@ -6,11 +6,11 @@
<meta name="description" content="Bored? Find a game! Bored Game!" />
<link rel="icon" href="%sveltekit.assets%/favicon-bored-game.svg" />
<meta name="viewport" content="width=device-width" />
<noscript>Please enable JavaScript.</noscript>
%sveltekit.head%
</head>
<body data-sveltekit-preload-data="hover">
<div id="svelte" style="display: contents">%sveltekit.body%</div>
<body>
<div id="svelte">%sveltekit.body%</div>
</body>
</html>

View file

@ -0,0 +1,13 @@
<script lang="ts">
import { PUBLIC_SITE_URL } from '$env/static/public'
const src = `${PUBLIC_SITE_URL}/js/script.js`
const dataDomain = PUBLIC_SITE_URL.replace('https://', '').replace('http://', '')
</script>
<svelte:head>
<script
defer
data-domain={dataDomain}
{src}
></script>
</svelte:head>

View file

@ -1,24 +1,25 @@
<script lang="ts">
import '$lib/styles/app.pcss';
import { onMount } from 'svelte';
import { MetaTags } from 'svelte-meta-tags';
import { getFlash } from 'sveltekit-flash-message/client';
import 'iconify-icon';
import { ModeWatcher } from 'mode-watcher';
import { Toaster } from '$lib/components/ui/sonner';
import { onNavigate } from '$app/navigation';
import { page } from '$app/stores';
import Analytics from '$components/Analytics.svelte';
import PageLoadingIndicator from '$lib/page_loading_indicator.svelte';
import { theme } from '$state/theme';
import { toastMessage } from '$lib/utils/superforms.js';
import '$lib/styles/app.pcss'
import { onMount } from 'svelte'
import { MetaTags } from 'svelte-meta-tags'
import { getFlash } from 'sveltekit-flash-message/client'
import 'iconify-icon'
import { onNavigate } from '$app/navigation'
import { page } from '$app/stores'
import Analytics from '$components/Analytics.svelte'
import PlausibleAnalytics from '$components/PlausibleAnalytics.svelte'
import { Toaster } from '$lib/components/ui/sonner'
import PageLoadingIndicator from '$lib/page_loading_indicator.svelte'
import { toastMessage } from '$lib/utils/superforms.js'
import { theme } from '$state/theme'
import { ModeWatcher } from 'mode-watcher'
const dev = process.env.NODE_ENV !== 'production';
const dev = process.env.NODE_ENV !== 'production'
const { data, children } = $props();
const { user } = data;
const { data, children } = $props()
const { user } = data
const metaTags = $derived({
const metaTags = $derived({
titleTemplate: '%s | Bored Game',
description: 'Bored Game, keep track of your gamesTable.',
openGraph: {
@ -28,44 +29,45 @@
description: 'Bored Game, keep track of your gamesTable',
},
...$page.data.metaTagsChild,
});
})
const flash = getFlash(page, {
const flash = getFlash(page, {
clearOnNavigate: true,
clearAfterMs: 3000,
clearArray: true,
});
})
onMount(() => {
onMount(() => {
// set the theme to the user's active theme
$theme = user?.theme || 'system';
document.querySelector('html')?.setAttribute('data-theme', $theme);
});
$theme = user?.theme || 'system'
document.querySelector('html')?.setAttribute('data-theme', $theme)
})
$effect(() => {
console.log('flash', $flash);
$effect(() => {
console.log('flash', $flash)
if ($flash) {
toastMessage({ type: $flash.type, text: $flash.message });
toastMessage({ type: $flash.type, text: $flash.message })
// Clearing the flash message could sometimes
// be required here to avoid double-toasting.
flash.set(undefined);
flash.set(undefined)
}
});
})
onNavigate(async (navigation) => {
if (!document.startViewTransition) return;
onNavigate(async (navigation) => {
if (!document.startViewTransition) return
return new Promise((oldStateCaptureResolve) => {
document.startViewTransition(async () => {
oldStateCaptureResolve();
await navigation.complete;
});
});
});
oldStateCaptureResolve()
await navigation.complete
})
})
})
</script>
{#if !dev}
<Analytics />
<PlausibleAnalytics />
{/if}
<MetaTags {...metaTags} />