My WordPress site (http://robfuquay.staging.wpengine.com/) is setup to only allow Google Analytics cookies after users have given their consent via a banner attached to the bottom of the window. (This is done via this plugin: https://wordpress.org/plugins/cookie-notice/)
Until that consent is given I have a cookie called ga-disable-UA-10877870-45
which is set to true
. When the consent button is clicked another cookie gets added cookie_notice_accepted
and set to true
. Once the cookie_notice_accepted
cookie is set to true
, the ga-disable-UA-10877870-45
cookie is set to false
via the function below:
add_action( 'init', 'set_ga_disable_cookie_according_to_cookie_notice' );
function set_ga_disable_cookie_according_to_cookie_notice() {
if ( function_exists( 'cn_cookies_accepted' ) && function_exists('get_ua')) {
if ( cn_cookies_accepted() ) {
setcookie( 'ga-disable-'.get_ua(), 'false', 0, "/" );
} else {
if(!isset($_COOKIE['ga-disable-'.get_ua()])) {
setCookie( 'ga-disable-'.get_ua(), 'true' );
}
}
}
}
Once the ga-disable-UA-10877870-45
is set to false, on the next page load the Google Analytics cookies get set: _ga
, _gat
, and gid
. (After the consent button is clicked the page is automatically reloaded via the Cookie Notice plugin settings.)
The problem I have is regarding the client. Chrome, Safari, and Opera (and all their private browsers) all work as expected: Accept notice, page reloads, Google Analytics cookies are set. Firefox also works as expected, but the Firefox private browsing doesn't set the Google Analytics cookies until an additional page request. That means even after the page gets automatically reloaded I have to refresh the page an additional time. This is consistent between both my MacBooks.
I am allowing cookies and I am not blocking tracking, so why does Firefox private browsing act this way?