This commit is contained in:
Jon McClure 2024-06-14 13:13:42 +01:00
parent 2d5cf12aaf
commit 38eed0c0ba

View file

@ -11,20 +11,19 @@ For example, here's how you can use SvelteKit's [`afterNavigate`](https://kit.sv
registerPageview, registerPageview,
} from '@reuters-graphics/graphics-components'; } from '@reuters-graphics/graphics-components';
import { afterNavigate } from '$app/navigation'; import { afterNavigate } from '$app/navigation';
import { onMount } from 'svelte';
let hasMounted = false; let isFirstPageview = true;
onMount(() => {
hasMounted = true;
});
afterNavigate(() => { afterNavigate(() => {
// We shouldn't fire on initial page load because the Analytics component // We shouldn't fire on initial page load because the Analytics component
// already registers a reader's first pageview. After this component // already registers a reader's first pageview. After this component
// has mounted, we can be sure that further navigation is virtual and // has initially mounted, we can be sure that further navigation is virtual
// register pageviews using this function. // and register pageviews using this function.
if (hasMounted) registerPageview(); if (!isFirstPageview) {
registerPageview();
} else {
isFirstPageview = false;
}
}); });
</script> </script>