Next.js Discord

Discord Forum

how do i conditionally enable <GoogleTagManager/> using @next/third-parties/google"; and vanilla-co

Unanswered
Havana posted this in #help-forum
Open in Discord
HavanaOP
[...] and vanilla-cookieconsent?

4 Replies

Asian black bear
You just conditionally render the component like any other React component.
{condition && <GTM />}
HavanaOP
i was already doing that, but i tried to put a console log in the sendGTM event and it still runs the function (?)
Even if the GoogleTagManager component wasn't rendered the sendGTM still runs, not sure if it actually sends the data