重定向访客并创建新的推荐人信息? (一些PHP)
我有 2 个网站 - 网站 A 是接收流量的主要“营销”网站,网站 B 是人们进行购买的网站。网站 B 的报告系统向我提供了导致购买的网站 A 的引荐 URL。
网站 A 有多种指向网站 B 的号召性用语链接,我想衡量其中哪个链接对推动销售最有效。
以下是我目前的设置:
假设您位于 siteA.com/this-page.php。通常,单击站点 B 的链接会将此页面显示为引荐来源网址。相反,指向站点 B 的链接是 siteA.com/this-page.php?link=top-banner&dest=home,其中“link”提供被单击链接的 ID,dest 是站点 BI 想要访问的页面将点击发送至。
我在网站的每个页面上都有一个 PHP 包含内容:
<?php
if (isset($_GET['link'])) {
$qs = $_SERVER['QUERY_STRING'];
$form_action = "/redirect.php?" . $qs;
?>
<html>
<body onload="document.forms.go.submit();">
<form method="post" action="<?php echo $form_action; ?>" name="go"></form>
</body>
</html>
<?php } else {} ?>
redirect.php 页面计算出网站 B 上的目标页面,并执行标头重定向到适当的页面。
现在这对我来说效果很好,并且推荐人在站点 B 的统计数据中正确显示。
这似乎是一个不太优雅的解决方案,而且我还遇到了一些可用性问题:
当您单击指向站点 B 的链接时,会出现明显的延迟,因为当前页面会重新加载,表单会被提交,并且访问者会被访问。重定向。
访问者到达站点 B 后,他们无法点击“后退”按钮返回站点 A。点击“后退”会将他们带到带有 ?link 参数的页面,然后他们会再次重定向。
我是一名编码新手,因此感谢您的帮助和建议。谢谢!
编辑:本质上,我在这里所做的是动态更改引荐来源网址:
- 常规引荐来源网址:siteA.com/this-page.php
- 更新的引荐来源网址:siteA.com/this-page.php?link=top-banner
I have 2 websites -- website A is the primary 'marketing' site that receives traffic and website B is the site where people make a purchase. Site B's reporting system provides me with the referring URL from site A that resulted in a purchase.
Site A has a variety of call to action links that go to site B, and I would like to measure which of these links is most effective at driving sales.
Here's what I currently have set up:
Let's say you're on siteA.com/this-page.php. Normally, clicking on a link to site B would show this page as the referrer. Instead, a link to site B is siteA.com/this-page.php?link=top-banner&dest=home, where 'link' provides the id for the link being clicked and dest is the page on site B I want to send the click to.
I have a PHP include on every page of the site with this:
<?php
if (isset($_GET['link'])) {
$qs = $_SERVER['QUERY_STRING'];
$form_action = "/redirect.php?" . $qs;
?>
<html>
<body onload="document.forms.go.submit();">
<form method="post" action="<?php echo $form_action; ?>" name="go"></form>
</body>
</html>
<?php } else {} ?>
The redirect.php page figures out the destination page on site B and does a header redirect to the appropriate page.
This works fine for me right now and the referrer shows up properly in site B's stats.
This seems like an inelegant solution and I also run into a couple of usability issues:
There is a noticeable delay when you click on a link to site B, as the current page reloads, the form is submitted, and the visitor is redirected.
Once the visitor arrives at site B, they can't hit the 'back' button to get back to site A. Clicking back takes them to the page with the ?link parameter and they just get redirected again.
I'm a coding novice, so your help and suggestions are appreciated. Thanks!
EDIT: In essence, what I'm doing here is changing the referrer on the fly:
- regular referrer: siteA.com/this-page.php
- updated referrer: siteA.com/this-page.php?link=top-banner
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这就是流程:
我不确定我是否理解你的问题。您希望引荐来源网址停留在siteA.com/redirect.php?link=id&dest=home
而不是siteA.com/this-page.php?link=id&dest=家?为什么?
浏览器在遵循重定向时不会更改引荐来源网址,因此您确实需要转发技巧。
我建议您做的是将链接直接链接到
redirect.php
。引荐来源网址将是siteA.com/this-page.php
而不是redirect.php
,但我不明白为什么这是一个问题。So this is the flow:
I'm not sure I understand your question. You want the referrer to stay atsiteA.com/redirect.php?link=id&dest=home
and notsiteA.com/this-page.php?link=id&dest=home
? why?The browser doesn't change the referrer when it follows a redirect, so you really need your forward hack.
What I suggest you do do is to have your links link to
redirect.php
directly. The referrer will besiteA.com/this-page.php
instead ofredirect.php
, but I don't see why that's a problem.