cool tech graphics

Drupal Views now supports queries of Google Analytics report data

Filed under:

Views 3 now supports queries against Google Analytics. I've added this experimental module to the 7.x-3.x development release of Google Analytics Reports.

Queries supported

Most popular Google Analytics queries currently pass:

  • Most popular content, sorted by most pageviews
  • All traffic by search engine, sorted by pageviews in descending order
  • Visits broken down by search engine keywords used, sorted by visits in descending order
  • Revenue generated through the site for the given time span, sorted by visits in descending order
  • New visits vs. returning visits
  • Visits by country, sorted by number of visits
  • Visits by the Operating System, web browser, and browser version used
  • Traffic source and medium, sorted by visits in descending order

The tests above pass, but the code is rough. I have yet to refactor it, and there is some spaghetti code in there that needs to be gobbled up

New Query Type

When creating a new view, select "Google Analytics" from the wizard drop down.

Display Format

The default display formats of Grid, HTML list, Jump menu, Table, and Unformatted list tend to work as expected. I wasn't able to get Chart Views working very well, unfortunately. It'll take some work to get charts working correctly.

Fields - For both metrics and dimensions

One metric is always required, but you may have several. Dimensions are optional, and you can have as many as you want. It can be a bit tricky to learn when a metric and a dimension are incompatible, but for most general uses, you should be fine. To understand which metrics and dimensions can be used together, use the checkbox on/off tool offered in the Core Reporting API v3 documentation.

Filters - For both metrics and dimensions

The only required filter is the start/end day of the report. We added a default of 2005 if you don't provide a start date. All other filters work mostly as designed. I added a Profile ID filter as well, so you could change which Google Analytics profile you were looking at for this view.

AND/OR groups should also work, but the Core Reporting API has limits in this area. I need to invest some in making this more usable for admins.

Sort - For both metrics and dimensions

Sort works as expected - ascending and descending. I haven't done too many tests with multiple sorts, but the few multiple sorts I tried seemed to work well.

Contextual Filters - For both metrics and dimensions

Like with filters, arguments works mostly as expected. I also added a Profile ID here, so that you could have different report profiles for different views. I'm excited to implementations where Views, with exposed filters, show admins their Google Analytics data across multiple profiles.


All the default paging options should work: Full, mini, limit to a specific number only, and no paging. Exposed pagers should also work fine.


I haven't added any relationships yet, but I am excited about the possibilities.

Bugs please!

Please file a billion bugs in the issue queue. I need lots of eyes to help solidify this module.

Date posted: May 3, 2012


Wow, thanks!

It seems to me that this is a great way to:

  1. give executives custom displays of analytic data, avoiding the Google Analytics "cockpit" effect.
  2. A great way to provide gated access to website Google Analytics data without needing to provide complete access.


Great addition, really useful!


This is the best bit of Drupal related news I've seen in ages. As someone who does a lot of SEO and has a great interest in SEO and analytics this is something I've often thought about. Huge thumbs up from me.

I am looking into building an editorial screen for managing old content, which might getting stale. But before the editor should delete the page, he should be able to see how many visits the page generates over time. Is that possible using this?

Almost there :) We are working on a solution to join pages with content. Right now, alas, there is no relationship with nodes in the module.

Feel free to experiment and post your findings to the issue queue on

Hi Tony and thanks for this awesome implementation!

Unfortunately I've installed everything as you describe in this article but I can't see Google Analytics on my dropdown list.

Any idea?

I cant add any relationships. why is that? I would like to use that for listing content and sort it by popularity. I gueas i need to add relationship to content to be able to add fields from content, like node title, image and so on?

It's a feature we would like have also:
#1742914: Support views relationship with nodes

However, there is no method known to me that will enable Views to form relationships between heterogenous data types (in this case, the REST+XML API and SQL).

... I'm completely blocked from using it by the dependency on Google Chart API which is now deprecated by Google and can be switched off at any moment :( I can't build a website with that risk hanging over it, sorry!

Any way around this, thanks?

Add new comment

Restricted HTML

  • Allowed HTML tags: <a href hreflang> <em> <strong> <cite> <blockquote cite> <code> <ul type> <ol start type> <li> <dl> <dt> <dd> <h2 id> <h3 id> <h4 id> <h5 id> <h6 id>
  • You can enable syntax highlighting of source code with the following tags: <code>, <blockcode>, <cpp>, <java>, <php>. The supported tag styles are: <foo>, [foo].
  • Web page addresses and email addresses turn into links automatically.
  • Lines and paragraphs break automatically.

Metal Toad is an Advanced AWS Consulting Partner. Learn more about our AWS Managed Services

Have questions?