Use Google Analytics for data to display on our webpage?
S

1

6

On some of our pages, we display some statistics like number of times that page has been viewed today, number of times it's been viewed the past week, etc. Additionally, we have an overall statistics page where we list the pages, in order, that have been viewed the most.

Today, we just insert these pageviews and event counts into our database as they happen. We also send them to Google Analytics via normal page tracking and their API. Ideally, instead of querying our database for these stats to display on our webpages, we just query Google Analytics' API. Google Analytics does a FAR better job figuring out who the real uniques are and avoids counting people who artificially inflate their pageview counts (we allow people to create pages on our site).

So the question is if it's possible to use Google Analytics' API for updating the statistics on our webpages? If I cache the results is it more feasible? Or just occasionally update our stats? I absolutely love Google Analytics for our site metrics, but maybe there's a better solution for this particular need?

Synovitis answered 28/7, 2011 at 10:3 Comment(1)
Where you able to create anoverall statistics page? I'm kinda stuck at with the same proble. Tried alot of things but noting that actually works. Thank youValentino
Q
6

So the question is if it's possible to use Google Analytics' API for updating the statistics on our webpages?

Yes, it is. But, the authentication process and xml return may slow things up. You can speed it up by limiting the rows/columns returned. Also, authentication for the way you want to display the data (if I understood you correctly) would require you to use the client authentication method. You send the username and password. Security is an issue.

I have done exactly what you described but had to put a loading graphic on the page for the stats.

If I cache the results is it more feasible? Or just occasionally update our stats?

Either one but caching seems like it would work especially since GA data is not real-time data anyway. You could make the api call and store (or process then store) the returned xml for display later.

I haven't done this but I think I might give it a go. Could even run as a scheduled job.

I absolutely love Google Analytics for our site metrics, but maybe there's a better solution for this particular need?

There are some third-party solutions (googling should root them out) but money and feasibility should be considered.

Quarrel answered 28/7, 2011 at 13:49 Comment(3)
when you say security is an issue because I have to send the username and password, you mean I have to send my google analytics username and password? I wouldn't be sending my user's GA account credentials, this is only for my website, users are able to create pages like wikipedia, but they don't control the analytics. You make an excellent point about GA data not being real-time anyway, so caching makes sense... Now you've got me thinking more about a different solution...Synovitis
Right, it doesn't matter whose credentials, they still have to be sent so steps should be taken to protect them. I have in the past created a google account and given it user rights, not admin rights to the account.Quarrel
I think jen sums it up pretty well. I would like to add a few things. The google analytics API has different authentication mechanisms which are "token" based. This allows you to authenticate once but use the access token for follow up requests. There are request quotas. Not sure how many requests you are making per hour, but another reason to explore a caching mechanism. Lastly (and the self-promotional part), I have developed a 3rd party service which might accomplish what you are trying to do without doing any programming. Check out embeddedanalytics.comOveranxious

© 2022 - 2024 — McMap. All rights reserved.