Click here to Skip to main content
Click here to Skip to main content

Exporting Google Analytics Report in Excel Using DataExport API

, 2 Oct 2011
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  http://code.google.com/apis/analytics/docs/gdata/gdataReferenceDataFeed.html#filters
 
            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.

License

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

Comments and Discussions

 
QuestionCheck out Megalytic PinmemberMember 890302129-Apr-12 8:14 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    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 | Mobile
Web01 | 2.8.140709.1 | Last Updated 2 Oct 2011
Article Copyright 2011 by kranthi kumar Masana
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid