1

I am trying to find a stable and up to date example of a Google Analytics Reporting handler in .NET. Any information on the matter will be greatly appreciated. I have searched, and found nothing that really is for current use in .NET. I have also noticed, that the friendly friend Google did not create a library for it, but did under Java. At least from what I was able to see. Does anyone have a reference I could view, or a link with some good examples of setting up a reporting tool with this API?

Thanks in advance. :)

1 Answer 1

1

Here is my basic working example I finally got. Hopefully this helps, enjoy!

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Google.GData.Analytics;
using Google.GData.Client;
using Google.GData.Extensions;


namespace Gongos.AnalyticsAPI
{
    public partial class _Default : Page
    {

        public string VisitsNumber()
        {       

            string visits = string.Empty;
            string username = "******** --> Your email";
            string pass = "********** --> Your password";
            string gkey = "?key= **** --> Your APY key <--  ****";

            string dataFeedUrl = "https://www.google.com/analytics/feeds/data" + gkey;
            string accountFeedUrl = "https://www.googleapis.com/analytics/v2.4/management/accounts" + gkey;

            AnalyticsService service = new AnalyticsService("WebApp");
            service.setUserCredentials(username, pass);

            DataQuery query1 = new DataQuery(dataFeedUrl);

            query1.Ids = "ga:********";
            query1.Metrics = "ga:visits";
            query1.Sort = "ga:visits";


            query1.GAStartDate = new DateTime(2013, 1, 2).ToString("yyyy-MM-dd");
            query1.GAEndDate = DateTime.Now.ToString("yyyy-MM-dd");
            query1.StartIndex = 1;

            DataFeed dataFeedVisits = service.Query(query1);

            foreach (DataEntry entry in dataFeedVisits.Entries)
            {
                string st = entry.Title.Text;
                string ss = entry.Metrics[0].Value;
                visits = ss;
            }

            return visits;
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                Response.Write("Visits:" + this.VisitsNumber());
            }
        }

    }
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.