cookieDomain in JS tracker: to set or not to set

We have a site with subdomains:

These subdomains are using different instances of the Snowplow trackers because they are served by different codebases.

Is it possible to get consistent domain_userids across these two domains? In the docs, it says:
“Set the cookie domain for the tracker instance using the cookieDomain field of the argmap. If this field is not set, the cookies will not be given a domain.”

I’m assuming that if we don’t set cookieDomain, it’s not like a magical wildcard that will get us what we want.

So if we set the cookieDomain in both tracker instances to, would that work? Note that we do NOT use

Changing the cookieDomain to “” would work. You can alternativelly use the discoverRootDomain tracker configuration setting as described here to automatically set the cookie domain to the highest domain possible (in your case, “”). For reasons of backwards compatibility this is not the default behaviour - if you have not explicitly been setting the domain, it will have defaulted to the lowest subdomain.

Having multiple cookies with the same name but different domains on one page can lead to hard-to-debug behaviour due to unpredictability in which cookie gets read. So if you do change the cookie domain, you should also rename your cookies using this setting.

Be aware that this creates new cookies. The old cookies will no longer be read, so information stored in them will be lost. In particular, returning users will have new domain_userids assigned to them on their first visit after you make the change.

Hope that helps,

1 Like

Thanks Fred, very helpful!