[英]What's the easiest way to keep tracking a visitor through multiple pages?
I have users coming from both organic and paid search. 我的用户来自自然搜索和付费搜索。
organic users land on page.php
, paid users land on page.php?source=paid
. 随机用户登陆
page.php
,付费用户登陆page.php?source=paid
。
A PHP variable on page.php
would change according the source
string, to help me identify where the user initially came from, for example, if he purchase something on my site right from the same page, I would have an indication. page.php
上的PHP变量将根据source
字符串进行更改,以帮助我确定用户最初来自何处,例如,如果他直接从同一页面上在我的网站上购买了商品,则会有提示。
The problem: 问题:
I have multiple pages in my website. 我的网站上有多个页面。 once a paid user decides to navigate to another page such as
page2.php
, the indicating variable won't work, as he navigated to page2.php
, and not to page2.php?source=paid
. 一旦付费用户决定导航到另一个页面(例如
page2.php
,指示变量将不起作用,因为他导航到page2.php
而不是page2.php?source=paid
。
So one possible messy solution, would be to drag the string all over the website, by placing on every link, an IF/ELSE
that would insert at the end of all the href
in the page, a ?source=paid
string, in any case that the user initially landed with the ?source=paid
string. 因此,一种可能的混乱解决方案是,通过在每个链接上放置一个
IF/ELSE
,将字符串拖到整个网站上,该IF/ELSE
将插入页面中所有href
的末尾,一个?source=paid
字符串,用户最初使用?source=paid
字符串登陆的情况。
But, is there another option? 但是,还有其他选择吗? I suppose there's a way to do this with cookies?
我想有办法用Cookie做到这一点吗? but I have never dealt with cookies, and rather not to, unless it's easy.
但是我从来没有处理过cookie,除非很简单,否则我不会。
Thanks 谢谢
This is exactly what sessions are for: 这正是会话的目的:
Sessions are a simple way to store data for individual users against a unique session ID.
会话是根据唯一的会话ID为单个用户存储数据的简单方法。 This can be used to persist state information between page requests.
这可用于在页面请求之间保留状态信息。 Session IDs are normally sent to the browser via session cookies and the ID is used to retrieve existing session data.
会话ID通常通过会话Cookie发送到浏览器,并且该ID用于检索现有会话数据。
To solve this I would recommend you to use Sessions. 为了解决这个问题,我建议您使用Sessions。
On the first page you need to set the session variable with something like this: 在第一页上,您需要使用以下内容设置会话变量:
<?php>
session_start();
if isset($_GET['source']) {$_SESSION['source'] = $_GET['source'];}
and the rest of your first page goes here..
?>
On the other pages you can recall the sessionvariable like this: 在其他页面上,您可以像这样调用session变量:
<?php>
session_start();
if ($_SESSION['source'] == 'paid')
{ paid version}
else
{unpaid version}
?>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.