-
-
Notifications
You must be signed in to change notification settings - Fork 66
Description
Environment
"@unhead/vue": "^2.0.19"
"vite": "^7.2.7"
"vue": "^3.5.25"
Reproduction
Hi! First of all thanks for creating this great library
Now, I'm having a hard time synchronising the update of the page title with the initialisation of analytics solutions such as Amplitude.
The issue is that as soon as an analytics monitoring is initialised, it will capture the default page title of index.html.
Example App.vue:
<template>
<RouterView/> <!-- It loads a View which uses useHead() to set the title -->
</template>
<script setup>
// [ . . . ]
useHead({
link: [
{
rel: "canonical",
href: canonicalUri,
},
],
meta: [
// [ . . . ]
],
});
const amplitudeClient = inject("amplitudeClient");
onMounted(() => {
// <amplitude>
// Used to wait for the route to be rendered before initialising Amplitude
(async () => {
await nextTick();
await amplitudeClient?.init();
})();
// </amplitude>
});
fetch();
</script><RouterView> loads the actual user view which will initialise again useHead() with the page title
So if the index.html has "App Name - Loading..." as title, Amplitude and other Analytics tools will capture it and send as event. Is there smooth way to expose the useHead() DOM updates so we can synchronise it with analytics?
Another solution that I tried consisted of using router.afterEach() then awaiting a next tick and initialising the analytics, it didn't work either as the window.document.title still wasn't updated at that point.
Describe the bug
Please check the reproduction section.
Additional context
No response