nuxt-matomo
nuxt-matomo copied to clipboard
setting route.meta.matomo has no effect with SSR
When running a universal app, setting route.meta.matomo in a middleware has no effect when the page renders first on the server.
Obviously, matomo is unlikely to work on the server, but is there a way to have this module apply route.meta.matomo when the page is evaluated on the client?
Sorry for the late response, could you maybe share some code that explains a bit what you are trying to do?
Yes. Roughly this (only the relevant parts retained)
// middleware that runs for some pages/layouts
export default async (context: Context) => {
const { store, route } = context;
// get the current user
const {viewer} = store.state;
// this runs, but has no effect when coming from SSR'd page. It only has an effect on subsequent runs on the client
route.meta.matomo = {
userId: ["setUserId", viewer.id],
userTypeVar: ["setCustomVariable", 1, "UserName", viewer.name],
}
}
Ideally, route.meta.matomo would get serialized going from server -> client, and then rehydrated on the clientside, and passed to Matomo
I am not really sure that that is something this module should/could support. Eg if your middleware would be executed at page load (but it isnt, see below) then the meta should be re-applied and only vuex state would need to be hydrated.
Unfortunately it seems calling route middlewares on hydration is just not supported, the workaround is to add a client side plugin but I am not sure you have access to the route.meta there. See this topic and the linked comment for more info: https://github.com/nuxt/nuxt.js/issues/2653#issuecomment-390588837
Related Nuxt rfc: https://github.com/nuxt/rfcs/issues/28