![Sue5673885](https://vmapp.org/images/player/000default.jpg)
: 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
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
More posts by @Sue5673885
1 Comments
Sorted by latest first Latest Oldest Best
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'])
Terms of Use Create Support ticket Your support tickets Stock Market News! © vmapp.org2025 All Rights reserved.