Google Blogoscoped


No Google Analytics API? No Problem!  (View post)

Niraj Sanghvi [PersonRank 10]

Thursday, January 17, 2008
15 years ago13,598 views

Very nice! It's quick and easy if you've worked with the services involved before, and I really like that it doesn't involve divulging any credentials.

aspiroots [PersonRank 1]

15 years ago #


What are we waiting for suggesting Google to lanch the Google Analytics API ???

Philip, use your contacts from inside the building please ;-)

sanderqd [PersonRank 1]

15 years ago #

I don't like Analytics' terms of service:

"You must post a privacy policy and that policy must provide notice of your use of a cookie that collects anonymous traffic data."

Often I don't care to read those texts, but I don't want Google to close my account (including Gmail) because I didn't write down my privacy policy...

In the previous version, they included a text you had to put in your own policy ("we use Google services that use cookies, etc.") and it was forbidden to publish *any* data fetched by Analytics, so you couldn't use the method described in this post.

Douglas Karr [PersonRank 1]

15 years ago #

Or you could just add a field to your posts table and set an image pixel to a page that advances the count. Then you can keep track regardless of the Analytics application and it's a lot less work.

Stuart Grimshaw [PersonRank 1]

15 years ago #

Now I know the data provided in the mail from Analytics is going to end up public anyway, but the thought of mailing it wholesale to a public forum like Google Groups makes me suck air through my teeth :-)

I'd send the mail to a specific mailbox, most ISP's offer this kind of thing with your account, as well as POP3 access, or, stick with GMail because that also has an IMAP interface.

Next, breakout your language of choice, have that access the mailbox via pop3 and grab the xml out of the attachment.

What you do next depends on how your system is set up, but among the options is parseing the xml so it contains only the info you actually need, and dumping it as a blob of JSON and replace the call to pipes with a URL to that.

I'd be tempted to parse the xml into a discrete chunk of html, load that via an xhtml request and insert that into the DOM.

Chris Riley [PersonRank 3]

15 years ago #

[put at-character here]Douglas and @Stuart – the point is that this solution doesn't need server side script or a database to keep a count, which might not be possible for some people depending on how they host their website/blog. It is all done with simple services and a small portion of JavaScript. You certainly could do some clever stuff with mailboxes server side, but I didn't want to do that!

[put at-character here]sanderqd – interesting point, although I think reading those snippets you've provided there, and having scanned the Analytics TOS myself just now they are more concerned with you publishing the data being collected from the client side, rather than publishing the report that contains no personally identifiable information (especially for a top content report). Though I'm no lawyer!

As mentioned in the conclusion if you don't like the idea of the report data being available in a Google Group, then this solution isn't for you.

Tony Ruscoe [PersonRank 10]

15 years ago #

> Or you could just add a field to your posts table...
Now, remind me where I can find that table in Blogger again... ;-) (I know, I know... I should be using "proper" blog software.)

Seriously though, if you were going to do things server-side, surely you'd just hack the login so that your code could access your Google Analytics account directly rather than bother emailing the reports in the first place... wouldn't you? (I think a few others have tried this before... although that would involve coding your Google Account username and password credentials into your code somewhere.)

While I personally don't like the idea of emailing my Google Analytics reports to Google Groups to make them publicly available (although I'm sure nobody would care about my stats) I think this is a really imaginative solution to the problem – and one which is actually achievable by non-techies who don't have their own server. It's a shame that Google Groups doesn't have a way to access private groups by using a hash or something else in the URL. (Although that might then be viewable in Yahoo Pipes if you made your Pipe public...)

hamid reza [PersonRank 0]

15 years ago #

There exists a plugin for wordpress which fetches data from GA and displays it in admin panel:
It comes with a widget which shows most popular posts in the sidebar. Although it does not make stats public, with some modifications you can create a public page for showing GA report summary in a page or whenever you want.

Chris Riley [PersonRank 3]

15 years ago #

[put at-character here]hamid reza – Nice as that plugin is it uses the screen scraping approach so you would have to give it your Google Account login details to use it, something I'm always wary of doing. You can get an unofficial php API for Analytics as well, but again this uses screen scraping so it would have a tendancy to break should Google tweak their Analytics interface. Hench the approach I've taken avoids screen scraping completely.

