setCookieDomain

The setCookieDomain() method sets the domain where visitor cookies (_pk_id.*) and session cookies ( _pk_ses.*) will be stored. These cookies contain a visitor ID, which is used to recognize the visitor in different subdomains. A visitor who moves from one subdomain to another will be recognized as the same visitor. Sessions that would be treated as separate for each subdomain will be treated as one session.

This method needs to be preceded with setDomains().

Syntax

setCookieDomain(domain)
setCookieDomain(domain): void
setCookieDomain(domain): void
setCookieDomain(domain): void
setCookieDomain(domain): void
setCookieDomain(domain): void
setCookieDomain(domain): void

Parameters

Domain (string, required)

The domain where you'll store visitor cookies (_pk_id.*) and session cookies ( _pk_ses.*). You can use a wildcard or a dot for subdomains.

Examples

To recognize visitors across two subdomains example.com and help.example.com:

// Set the domains that are tracked as one site or app. Use the same tracking code for these domains.  
_paq.push(\["setDomains", ["example.com", "help.example.com"]]);

// Store a cookie with the visitor ID on this domain. Use it for recognizing a visitor across subdomains.  
_paq.push(["setCookieDomain", "*.example.com"]);
setCookieDomain("example.com", "help.example.com"): void
setCookieDomain("example.com", "help.example.com"): void
setCookieDomain("example.com", "help.example.com"): void
setCookieDomain("example.com", "help.example.com"): void
setCookieDomain("example.com", "help.example.com"): void
setCookieDomain("example.com", "help.example.com"): void

Related methods