.netgoogle-analyticsmigration

Migration analytics management clientlogin


I was using Google Analytics API to show users of my CMS their visitor data. All profiles are under my own account, so using clientlogin and some Google .net libraries I was able to retrieve all web id's of the accounts to query data. Now since the API is deprecated all requests for account return a 404.

I have tried everything to update to 2.4 but without any success. What would be the way to go for me? Since I only need to login once with my own account instead of redirecting users to accept my app..

Using service accounts? I also have a server api key, but I have no idea how to implement the new API's. Too bad there is no .net library yet. Any advice is welcome!


Solution

  • The main issue you are running into is they removed the Account Feed that was included in version 2.3 of the API. That means any sort of information about accounts, web properties, profiles, and goals all won't work using the old client libraries. The rest of it, aka the data queries, should still work and you should upgrade them as per the migration documents.

    To fix the issue you are having getting profiles you have to switch over to their management api. The easiest fix would be to gut out your old method of getting profiles and replace it with a simple restful implementation of their management api. The rest of your library (such as getting visitors/visits) should still work fine.

    Heres a little example:

    1) Use ClientLogin to get an auth token.

    2) Grab the profiles xml by sending a GET request to https://www.googleapis.com/analytics/v2.4/management/accounts/~all/webproperties/~all/profiles. Make sure to include the authorization header in the request request.Headers.Add("Authorization", String.Format("GoogleLogin auth={0}", clientLoginAuthToken));

    3) Use XDocument to parse the results!