I have been looking for a good solution all day, but Google evolves so fast that I can’t find something working. What I want to do is that, I have a Web app that has an admin section where user need to be logged in to see the information. In this section I want to show some data from GA, like pageviews for some specific urls. Since it’s not the user information that I’m showing but the google analytics’user I want to connect passing information (username/password or APIKey) but I can’t find out how. All the sample I found use OAuth2 (witch, if I understand, will ask the visitor to log in using google).
What I found so far :
- Google official Client Library for .Net : http://code.google.com/p/google-api-dotnet-client/, no sample for GA
- official developers help : https://developers.google.com/analytics/
- an other question with code on SO : Google Analytics API – Programmatically fetch page views in server side but I get a 403 when I try to authenticate
- some source that access the API : http://www.reimers.dk/jacob-reimers-blog/added-google-analytics-reader-for-net downloaded the source but I can’t figure out how it works
- this other question on SO : Google Analytics Access with C# but it does not help
- while writing this they suggest me this 09 old post Google Analytics API and .Net.
Maybe I’m just tired and that tomorrow it will be easy to find a solution but right now I need help!
Thanks
I did a lot of search and finally either looking up code from multiple places and then wrapping my own interface around it i came up with the following solution. Not sure if people paste their whole code here, but i guess why not save everyone else time 🙂
Pre-requisites, you will need to install Google.GData.Client and google.gdata.analytics package/dll.
This is the main class that does the work.
And this is the interface and implementation that i use to wrap it up with.
And now the rest is the obvious stuff – you will have to add the web.config values to your application config or webconfig and call IPageViewCounter.GetPageViewCount