The in development Views 3 supports the ability to query something other than a SQL database, such as a web service. For more information on this see #293841: Allow different back-ends for Views and a Flickr proof of concept at http://developmentseed.org/blog/2009/feb/05/extendr-flickr-and-views.

For a future version (2.x perhaps?), I think this is where the Google Analytics API should be headed. Views integration would open up all kinds of integration possibilities and would allow all charting/mapping to be done via any visualization system that provides views display capabilities.

Comments

greggles’s picture

Another idea is to store the values locally. The module could periodically get some data (like page visits) from google analytics and store those in a local database table and then add views metadata for that table so it can be used with a relationship to the node table.

Also, subscribe and I'm potentially going to work on this in the next few days.

rickvug’s picture

@greggles That is certainly one approach. I wonder how well it will scale on a site with many pages that wants to have data updated daily. I'm also wondering out loud about data retention clauses for the API. Does Google say anything about storing data locally? I haven't looked into terms of use one way or another. Don't let any of these comments discourage work. Just thinking out loud here.

shrimphead’s picture

subscribing

jkitching’s picture

Just to let everyone know, I'm planning on applying for another GSoC grant ths summer to continue development on the Google Analytics API module. Views 3 could be one of the major features written.

greggles’s picture

Title:Expose Google Analytics data to Views» Expose node page views data to Views

Updating the title to refer to exactly what I need. If others want something different I should be clear.

Also, I hope to have a patch (or a new module, not sure) real soon now.

greggles’s picture

Title:Expose node page views data to Views» Integrate with Views so Views can use Google Analytics as a data source

Nevermind!

What I needed is already possible with http://drupal.org/project/ga_customvars so I'm switching this back to the much more complex (and exciting) purpose of making Google Analytics a live backend for the data.

grendzy’s picture

Project:Google Analytics API» Google Analytics Reports
Version:6.x-1.x-dev»
achton’s picture

This would allow for some interesting "Related Content"-type applications, AFAICT. If E-commerce data was available as well, the Ubercart/Commerce guys would probably wet their pants.

So subscribing.

dstol’s picture

To latch on here... much of the lift of importing GA data into Drupal has been implemented in http://drupal.org/project/ga_importer

grendzy’s picture

dstol: interesting! As we're conceptualizing it now, the views integration would be a views 3.x query plugin - so views could query GA directly.

I see there are advantages to updating the {node_counter} table, as well, so we may want both. A question, I assumed {node_counter} was "owned" by the core statistics module, but looking at the core install files this seems to be not the case? What are your thoughts?

jimmynail’s picture

subscribing.

GA data like visits, keywords, adsense cpm available through Views would enable all kinds of great.

greggles’s picture

Version:» 6.x-1.x-dev

@grendzy, as of a few months ago the ga_importer updates both node_counter AND its own table. The latter seems like the right thing for us to do, it just needs views integration so we can sort views by it and then we can drop the updating of node_counter.

dstol’s picture

@grendzy, updating {node_counter} was necessary for my use case. My site sits behind Akamai so 90% of the traffic is served out of their edge. We wanted to use some of the blocks for popular content for an internal dashboard and ga_importer is what we came up with.

I'm all for dropping support for updating {node_counter} but I'd also like to a hook like hook_google_analytics_api_incoming_data() so that other tables could be used as well.

grendzy’s picture

I found this list of known query plugins, that we can use for inspiration / code samples:
http://drupal.org/node/1126578

grendzy’s picture

dstol: From #440768: Transfer the {node_counter} table from node.module, I infer that node_counter really belonged to the statistics module all along; the fact that it was previously in node.install was just an oversight.

Can you explain more about the use case for the proposed hook_google_analytics_api_incoming_data()? We are mostly expecting modules to fetch data they need with google_analytics_api_report_data().

kryptik’s picture

subscribing

jameswoods’s picture

subscribing

nicoz’s picture

Possible duplication of efforts? http://drupal.org/project/ga_stats

grendzy’s picture

Yes, indeed it also duplicates http://drupal.org/project/google_analytics_counter and http://drupal.org/project/ga_importer .

The aim of this issue is fundamentally different, however - we hope to write a query plugin that bypasses the database entirely.

SWMdave’s picture

Subscribe-

ximo’s picture

Shamelessly subscribing…

I hope this effort will be for 7.x as well?

SchwebDesign’s picture

subscribing- i need this for Views 3 in Drupal 6... is how similar is that to the code for Views 3 in Drupal 7?.... i'm guessing different enough there'd need to be a views 2 and views 3 version for Drupal 6 or one that can handle both?

grendzy’s picture

Status:Active» Patch (to be ported)

Raspberryman has done it! Check out the 7.x-3.x branch, and the announcement on metaltoad.com.

Angry Dan’s picture

Has anyone got any ideas on how we could relate this back to the node table? It would be really interesting if we could find a way of joining the data back to node so that you could create relationships in the interface.

Tander1’s picture

That's great news for users of Drupal 7... any ideas if this can be done for 6 ?

jtbayly’s picture

"Has anyone got any ideas on how we could relate this back to the node table?"

Yes, this is exactly what I want to know. (Because it's exactly what I need!)

-Joseph

gstout’s picture

Subscribing. Need this for Drupal 6. I've hacked together some horrible direct calls into views for this purpose but would much prefer using this new system.

jtbayly’s picture

Status:Patch (to be ported)» Needs work

I'm sorry it's only D7, but ga_stats provides truly useful views integration with Google Analytics, including relating the data to the node table so that the queries are actually useful. I'm quite pleased with it. Even though it is limiting in terms of what you can actually query, it is the only module that really worked for me.

I needed to produce a "most popular content" block on a server with heavy caching. The only practical way to do this is to rely on data from Google Analytics for pageviews. But ga_importer is basically abandoned now, and google_analytics_counter wasn't actually putting the statistics into the core table like it's supposed to. And google_analytics_reports allowed me to get the data, but there was no way for me to get the node title into the view for displaying on the front-end.

If that last hurdle could be overcome with this module, I think we could move this out of "needs work" but until then, I don't think views integration is really complete. Maybe somebody can take a look at how they did it in ga_stats and do that here too?

-Joseph

grendzy’s picture

Component:Code» Views module
Status:Needs work» Patch (to be ported)

jtbayly - ga:pageTitle should be available as a dimension in Views.

Still, I've opened a new feature request for node relationships: #1742914: Support views relationship with nodes. I'd like this feature also; please understand it will be challenging because field queries use SQL, and GA queries use a REST / XML API. This approach is fundamentally different from e.g. google_analytics_counter which imports data into SQL.

I'm not sure what's up with google_analytics_counter. For reference, the issue jtbayly mentions is #1407034: The node counter does not replace the value from the statistics module.

jtbayly’s picture

Thanks grendzy.

I guess a feature request is really the way to go. I didn't catch that basic difference in querying. Still, how is ga_stats doing it?

I did try using ga:pageTitle, but the title is often more than simply the node title. On my site, it goes "[node title] - [site name]" and I couldn't figure out how to remove just the sitename from the field in Views. I'm sure there's a way (there always is), but I gave up.

I'm a huge fan of how this module exposes *all* the data from ga to views. I think I'm going to be able to do very neat stuff with it in the backend, but until i can get the node too, ga_stats is working just fine for the "most popular" block.

-Joseph

jtbayly’s picture

Status:Patch (to be ported)» Needs review

Edited to remove comment as I put it on a different issue. See next comment.

jtbayly’s picture

setting status back, because there is a separate issue for my patch: #1649270: Views break when custom fields are used