Webinar SignUp

Today’s Integration: Google Analytics API

We begin our August series of integrations with one that has been of significant value to us – and with more and more of our users building second (and subsequent) stores, you may all find value in this, too.

Alfred writes here about the technique he used to extract data from multiple Google Analytics accounts and consolidate them in a single dashboard.

Retrieve Google Analytics Data using the Data Export API.

As all of us are well aware, AspDotNetStorefront has a built-in feature which allows store admin’s to easily integrate with Google Analytics service. If Google Analytics is enabled on your AspDotNetStorefront website, you can pull out your visitor stats, bounce rates, page views, and more using the Data Export API provided by Google. Although you can retrieve them via Data Feed Query Explorer, there isn’t a way you can consolidate data from multiple website profiles and present them for analysis.

After doing a lot of research, I found working code samples, unfortunately though none of them worked the way I wanted them to (retrieve data from different profiles, consolidate, and export to excel). The best thing I could find was this blog post. I used it heavily to create my results.

Using the API requires 3 stage processes:

1. Initialize and Authenticate: Log in via an HTTP POST request and obtain an authorization key.

2. Account Query: Query the stats via an HTTP GET request (passing the key as a header) and obtain a data feed

3. Profile/Report Query: Parse the data feed for display

Initialize and Authenticate:

Pass in your email address and password as the parameters. This part will carry out all the necessary steps to be able to get the data from Google.

This is use to login via an HTTP POST request and obtain an authorization key. If an authorization fails, it will of course throw an exception.

As you can see, the authentication is handled by the Authenticate method. The authentication URL and authentication post for Google are:

The Authenticate URL makes a HTTP POST request which checks if the result has an “Auth=” in it. If so, the user is authenticated and the authentication key is saved into a string variable for further requests.

Account Query:

The GetUserProfiles calls the GetProfilesData method of the BaseClass. It basically sends an HTTP Get Request to “https://www.google.com/analytics/feeds/accounts/default”.


Profile/Report Query:

To get the final results, first define what dimensions/metrics you’re interested in and then call the GetAnalytics method.

The GetAnalytics method is responsible for requesting and pulling out the Analytics data. The query string that’s passed on to Google API is much like below:


An important thing to note here is that Google Analytics API does not allow retrieval on multiple profiles on a single request (i.e. https://www.google.com/analytics/feeds/data?ids=ga:xxxx&ids=ga:xxxxx), so you need to loop through the GetAnalytics class. Also, not all dimension/metric combinations are allowed. If you provide an incorrect dimension/metric combination, you’ll get Http 400 (Bad Request) exception. To view the valid combinations, check out this link.

Given your requests are all correct (metrics/dimensions/etc), you’ll see something like below. You’ll also have an option to export it to excel.

Digg This
Reddit This
Stumble Now!
Buzz This
Vote on DZone
Share on Facebook
Bookmark this on Delicious
Kick It on DotNetKicks.com
Shout it
Share on LinkedIn
Bookmark this on Technorati
Post on Twitter
Google Buzz (aka. Google Reader)
Posted in Analytics, Integrations | 5 Comments

5 Responses to Today’s Integration: Google Analytics API

  1. In order to correctly extract data from your account, you will have to work hard, since this is not very easy.

  2. This is really a great stuff for sharing. Keep it up .Thanks for sharing.

  3. I appreciate your efforts in preparing this post. I really like your blog articles.

  4. your blog’ s configuration is straightforward and clean and welcome the positive information. I by and large like these stuff My companion prescribed this blog and he was thoroughly right to keep up the incredible work!

  5. richardmajece says:

    I’ve learned a lot about analytics in instagram. https://cellspyapps.org/how-to-hack-instagram-account/ willhe;p you to hack instagram account, by the way. It can be really useful.

Leave a Reply

Your email address will not be published. Required fields are marked *

2 + = 4

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>