Welcome to WebmasterWorld Guest from

Forum Moderators: DixonJones & mademetop

Message Too Old, No Replies

Capturing Keywords on Form

8:43 pm on May 25, 2010 (gmt 0)

10+ Year Member

I got a question I have some landing pages that I work with and I have the forms on the page send me an email with the information collected. Is there a way to add the keyword or even search query that the user came in on to the email that is sent to me?
7:58 am on May 26, 2010 (gmt 0)

WebmasterWorld Senior Member 5+ Year Member

I'm not sure if this is technically possible.
Your data come actually from OUTsource. Some statistical code connected to your page could perform this. But as I understand google does not support this.
3:51 pm on May 26, 2010 (gmt 0)

5+ Year Member


It's apparently not foolproof though.
9:34 pm on May 27, 2010 (gmt 0)

5+ Year Member

Unfortunately you won't get a referer if the search comes from the experimental google AJAX search or from the new https search.
This is a problem that I will have to deal with in my WP TID Generator product [wptidgenerator.com], too.

binarymonkey suggested the following code on the google forum [google.com] to deal with that problem:

* Returns an array with details held in Google Analytics cookie,
* or false if cookie not set.
* @returns array|bool
function google_analytics_cookie_data() {

if(isset($_COOKIE['__utmz'])) {

preg_match_all('$[a-z]*=[^\|]*$', $string, $matches);

$ga_data = array();
foreach($matches[0] as $kvpair) {

$bits = explode('=',$kvpair,2);

$key = $bits[0];
$val = $bits[1];

switch($key) {

case 'utmcsr':
$key = "Source";

case 'utmccn':
$key = "Campaign";

case 'utmcmd':
$key = "Medium";

case 'utmcct':
$key = "Referring Page";

case 'utmctr':
$key = "Keywords";


$ga_data[$key] = $val;


return $ga_data;

} else {
return false;


It extracts the keywords from the google analytics cookie, which of course means that you have to run google analytics in order to be able to use it.