Create a page on your site / blog for weekly inspiration with Google Trends and PHP

1 post / 0 new
Create a page on your site / blog for weekly inspiration with Google Trends and PHP

Hello,

Maybe you know that Google Insights has been merged with Google Trends. They were very similar anyway, so it made sense to have them both into one tool. I talked about it already here: "What are the most searched for keywords on Google?", but today I'm going to show you how you can also create the same thing on your own site / blog, so you can share it with your visitors and I guess because you just are more likely to look at the page often instead of coming to my site to study what's going on in online searches, it just makes more sense for you to have such a useful page on your own site / blog..

I would like to show you in details how you can make a page on your site that will embed their widgets, so you can have an overview of what's popular and even what is going to be popular in the next few months, for recurring / seasonal keywords.

First, when you go to Google Trends, the important part is not the front page or the hot trends, but rather this url:
Google Trends

The way it works is you enter a keyword, choose a category and see related terms which are most popular and top rising for the last X days/months/etc.

But by putting no keyword, selecting no category, then you get an idea of what's really popular and rising, all niches included.

Ultimately it's up to you to modify the script I'll show you, so that you can target a specific category, keywords and even country, but for the purpose of this tutorial, I will use worldwide, all categories and no keywords..

Here is the code, I'll explain a few things below:

<?php
$mylastyear = date('Y') - 1;
$mymonth = date('n');
?>
<div align="center"><table>
<tr>
<td align="center">
<script type="text/javascript" src="http://www.google.com/trends/embed.js?hl=en-US&date=today+7-d&cmpt=q&content=1&cid=RISING_QUERIES_0_0&export=5&w=300&h=420"></script>
</td>
<td align="center">
<script type="text/javascript" src="http://www.google.com/trends/embed.js?hl=en-US&date=today+1-m&cmpt=q&content=1&cid=RISING_QUERIES_0_0&export=5&w=300&h=420"></script>
</td>
</tr>
<tr>
<td align="center">
<script type="text/javascript" src="http://www.google.com/trends/embed.js?hl=en-US&date=today+3-m&cmpt=q&content=1&cid=RISING_QUERIES_0_0&export=5&w=300&h=420"></script>
</td>
<td align="center">
<script type="text/javascript" src="http://www.google.com/trends/embed.js?hl=en-US&date=today+12-m&cmpt=q&content=1&cid=RISING_QUERIES_0_0&export=5&w=300&h=420"></script>
</td>
</tr>
<tr>
<td align="center">
<?php
echo '<script type="text/javascript" src="http://www.google.com/trends/embed.js?hl=en-US&date='. $mymonth .'/'. $mylastyear .'+2m&cmpt=q&content=1&cid=RISING_QUERIES_0_0&export=5&w=300&h=420"> </script>';
?>
</td>
<td align="center">
<?php
echo '<script type="text/javascript" src="http://www.google.com/trends/embed.js?hl=en-US&date='. $mymonth .'/'. $mylastyear.'+4m&cmpt=q&content=1&cid=RISING_QUERIES_0_0&export=5&w=300&h=420"> </script>';
?>
</td>
</tr>
</table></div>

First, how do I find the code for the widget, this is easy, as you use google trends, you can see a button at the bottom right of the result which says "Embed" and then simply by selecting different categories, keywords, country, type of search you can clearly see what variables/arguments they use in the code of their widget.

I think most of you know this already, so I'll focus on the PHP part because even if it's basic and most of you already know it too, I think there is more people who don't know that simply because they never needed to learn basic PHP to be successful online anyway.. So:

<?php
$mylastyear = date('Y') - 1;
$mymonth = date('n');

echo '<script type="text/javascript" src="http://www.google.com/trends/embed.js?hl=en-US&date='. $mymonth .'/'. $mylastyear .'+2m&cmpt=q&content=1&cid=RISING_QUERIES_0_0&export=5&w=300&h=420"> </script>';

echo '<script type="text/javascript" src="http://www.google.com/trends/embed.js?hl=en-US&date='. $mymonth .'/'. $mylastyear .'+4m&cmpt=q&content=1&cid=RISING_QUERIES_0_0&export=5&w=300&h=420"> </script>';
?>

$mylastyear = date('Y') - 1;
$mylastyear will have as of today: 2011, because date('Y') returns the current year and 1 is substracted to it.

$mymonth = date('n');
$mymonth will have as of today: 9, because date('n') return the current month number without leading 0

Those 2 variables will be used to be put in the widget code, so that it is always current, no matter when you're looking at your page, 6 months or 2 years from now:

echo '<script type="text/javascript" src="http://www.google.com/trends/embed.js?hl=en-US&date='.$mymonth.'/'.$mylastyear.'+2m&cmpt=q&content=1&cid=RISING_QUERIES_0_0&export=5&w=300&h=420"></script>';

&date='.$mymonth.'/'.$mylastyear.'+2m
translates into &date=9/2011+2m
and that will show you what were the top rising queries during the months of september and october 2011. This can be useful to spot recurring trends, seasonal things.
For instance we can see that "halloween costumes" has been rising, of course that is obvious, but there are other things that are not obvious, like tv programs, if you see big brother 2011 then you know you could write in advance about big brother 2012, or at least you know that some keywords will become popular again. Of course it doesn't work for everything, like the event of the death of steve jobs is not going to trigger a rising keyword this year, but some of those keywords can be useful, you just have to analyse them and use common sense.

I hope this helps you creating a useful predictive page for your own niches and keywords to ease your research process, if you have questions or ideas to improve upon it, please share.

Your feedback is important to us! We invite all our readers to share with us their views and comments about this page.

The content of this field is kept private and will not be shown publicly.
Please answer the question, even if it looks like a very stupid question, it filters out most of the spam.
Valentus