Firefox私人浏览需要2个页面加载才能设置Cookie [英] Firefox private browsing requires 2 page loads to set cookies

查看:91
本文介绍了Firefox私人浏览需要2个页面加载才能设置Cookie的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的WordPress网站( http://robfuquay.staging.wpengine.com/ )是设置为仅在用户通过窗口底部的横幅广告表示同意后才允许Google Analytics(分析)Cookie。 (这是通过以下插件完成的: https://wordpress.org/plugins/cookie-notice/

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

在获得同意之前,我有一个名为 ga-disable-UA-10877870-45 设置为 true 。单击同意按钮时,将添加另一个 cookie_notice_accepted cookie,并将其设置为 true 。将 cookie_notice_accepted cookie设置为 true 后, ga-disable-UA-10877870- 45 cookie通过以下功能设置为 false

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

一次 ga-disable-UA-10877870-45 设置为false,在下一页加载Google Analytics(分析)Cookie: _ga _gat gid 。 (单击同意按钮后,页面会通过Cookie通知插件设置自动重新加载。)

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

我遇到的问题与客户端有关。 Chrome,Safari和Opera(及其所有私有浏览器)均按预期工作:接受通知,重新加载页面,设置Google Analytics(分析)Cookie。 Firefox也可以按预期工作,但是 Firefox的私有浏览只有在有其他页面请求时才设置Google Analytics(分析)Cookie。这意味着即使页面自动重新加载后,我也必须刷新页面一次。这在我的两台MacBooks上都是一致的。

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.

我允许使用cookie,但我没有阻止跟踪,所以为什么Firefox私人浏览会这样?

I am allowing cookies and I am not blocking tracking, so why does Firefox private browsing act this way?

推荐答案

@Jamie_D在识别问题时是正确的:

@Jamie_D was correct in identifying the problem:


根据此页面的内容:在私有窗口中设置的Cookie会暂时保存在内存中,与常规窗口Cookie分开,并在私有会话结束时丢弃。

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"

由于未在开发工具中显示cookie,解决方案是在控制台中输入以下JavaScript:

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('; '));

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

返回的预期cookie包括 _ga _gat _gid

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

我再次检查了Google Analytics(分析)是否提取了正确的实时数据,并且一切看起来都很好。

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

很明显,Firefox私人浏览不需要两次加载页面来设置cookie。Firefox只是不显示它们是在开发工具中设置的。

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.

这篇关于Firefox私人浏览需要2个页面加载才能设置Cookie的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