If you want to capture google search terms and display keywords on your site then this is what to do.You can create a php script file and upload to your web host.
Here is the code for the php script file.Name the file as display-keywords.php.Change file permissions to 755 after upload.
// take the referer $thereferer = strtolower($_SERVER['HTTP_REFERER']); // see if it comes from google if (strpos($thereferer,"google")) { // delete all before q= $a = substr($thereferer, strpos($thereferer,"q=")); // delete q= $a = substr($a,2); // delete all FROM the next & onwards if (strpos($a,"&")) { $a = substr($a, 0,strpos($a,"&")); } // we have the results. $mygooglekeyword = urldecode($a); } $file_name = "/home/hosting-username/public_html/keywords.txt"; if (!($mygooglekeyword=="")) { $file_handle= fopen($file_name,"a");//places file ptr at end of file ,file open for writing a+ both reading writing $output_string = $mygooglekeyword."\n"; fwrite($file_handle,$output_string); fclose($file_handle); } $file_handle= fopen($file_name,"r");//places file ptr at beg of file ,file open for reading $file_contents_string = file_get_contents($file_name); $pieces = explode("\n", $file_contents_string);//our file has a new line separator $unique_pieces = array_unique($pieces); foreach ($unique_pieces as $v) { echo $v." "; } fclose($file_handle); ?>
Also create and upload an empty file keywords.txt to the path as set in $file_name.
Next you need to call the file display-keywords.php somewhere.The ideal place is your website’s footer.Add the following code to the file displaying your website’s footer.
<?php include "/home/hosting-username/public_html/display-keywords.php" ; ?>
That is all is required.You may format the output to appear in some div tag like
<div class="your-style-class">People came to this site looking for : <?php include "/home/hosting-username/public_html/display-keywords.php" ; ?></div>
The google search keywords will now be displayed on website.Note that each keyword search will be stored in the txt file,i.e duplicates will be stored for you to count the number of searches,but when displaying the data,duplicate keywords will be removed.
That is all.
If you liked this article please do leave a reply and share it with friends.
Thanks.