Next.js Discord

Discord Forum

What are some best practices for using GTM dataLayer with Next.js client-side navigation

Unanswered
Japanese common catfish posted this in #help-forum
Open in Discord
Japanese common catfishOP
I am implicitly opting in to client-side navigation using the <Link /> component. One issue I've noticed is that when I push to the dataLayer, I can end up with properties persisting in the dataLayer after navigation that are not relevant to the new page.

I've tried a few things, including using next/route and listening for routeChangeComplete or routeChangeStart and calling this.reset() on the dataLayer or setting specific properties in the dataLayer to null.

However, I'm not yet satisfied with anything I have come up with and thought I should step back and ask the community for any tips or best practices when working with dataLayer and client-side navigation in Next.js

0 Replies