How to compare keywords with google trends

Authors: CodeToday | Google Trends | Views: 677 | Posted: 07 AM: 09/10/2017

Google trends are the best tool for comparing visits between keywords, You can watch live on google with the following link https://trends.google.com/trends/. If you are not sure to use keywords for SEO or advertising, google trends will help you do this, it will tell you trends and searches for each keyword over a period of time.

This article will guide you to use google trends to display directly on your website using php code.

HTML

Below is an example of some keywords related to "Ohio state". In this form I will take the submit keyword as array

<form action = "" method = "post">
<div class="row">
	<div class="col-sm-4"><p><input name="valKey[]" value="Ohio state football" checked="" type="checkbox"> Ohio state football</p></div>
	<div class="col-sm-4"><p><input name="valKey[]" value="ohio state football schedule 2017" type="checkbox"> ohio state football schedule 2017</p></div>
	<div class="col-sm-4"><p><input name="valKey[]" value="ohio state football schedule" type="checkbox"> ohio state football schedule</p></div>
	<div class="col-sm-4"><p><input name="valKey[]" value="ohio state football score" type="checkbox"> ohio state football score</p></div>
	<div class="col-sm-4"><p><input name="valKey[]" value="ohio state football roster" type="checkbox"> ohio state football roster</p></div>
	<div class="col-sm-4"><p><input name="valKey[]" value="ohio state football tickets" type="checkbox"> ohio state football tickets</p></div>
	<div class="col-sm-4"><p><input name="valKey[]" value="ohio state football recruiting" type="checkbox"> ohio state football recruiting</p></div>
	<div class="col-sm-4"><p><input name="valKey[]" value="ohio state football news" type="checkbox"> ohio state football news</p></div>
	<div class="col-sm-4"><p><input name="valKey[]" value="ohio state football game" type="checkbox"> ohio state football game</p></div>
	<div class="col-sm-4"><p><input name="valKey[]" value="ohio state football stadium seating chart" type="checkbox"> ohio state football stadium seating chart</p></div>
	<div class="col-sm-4"><p><input name="valKey[]" value="ohio state football schedule 2017 printable" type="checkbox"> ohio state football schedule 2017 printable</p></div>
	<div class="col-sm-12"><button class="btn btn-info" type="submit" name="Compare" value="Compare"><i class="glyphicon glyphicon-search"></i> Compare Search</button> <em>( Please select at least <b>2 keywords</b> )</em></div>
</div>
</form>

PHP Soucre Code

<?
if(isset($_POST['Compare']) && count($_POST['valKey']) > 0) {

echo '<h2>Results</h2>';
	
	foreach($_POST['valKey'] as $val) { 
		$valKey[]  = '{"keyword":"'.$val.'","geo":"","time":"today 12-m"}';
		$valItem[] = urlencode($val);
	}
	$valQuery = implode(',',$valKey);	
	$valItem  = implode(',',$valItem);	
	?> 
        // Below javascript code embed from google trends
	<script type="text/javascript" src="https://ssl.gstatic.com/trends_nrtr/1101_RC02/embed_loader.js"></script>
	<script type="text/javascript">
		trends.embed.renderExploreWidget("TIMESERIES", {"comparisonItem":[<?=$valQuery?>],"category":0,"property":""}, {"exploreQuery":"q=<?=$valItem?>&date=today 12-m","guestPath":"https://trends.google.com:443/trends/embed/"});
	</script>
<? }?>

After you completed the above steps and click submit your results will look like the image below


If you have any questions, please leave a message below

sweetselle

This was very helpful for me for researching all the trends i needed, so that i can stay updated with the news happening around. http://primacontent.com/

Posted: 10/13/2017