docs
This commit is contained in:
parent
2d5cf12aaf
commit
38eed0c0ba
1 changed files with 8 additions and 9 deletions
|
|
@ -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>
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue