Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

setting route.meta.matomo has no effect with SSR #7

Open
dhritzkiv opened this issue May 24, 2019 · 4 comments
Open

setting route.meta.matomo has no effect with SSR #7

dhritzkiv opened this issue May 24, 2019 · 4 comments

Comments

@dhritzkiv
Copy link

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?

@pimlie
Copy link
Owner

pimlie commented Jun 7, 2019

Sorry for the late response, could you maybe share some code that explains a bit what you are trying to do?

@dhritzkiv
Copy link
Author

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

@pimlie
Copy link
Owner

pimlie commented Jun 7, 2019

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: nuxt/nuxt#2653 (comment)

@pimlie
Copy link
Owner

pimlie commented Jun 9, 2019

Related Nuxt rfc: nuxt/rfcs#28

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants