Know what you should be publishing about right now with GoogleTrends and a bit of PHP

Discussion in 'Search Engine Optimization' started by JamesColin, Sep 30, 2012.

  1. #1
    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 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:
    http://www.google.com/trends/explore#q=

    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>
    
    Code (markup):
    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>';
    ?>
    
    Code (markup):
    $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>';
    
    Code (markup):
    &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.
     
    Last edited: Sep 30, 2012
    JamesColin, Sep 30, 2012 IP