Drupal Views now supports queries of Google Analytics report data

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.

Pager


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

Relationships

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.

Comments

joaquin's picture

User Restrictions

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.

Superawesome!

Great!

Great addition, really useful!

Perfect!

Perfect!

Fantastic

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.

Get visits pr. page

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?

tony's picture

Almost there :) We are

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 drupal.org

Google Analytics not appearing in the views dropdown

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?

Reletionships

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?

Add new comment