From 38eed0c0baef5647ec6169eaa7770fe7ca6e358d Mon Sep 17 00:00:00 2001 From: Jon McClure Date: Fri, 14 Jun 2024 13:13:42 +0100 Subject: [PATCH] docs --- .../Analytics/stories/docs/multipage.md | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/src/components/Analytics/stories/docs/multipage.md b/src/components/Analytics/stories/docs/multipage.md index b8336dda..a3223927 100644 --- a/src/components/Analytics/stories/docs/multipage.md +++ b/src/components/Analytics/stories/docs/multipage.md @@ -11,20 +11,19 @@ For example, here's how you can use SvelteKit's [`afterNavigate`](https://kit.sv registerPageview, } from '@reuters-graphics/graphics-components'; import { afterNavigate } from '$app/navigation'; - import { onMount } from 'svelte'; - let hasMounted = false; - - onMount(() => { - hasMounted = true; - }); + let isFirstPageview = true; afterNavigate(() => { // We shouldn't fire on initial page load because the Analytics component // already registers a reader's first pageview. After this component - // has mounted, we can be sure that further navigation is virtual and - // register pageviews using this function. - if (hasMounted) registerPageview(); + // has initially mounted, we can be sure that further navigation is virtual + // and register pageviews using this function. + if (!isFirstPageview) { + registerPageview(); + } else { + isFirstPageview = false; + } });