Use Google Analytics for data to display on our we

2019-02-17 05:13发布

问题:

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?

回答1:

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.