Wpd Ai Cookie Domain

Alpha Insights Documentation

Docs Navigation

Filter: wpd_ai_cookie_domain

Set the domain used for Alpha Insights cookies (e.g. session and attribution cookies).

Description

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).

Location

File: includes/classes/WPDAI_Session_Tracking.php

Method: WPDAI_Session_Tracking::get_cookie_domain()

Parameters

Parameter Type Description
$host string The host parsed from home_url() (e.g. www.example.com)

Return

Type: string

The cookie domain to use (e.g. example.com for subdomain sharing). Empty string to use default behavior.

Example Usage

Share cookies across subdomains

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;
}

Related

Got A Question?

Subscribe
Notify of
guest
0 Comments
Newest
Oldest Most Voted
Inline Feedbacks
View all comments
Alpha Insights

Alpha Insights

The World's Most Advanced WooCommerce Profit Reporting Engine

5/5 – Trustpilot

Alpha Insights