Ionut Alex. Chitu [PersonRank 10]

15 years ago #

It's cool to automate things, but I don't like to run a Yahoo Pipe every time someone loads a page, considering that the data changes every month. Maybe caching the data somewhere and loading the list of popular posts from there is a better idea.

Also the pipe should use parameters for the Google Groups URL, the URL of your site etc. so you don't have to clone it to use it for another site.

Chris Riley [PersonRank 3]

15 years ago #

Indeed, some great tips, I was keeping this simple for this example as it is quite involved already, but if I do expand the use of this on my blog I'll be refining the pipe :o)

Haochi [PersonRank 10]

15 years ago #

There IS a Google Analytics API, but for tracking only...

p [PersonRank 1]

15 years ago #

This is a very clever solution! Although instead of coding the javascript to return JSON, I would use pipes to return the info as RSS and then use simplepie ( to embed the feed into the blog.

Suresh S [PersonRank 10]

15 years ago #

An easy way rather to use wordpress plugin.

4563214 [PersonRank 2]

15 years ago #

Nice job!

But in my Google Group the "part" var is "4" instead of "2".

In Yahoo Pipes it is "/?part=4".

andymurd [PersonRank 0]

15 years ago #

Nice idea – I hadn't thought of using google groups as a data repository.

I'm not sure it could be described as "simple" though :-) but it should give the google analytics teams some good ideas for expanding their API.

Tanner Christensen [PersonRank 0]

15 years ago #

Sounds great – and just what I've been looking for lately – but, because it's Friday afternoon, any effort to make this a reality for me will have to be made next week.

Jeff [PersonRank 0]

15 years ago #

Thanks for the guide, very helpful

[Signature URL removed – Tony]

Ianf [PersonRank 10]

15 years ago #

Chris, this is a great hack, but a hack never the less. For this to become usable for the occassional coder out there, you'd need to automate it a bit, perhaps via a "staggered dialogs" web-client.

Assuming JS, it'd display input fields for all initially known values, an "Exec" button, and subsequent fields that would appear after key steps in the process in response to "triggers" in the client-url generated during previous step (ie. a self-modifying url). Hope this is clear enough, 'cause I don't think I could explain it in simpler terms.

« [...] here’s a method that doesn’t involve any server-side code or screen-scraping. All you need to do is use a few existing free services from Google and Yahoo and a bit of JavaScript. [...] »

Chris Riley [PersonRank 3]

15 years ago #

[put at-character here]Ianf – "For this to become usable for the occassional coder out there, you'd need to automate it a bit, perhaps via a "staggered dialogs" web-client."

Where's the fun in that ;o)

Stuart Grimshaw [PersonRank 1]

15 years ago #

[put at-character here]Chris – This is what I like about API's and 'the semantic web', there's a 101 ways to achieve things, ask 10 different devs how to do it, and they'll give you 10 different ways.

Melanie Phung [PersonRank 1]

15 years ago #

Great post. I love that there are people out there who figure these hacks out and then are generous enough to share them with everybody.

Nikolai [PersonRank 1]

15 years ago #

Thanks! I was going to use separate mailbox for such things, but you open my eyes to GGroups)

James Hueston [PersonRank 0]

15 years ago #

very slick, thank you!

Saraj [PersonRank 1]

15 years ago #

Thanks for the great write-up. There are so many things in here I hadn't thought of before... now I just need to decide how to use it. :)

Andy [PersonRank 0]

15 years ago #

This is great, thank you for putting this together – very easy to follow. Anyone with Pipes experience know: is it possible to log in to Analytics using the Fetch Page and Private Data modules directly? Sure, it would make it more susceptible to GA changing formats and breaking the system, but if possible, we could have better control over frequency and period of the returned statistics. The CakePHP GA API hack out there is apparently able to log in to GA.

As it is, the "Daily" email option has stats for the previous 24 hours, and the "Weekly" email option is a 1 week duration of stats, and will only update on Monday mornings.

Forum home


Blog  |  Forum     more >> Archive | Feed | Google's blogs | About


This site unofficially covers Google™ and more with some rights reserved. Join our forum!