Click here to Skip to main content
11,929,283 members (55,101 online)
Click here to Skip to main content
Add your own
alternative version

Tagged as


1 bookmarked

Exporting Google Analytics Report in Excel Using DataExport API

, 2 Oct 2011 CPOL
Rate this:
Please Sign up or sign in to vote.
Exporting Google Analytics Report in Excel Using DataExport API

Exporting Google Analytics Report in Excel Using DataExport API

Google analytics is a service where all our website statistics are stored at Google server. If we want to get the reports like TopPages viewed in my website, Top cities my website viewed, Top zip codes, Average time spent on my website, etc... this solution will be very helpful. The main aim of the solution is how to get data from Google Analytics Server.

Using the Code

This code is helpful to get the report from google analytics between specific dataes and we can export the results to Excel or CSV.

The report consists of Pagename, Pageviews, Unique Pageviews, Avg. Time on Page, Bounce Rate, Exit Rate

 query1.Dimensions = "ga:pagePath";
 query1.Metrics = "ga:pageviews,ga:uniquePageviews,ga:timeonPage,ga:visits,ga:bounces,ga:exits";
 query1.Sort = "-ga:timeonPage,ga:pagePath";  //  '-' indicates in descending order

// Filters are Optional based on your  requirement

 query1.Filters = "ga:pagePath!@gia;ga:pagePath!@aspx;ga:pagePath!@htm;ga:pagePath!@ismobile;ga:pagePath!@?;ga:pagePath!@mydesk;ga:timeonPage>=10;ga:country==United States";
 query1.NumberToRetrieve = 10000;
 query1.GAStartDate = startdate.ToString("yyyy-MM-dd");
 query1.GAEndDate = enddate.ToString("yyyy-MM-dd");

How does the code actually work?

The code is nothing but a simple DataExport API, which requests the data from Google analytics service. First when we send out user credentials to the service, it will fetch the account profile data from the service. Once we got the profile id, then we can send requests to the service for top pages, top visits, etc. The Google service will return the value as a collection of DataEntry objects. Once we get the return collection, we can manipulate the data as per our reporting manner.

Points of Interest

I have learned a new thing about the Google metrics and dimensions to fetch specified data related to me. At the start, it will be bit difficult for everybody to understand what are metrics and dimensions. This solution contains only frequent methods used in routine. But this will give a heads-up how to fetch the data from the service. For more information about the Google metrics and dimensions, please visit the link.


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

No Biography provided

You may also be interested in...

Comments and Discussions

QuestionCheck out Megalytic Pin
Member 890302129-Apr-12 9:14
memberMember 890302129-Apr-12 9:14 
Have a look at Download months worth of Google Analytics data to Excel. Handles multiple accounts automatically. Also works with Facebook, Twitter, etc.

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Terms of Use | Mobile
Web03 | 2.8.151126.1 | Last Updated 2 Oct 2011
Article Copyright 2011 by kranthi kumar Masana
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid