Mobile app version of vmapp.org
Login or Join
Sue5673885

: Tracking Keyword user used to get to website Is there a way we can add the ability to track what keywords the user has used to end up on our website? i.e. If they type in Software into

@Sue5673885

Posted in: #Analytics #GoogleAnalytics #GoogleSearch #Seo

Is there a way we can add the ability to track what keywords the user has used to end up on our website? i.e. If they type in Software into google and our site pops up in the SEO list, when they click on it I want to log an entry into our db from logic in the home page to say the user used keyword 'Software' and also maybe offer some different features on the home page depending on the keyword used.

Thanks

10.01% popularity Vote Up Vote Down


Login to follow query

More posts by @Sue5673885

1 Comments

Sorted by latest first Latest Oldest Best

 

@Gail5422790

You can extract the keywords that the user searched from the HTTP_REFERER header.

Google uses the GET parameter "q" to send the terms that the user searched. Note that the terms are not always send, and the parameter q will be empty. This is based on each visitor's privacy settings, browser settings etc

You can use a function like this:

function extract_keywords($referral)
{
$parsed = parse_url($referral);
parse_str($parsed['query'], $query);

//Check if referral is Google
if (stripos($parsed['host'], 'www.google.') !== false)
{
if (!isset($query['q']{0}))
return false;

return trim($query['q']);
}
}

$a = 'https://www.google.gr/url?sa=t&rct=j&q=test';

echo extract_keywords($a);


Or in real project, use the $_SERVER['HTTP_REFERER'];

echo extract_keywords($_SERVER['HTTP_REFERER'])

10% popularity Vote Up Vote Down


Back to top | Use Dark Theme