Last Updated:

Transcript of search query statistics

This article presents a PHP script on the basis of which it will be easy to create a module for statistics of search queries for your site. Such a module can fish out from the search query by which the user came to your site, the name of the search engine and the actual search query itself. All this can be accumulated in a text or other database with subsequent output to any page of the site located in the admin panel. Such statistics are very useful for the site admin, because it gives a complete picture of site traffic from search engines. In the future, everything can be developed and tied queries to the pages of the site, which will give a picture of the attendance of each individual page from search engines. There's a lot more to speculate about that. In short, here is the script itself:

As you know, the transition to the site from the search engine is stored in the superglobal $_SERVER['HTTP_REFERER'] So the query can be loaded, for example, in $refer

$refer = !empty($_SERVER['HTTP_REFERER'] ? strtolower($_SERVER['HTTP_REFERER']): 'None')

Next, we will work with $refer from which you need to extract a search query and determine the search engine from which the transition to the site was performed. Before you fish out the query itself, you need to determine the search engine from which it came, because only then it will become clear in which variable passed with the request the request itself is stored. This is easy to do with a matrix or a list of search engines. Such a list can be found on the Internet in different versions. But my attention was drawn to a matrix of search engines of this kind:

$searchEngines=array(
'images.google.' =>array('q','prev'),
'bing.com'=>'q',
'.alot.' =>'q',
'a993.com'=>'q1',
'abcsok.' =>'q',
'alltheweb.' =>'q',
'altavista.' =>'q',
'aol.' =>array('q','query','encquery'),
'aolsvc.' =>'query',
'avantfind.com'=>'keywords',
'bonvote.com'=>'search',
'bonweb.com'=>'search',
'comcast.net'=>'q',
'conduit.' =>'q',
'eniro.se'=>'search_word',
'excite.' =>'search',
'google.' =>array('q','as_q'),
'gogo.com'=>'q',
'yandex.' =>array('text','query'),
'ya.com'=>'text',
'hotbot.' =>'query',
'icerocket.com'=>'q',
'icq.com'=>'q',
'isheyka.com'=>'q',
'midco.net'=>'q',
'live.com'=>'q',
'msn.' =>'q',
'yahoo.' =>array('p','k'),
'search.' =>'q',
'kvasir.no'=>'q',
'myway.com'=>'searchfor',
'netscape.' =>array('q','query'),
'oceanfree.net'=>'as_q',
'qip.com'=>'query',
'sweetim.com'=>'q',
'tut.by'=>'query',
'ukr.net'=>'search_query',
'search.oboz.ua'=> k',
'search.www.infoseek.co.jp'=>'qt',
'.setooz.com'=>'query',
'toile.com'=>'q',
'vinden.nl'=>'q',
'.i.ua'=>'q',
'. mail.com'=>array('q','tag'),
'.oncom.com'=>'q',
'aport.com'=>'r',
'find.com'=>'text',
'gde.com'=>array('keywords','query','t','search_query','id'),
'go.km.com'=>'sq',
'meta.ua'=>'q',
'metabot.com'=>'st',
'necoms.com'=>'query',
'nigma.com'=>array('s','pq'),
'nova.rambler.com'=>'query',
'poisk.com'= >'text',
'protonet.com'=>'q',
'rambler.com'=>'words',
'tyndex.com'=>'pnam',
'webalta.com'=>'q',
'exactseek.com'=>array('q','query'),
'lycos.' => 'query',
'ask.' => 'q',
'cnn.' => 'query',
'looksmart.' => 'qt',
'about.' => 'terms',
'mamma.' => 'query',
'gigablast.' => 'q',
'voila.' => 'rdata',
'virgilio.' => 'qs',
'baidu.' => 'wd',
'alice.' => 'qs',
'najdi.' => 'q',
'club-internet.' => 'q',
'mama.' => 'query',
'seznam.' => 'q',
'netsprint.' => 'q',
'szukacz.' => 'q',
'yam.' => 'k',
'pchome.' => 'q',

);

If you look closely, this matrix is arranged very competently. The keys are the strings from part of the names of the search engines, and the parameters are the name (names) of the variables in which the query text is transmitted. The task of the script is to get the text of the search query and the name of the search engine from where the transition to your site was made based on the content of the $refer and above the matrix presented. Below is such a simple script, in which the name of the search engine will be located in the $site, and the text of the search query will be $s_word.

$tmp = parse_url(urldecode(trim($refer)));
$site = $tmp['host'];
$str = $tmp['query'];
parse_str($str,$arr);
foreach ($searchEngines as $key=>$value)
{
if(substr_count($site, $key))
{
foreach ($arr as $k=>$v)
{
if(is_array($value))
{
if(in_array ("$k",$value))
{$s_word = $v; break;}
}
elseif("$k" == $value) {$s_word = $v; break;}
else {$s_word = "None"; break;}
}
break;

}
}

Such a technique and statistics of search queries are successfully implemented on <a ="="" acvarif.net.com"="" target="_blank" _mstmutation="1" _istranslated="1">the php engine without Acvarif-CMS databases. Statistics works without complaints and gives, among other things, a lot of all sorts of usefulness - statistics of visits from search engines in quantitative form, statistics of search queries for the site as a whole and for each page separately, etc. The advantage of this option is its simplicity and speed of work.