Next.js Discord

Discord Forum

Configure cookies only for www domain, not subdomains, in GTM and NextJS

Unanswered
Birman posted this in #help-forum
Open in Discord
BirmanOP
I don't know if this is the right forum for this.

If it isn't, please point me the way.

I work in a company which website is setup with NextJS and Google Tag Manager. Let's call it www.website.com.

When I open the URL, there are a few cookies, like _ga and _fbp. That's expected, because GTM is injecting these cookies to track the users.

The issue is: when I open another service in a subdomain, e.g. kafka-ui.website.com, these same cookies are loaded and sent around in the requests. This messes up some things, the headers become too big for the server, and this needs to change.

When looking at the cookies tab, I can see the cookies domain is website.com and according to what I've researched, that's the default way it works.

I want to configure the cookies to target only specific domains — www.website.com or specific-subdomain.website.com. Is that possible? Would I need to work on NextJS config or GTM? Or is this setup somewhere else entirely?

I haven't got much experience in working with cookies but I'm happy to edit and add more information.

0 Replies