Firefox private browsing requires 2 page loads to set cookies





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}







1















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?










share|improve this question




















  • 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
    Nov 18 '18 at 12:26


















1















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?










share|improve this question




















  • 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
    Nov 18 '18 at 12:26














1












1








1


1






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?










share|improve this question
















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?







php wordpress firefox cookies google-analytics






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 16 '18 at 17:33







Dreadnought

















asked Nov 16 '18 at 17:28









DreadnoughtDreadnought

535




535








  • 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
    Nov 18 '18 at 12:26














  • 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
    Nov 18 '18 at 12:26








1




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
Nov 18 '18 at 12:26





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
Nov 18 '18 at 12:26












1 Answer
1






active

oldest

votes


















1














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






share|improve this answer
























  • The code in this answer no longer seems to work, at least for me using Firefox 64.0.2 on OSX, as document.cookie returns an empty string. Cookies are still held in memory, though they're just a little harder to inspect

    – kevlarr
    Feb 10 at 1:23






  • 1





    Scratch that, I was getting empty strings because the cookies in question are HttpOnly, meaning no access from JS

    – kevlarr
    Feb 15 at 3:35












Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53342704%2ffirefox-private-browsing-requires-2-page-loads-to-set-cookies%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









1














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






share|improve this answer
























  • The code in this answer no longer seems to work, at least for me using Firefox 64.0.2 on OSX, as document.cookie returns an empty string. Cookies are still held in memory, though they're just a little harder to inspect

    – kevlarr
    Feb 10 at 1:23






  • 1





    Scratch that, I was getting empty strings because the cookies in question are HttpOnly, meaning no access from JS

    – kevlarr
    Feb 15 at 3:35
















1














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






share|improve this answer
























  • The code in this answer no longer seems to work, at least for me using Firefox 64.0.2 on OSX, as document.cookie returns an empty string. Cookies are still held in memory, though they're just a little harder to inspect

    – kevlarr
    Feb 10 at 1:23






  • 1





    Scratch that, I was getting empty strings because the cookies in question are HttpOnly, meaning no access from JS

    – kevlarr
    Feb 15 at 3:35














1












1








1







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






share|improve this answer













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







share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 19 '18 at 17:11









DreadnoughtDreadnought

535




535













  • The code in this answer no longer seems to work, at least for me using Firefox 64.0.2 on OSX, as document.cookie returns an empty string. Cookies are still held in memory, though they're just a little harder to inspect

    – kevlarr
    Feb 10 at 1:23






  • 1





    Scratch that, I was getting empty strings because the cookies in question are HttpOnly, meaning no access from JS

    – kevlarr
    Feb 15 at 3:35



















  • The code in this answer no longer seems to work, at least for me using Firefox 64.0.2 on OSX, as document.cookie returns an empty string. Cookies are still held in memory, though they're just a little harder to inspect

    – kevlarr
    Feb 10 at 1:23






  • 1





    Scratch that, I was getting empty strings because the cookies in question are HttpOnly, meaning no access from JS

    – kevlarr
    Feb 15 at 3:35

















The code in this answer no longer seems to work, at least for me using Firefox 64.0.2 on OSX, as document.cookie returns an empty string. Cookies are still held in memory, though they're just a little harder to inspect

– kevlarr
Feb 10 at 1:23





The code in this answer no longer seems to work, at least for me using Firefox 64.0.2 on OSX, as document.cookie returns an empty string. Cookies are still held in memory, though they're just a little harder to inspect

– kevlarr
Feb 10 at 1:23




1




1





Scratch that, I was getting empty strings because the cookies in question are HttpOnly, meaning no access from JS

– kevlarr
Feb 15 at 3:35





Scratch that, I was getting empty strings because the cookies in question are HttpOnly, meaning no access from JS

– kevlarr
Feb 15 at 3:35




















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53342704%2ffirefox-private-browsing-requires-2-page-loads-to-set-cookies%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

List item for chat from Array inside array React Native

Thiostrepton

Caerphilly