跟踪 http 域引荐来源网址

发布于 2024-08-09 06:24:17 字数 310 浏览 5 评论 0原文

我可以使用 javascript 跟踪 http 引用,并将变量附加到 URL 字符串以存储到数据库中吗?

或者我可以跟踪用户获得的cookie吗?

(这里非常通俗易懂,抱歉)

如果http引荐来源网址是domain.com 添加到网址“&referer=google”,

该网址应在他们的会话期间保留在他们身边。

或者

当用户点击我的 Google adwords 广告时。他们得到一个带有引用域的 cookie。 尝试读取该 cookie,并附加相同的变量。

有什么想法吗?

Can i track the http referer with javascript, and append a variable to the URL string to store into a dbase?

or could i track a cookie that the user gets?

(very layman's terms here, sorry)

if http referrer is domain.com
add to url '&referer=google'

which should stay with them during their session.

OR

when a user clicks my Google adwords ad. they get a cookie with a referring domain in it.
try to read that cookie, and append the same variable.

any thoughts?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

亣腦蒛氧 2024-08-16 06:24:17

是的,你可以这样做。

如何最好地跟踪取决于您想要如何处理这些信息。如果您需要知道该访问中每个页面浏览量的当前访问的引荐来源网址,那么在该访问中的第一个(也称为引用)页面浏览量上设置 Cookie 是一个好主意。这样每个页面都可以访问引用域。

如果您只需要该信息用于记录目的(例如,仔细检查来自 PPC 广告供应商的计费信息),那么您不需要存储在 cookie 中,只需检测您是否有引荐来源网址并记录该事实即可。在服务器代码中而不是在客户端脚本中执行此操作可能更容易。

您没有注意到您在哪个服务器平台上运行,因此很难提供具体的代码示例或建议,但在 javascript 中,这是我不久前的一个快速代码示例,它创建了一个跟踪图像(又名“网络错误”) ") 来记录综合浏览量,包括可选的“r=”查询字符串参数中的推荐信息。调整它来做你想做的事情应该不难。

<script type="text/javascript">
document.write("<img src=\"http://yoursite.com/logviews/?TYPE=PV" 
    + ((document.referrer == "" || document.referrer == null) ? "" : "&r=" + encodeURIComponent(document.referrer)) 
    + "\" width=\"0\" height=\"0\" alt=\"Page view tracker\" />");
</script>

Yes, you can do this.

How best to track depends on what you're trying to do with the information. If you need to know the referrer for the current visit on every pageview in that visit, then setting a cookie on the first (aka referred) pageview in that visit is a good idea. That way every page can have access to the referral domain.

If you only need the info for logging purposes (e.g. to double-check billing info from a PPC ad vendor), then you don't need to store in a cookie, simply detect that you have a referrer and log that fact. It's probably easier to do this in server code rather than client script.

You didn't note which server platform you were running on, so it's hard to give specific code samples or advice, but in javascript, here's a quick code sample I had from a while ago, which creates a tracking image (aka "web bug") to record a pageview, including referral information in an optional "r=" query string parameter. Adapting this to do what you want to do shouldn't be hard.

<script type="text/javascript">
document.write("<img src=\"http://yoursite.com/logviews/?TYPE=PV" 
    + ((document.referrer == "" || document.referrer == null) ? "" : "&r=" + encodeURIComponent(document.referrer)) 
    + "\" width=\"0\" height=\"0\" alt=\"Page view tracker\" />");
</script>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文