Using the Google Analytics API to make most popular pages widgets for your website


Published on

Using the Google Analytics API to create a most popular pages widget for your website or blog using the Google Analytics API. I'll demonstrate a custom report in Google Analytics, then show how to automate the same using Perl and the Google Analytics API to create an RSS feed of the top 10 stories from my blog — which I then incorporate into the siderail of my blog using a WordPress RSS widget.

Here's the link to code in GitHub:

Published in: Technology, Business
1 Comment
  • This is a super handy presentation, Dean, thanks! It actually gave us some inspiration to write a tutorial on how to do this, but in real-time, with GoSquared:
    Are you sure you want to  Yes  No
    Your message goes here
No Downloads
Total views
On SlideShare
From Embeds
Number of Embeds
Embeds 0
No embeds

No notes for slide

Using the Google Analytics API to make most popular pages widgets for your website

  1. 1. Using the Google Analytics API ... <ul><li>… to make most popular pages </li></ul><ul><li>widgets for your website. </li></ul><ul><li>by </li></ul><ul><li>@DeanPeters </li></ul><ul><li> </li></ul><ul><li>Slides: </li></ul><ul><li>Code: </li></ul>
  2. 2. Intro <ul><li>Who am I? </li></ul><ul><ul><ul><li>I'm the artist+geek linchpin Seth Godin warned you about. </li></ul></ul></ul><ul><li>What do I do? </li></ul><ul><ul><ul><li>I manage one of the Support Development Teams at McClatchy Interactive. </li></ul></ul></ul><ul><li>Why am I doing this presentation? </li></ul><ul><ul><ul><li>I'm a self-admitted analytics and social media API junkie </li></ul></ul></ul>
  3. 3. Some funs stuff I've done <ul><li>FaceBook Like Button </li></ul><ul><ul><ul><li>Wrote a popular Facebook like button plugin for WordPress </li></ul></ul></ul><ul><li>Heal Your Church Website </li></ul><ul><ul><ul><li>Where I blog about my usability & API addictions </li></ul></ul></ul><ul><li>Son of Web Pages that Suck </li></ul><ul><ul><ul><li>I was a contributing author to that 2002 classic </li></ul></ul></ul>
  4. 4. Most Popular Pages Widget <ul><li>What is it? </li></ul><ul><ul><ul><li>It's usually a box on the side rail that list linked titles to the most read stories on a website or blog </li></ul></ul></ul><ul><li>How popular is it? </li></ul><ul><ul><ul><li>You often see this widget on news media sites </li></ul></ul></ul><ul><li>Can we see some examples? </li></ul><ul><ul><ul><li>Sure </li></ul></ul></ul>
  5. 5. Bradenton Herald
  6. 6. USA Today
  7. 7. Lexington Herald-Leader
  8. 8. Most Popular Pages <ul><li>Where do they get the data? </li></ul><ul><ul><ul><li>From sources such as Google Analytics & Omniture </li></ul></ul></ul><ul><li>Can I do this with my website or Blog? </li></ul><ul><ul><ul><li>Sure </li></ul></ul></ul>
  9. 9. What you'll need <ul><li>A Website or Blog </li></ul><ul><ul><ul><li>For today's example, we'll use WordPress </li></ul></ul></ul><ul><li>An Analytics Service with an API </li></ul><ul><ul><ul><li>For today's example, we'll use Google Analytics </li></ul></ul></ul><ul><li>A programming language </li></ul><ul><ul><ul><li>For today's example, we'll use Perl </li></ul></ul></ul>
  10. 10. Google Analytics Dashboard <ul><li>Standard Reporting </li></ul><ul><ul><ul><li>How to filter your popular pages via GA's standard reports </li></ul></ul></ul>
  11. 11. Google Analytics Dashboard <ul><li>Custom Reporting </li></ul><ul><ul><ul><li>How to create a custom report </li></ul></ul></ul>
  12. 12. Why You Need an API <ul><li>Exporting from the Dashboard ... </li></ul><ul><ul><ul><li>… is a process that is tedious and unsustainable </li></ul></ul></ul><ul><li>Using an API ... </li></ul><ul><ul><ul><li>… allows you to automate this process </li></ul></ul></ul><ul><li>Using a Programming Language ... </li></ul><ul><ul><ul><li>… let's you fine-tune the data and reports you need </li></ul></ul></ul>
  13. 13. What is the Google API? <ul><li>One of many API web services ... </li></ul><ul><ul><ul><li>… found at </li></ul></ul></ul><ul><li>What does it provide? </li></ul><ul><ul><ul><li>Programmatic access to Google Analytics report data & statistics derived from the data collected on your site, organized as dimensions and metrics . </li></ul></ul></ul>
  14. 14. Dimensions & Metrics <ul><li>You've already seen these ... </li></ul><ul><ul><ul><li>… in custom & standard reports </li></ul></ul></ul><ul><li>Dimensions ... </li></ul><ul><ul><ul><li>… are the rows of data </li></ul></ul></ul><ul><li>Metrics ... </li></ul><ul><ul><ul><li>… are columns of data in the rows </li></ul></ul></ul>
  15. 15. Accessing the API <ul><li>You'll need to be authenticated ... </li></ul><ul><ul><ul><li>… in this case we'll use a gmail id & password </li></ul></ul></ul><ul><li>You'll need the Profile ID ... </li></ul><ul><ul><ul><li>… this is NOT the UA key </li></ul></ul></ul><ul><li>You'll need to filter the data ... </li></ul><ul><ul><ul><li>… using our old friends dimensions & metrics </li></ul></ul></ul>
  16. 16. Coding for the API <ul><li>You'll need to be authenticated ... </li></ul><ul><ul><ul><li>… with Perl, we'll use Net::Google::AuthSub </li></ul></ul></ul><ul><li>You'll need to talk via your Profile ID ... </li></ul><ul><ul><ul><li>… with Perl, we'll use Net::Google::Analytics </li></ul></ul></ul><ul><li>You'll need to output the data ... </li></ul><ul><ul><ul><li>… with Perl, we'll use XML::FeedPP </li></ul></ul></ul>
  17. 17. <ul><li>This is where I show you some code </li></ul>
  18. 18. Limitations of the API <ul><li>Authentication is often a hurdle ... </li></ul><ul><ul><ul><li>… for Google Analytics, investigate using OAuth </li></ul></ul></ul><ul><li>Be careful of quanity ... </li></ul><ul><ul><ul><li>… don't get penalized for asking for everything all the time </li></ul></ul></ul><ul><li>Don't expect miracles ... </li></ul><ul><ul><ul><li>… the quality of the data you pull is directly proportional to to how well you've setup & configured Google Analytics </li></ul></ul></ul>
  19. 19. Implementing the Code <ul><li>Crontab the program </li></ul><ul><ul><ul><li>* */12 * * * perl password </li></ul></ul></ul><ul><li>Add the output to your blog ... </li></ul><ul><ul><ul><li>… here's where I show you some WordPress widgetry </li></ul></ul></ul>
  20. 20. Voilà <ul><li>This is where I show you some results </li></ul>
  21. 21. Take-Aways <ul><li>Coding is 'easy-enough' ... </li></ul><ul><ul><ul><li>… if you let other libraries & modules do the heavy-lifting </li></ul></ul></ul><ul><li>Garbage-in/Garbage-out ... </li></ul><ul><ul><ul><li>… the API can only 'pull' what data your actively tracking </li></ul></ul></ul><ul><li>Have fun & explore... </li></ul><ul><ul><ul><li>… you'll be amazed at how many different and cool ways you can slice-n-dice your data in a coder's context </li></ul></ul></ul>
  22. 22. Questions & Answers <ul><li>On creating a Most Popular Pages widget for your website using the Google API. </li></ul><ul><li>by </li></ul><ul><li>@DeanPeters </li></ul><ul><li> </li></ul><ul><li>Slides: </li></ul><ul><li>Code: </li></ul>