-
- 14 Posts
I use ModX evolution and I am looking for the best way to handle/track visitors filling out a form on my site. Basically When some visits my site from a Google ad-words ad, they might browse through a few pages on my site and fill out my form, I want to know that they came from Google, and if a visitor came to my site from Yahoo I would like to know they came from Yahoo, and Bing ect...
What would be the best way to accomplish this with ModX Evolution?
Any help pointing me in the right direction would be greatly appreciated.
Thanks,
-Eric
Hello,
This would likely be something to do with a cookie or session. Just have a snippet to record the entry information and store in cookie/session, then insert that in your form later.
-
- 24,544 Posts
You’ll want to make sure you only save the referer once. Something like this:
<?php
/* GetUrl snippet */
/* make sure we don't already have it */
if(!isset($_SESSION[’referer’])){
/*get the URL the user came from */
if ($_SERVER[’HTTP_REFERER’]){
$referer = $_SERVER[’HTTP_REFERER’];
} else {
$referer = “unknown”;
}
// save it in the $_SESSION variable
$_SESSION[’referer’] = $referer;
}
?>
If you put [!GetUrl!] near the top of your template, you can check the referer further down on any page with something like this:
<?php
if (stristr($_SESSION['referer'],'google')) {
return "User came from Google";
}
?>
Note that, unlike the real world, in the land of PHP it’s "referer" not "referrer"