1
votes

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?

1
According to this page: "Cookies set in private windows are held temporarily in memory, separate from regular window cookies, and discarded at the end of your private session"Jamie_D

1 Answers

1
votes

@Jamie_D was correct in identifying the problem:

According to this page: "Cookies set in private windows are held temporarily in memory, separate from regular window cookies, and discarded at the end of your private session"

Due to the cookies not showing up in the dev tools, the solution was to enter the following JavaScript into the console:

unescape(document.cookie.split('; '));

Source: https://support.mozilla.org/en-US/questions/1031619#answer-672435

The expected cookies were returned including _ga, _gat, and _gid.

I double checked that Google Analytics was pulling the correct real-time data and everything looks good.

So to be clear, Firefox private browsing didn't require 2 page loads to set the cookies... Firefox was just not showing they were set in the dev tools.