You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[Vue] Can't synchronise head title with analytics tools #615
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><scriptsetup>// [ . . . ]useHead({link: [{rel: "canonical",href: canonicalUri,},],meta: [// [ . . . ]],});constamplitudeClient=inject("amplitudeClient");onMounted(()=>{// <amplitude>// Used to wait for the route to be rendered before initialising Amplitude(async()=>{awaitnextTick();awaitamplitudeClient?.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.
Activity
feat(vue): add onHeadUpdated composable for DOM sync
feat(unhead): add `onRendered` option to `HeadEntryOptions`
feat: access resolved head with `onRendered` (#712)