Set the domain used for Alpha Insights cookies (e.g. session and attribution cookies).
The plugin uses the current request host (from home_url()) as the cookie domain by default. This filter lets you override it so cookies are shared across subdomains (e.g. use example.com so both www.example.com and shop.example.com share the same cookie). No leading dot is used (RFC 6265 deprecates the leading dot).
File: includes/classes/WPDAI_Session_Tracking.php
Method: WPDAI_Session_Tracking::get_cookie_domain()
| Parameter | Type | Description |
|---|---|---|
| $host | string | The host parsed from home_url() (e.g. www.example.com) |
Type: string
The cookie domain to use (e.g. example.com for subdomain sharing). Empty string to use default behavior.
add_filter( 'wpd_ai_cookie_domain', 'wpd_ai_cookie_domain_root' );
function wpd_ai_cookie_domain_root( $host ) {
// Use root domain so www and shop share the same session
if ( preg_match( '/^([a-z0-9\-]+\.)?([a-z0-9\-]+\.[a-z]+)$/i', $host, $m ) ) {
return $m[2];
}
return $host;
}