热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

在Javascript重定向之前设置cookie-SettingacookiebeforeJavascriptRedirection

IhaveaRailsappwhereIsetasetasessionvariablethemomentauserlandsonmysitewiththe

I have a Rails app where I set a set a session variable the moment a user lands on my site with the referer and the page they hit. Additionally, I have Google Optimizer sending traffic from my homepage to various landing pages. The problem is that I think Google Optimizer is sending users away before the COOKIE is set.

我有一个Rails应用程序,当用户使用引用者和他们点击的页面登陆我的网站时,我设置了一个会话变量。此外,我还有Google Optimizer将流量从我的主页发送到各个目标网页。问题是,我认为Google Optimizer会在设置COOKIE之前将用户发送出去。

Is that even possible? I believe that the COOKIE is set from the HTTP Header, which must have fully loaded before Google's Javascript has even loaded.

这有可能吗?我相信COOKIE是从HTTP Header设置的,在Google的Javascript加载之前必须已经完全加载。

Thanks, Jason

2 个解决方案

#1


You're absolutely correct - the explanation you propose isn't possible. Assuming the browser is loading the page from your site that sends the COOKIE header, it will be set, and Javascript can't directly interfere with this.

你是绝对正确的 - 你提出的解释是不可能的。假设浏览器正在从您的站点加载发送COOKIE标头的页面,它将被设置,Javascript不能直接干扰它。

So the problem is elsewhere - the first thing I would test is whether the COOKIE header is actually being sent, whether it's being set (look in your browser's security/privacy panel), and then whether your code for checking if it's been set is functioning correctly.

所以问题出在其他地方 - 我要测试的第一件事是COOKIE标头是否实际发送,是否正在设置(查看浏览器的安全/隐私面板),然后检查是否已设置的代码是否正常运行正确。

#2


As you suspected, the COOKIE should be sent in the header when the visitor hits your page, so google optimizer shouldnt be affecting this..

如您所料,当访问者点击您的网页时,COOKIE应该在标题中发送,因此Google优化工具不应该影响这一点。

You may want to double check that you are setting the COOKIE, you can use firebug or similar for this (in the Net tab).

您可能想要仔细检查您是否正在设置COOKIE,您可以使用firebug或类似的(在Net选项卡中)。


推荐阅读
author-avatar
噬血--男爵_380_203
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有