Reimers.dk

.NET, AJAX and Google APIs brought together
Welcome to Reimers.dk Sign in | Join | Help
in Search

Jacob Reimers Weblog

Added Google Analytics Reader for .NET

I found out yesterday that Google recently launched an Analytics API. That is a very welcome to their APIs. But I was surprised to find that .NET developers were left to create their own HTTP requests and parse the results. I'm not going to go into any conspiracy theories here, but they managed to support Java, so why not .NET?

Well if Google won't support .NET, then I will :-) I added Analytics support to the Reimers.Google project in the public SVN trunk (svn://svn.reimers.dk/Reimers.Google). There will also be some code later in this post if you don't know how to use SVN.

The workhorse is the ReportRequestor class which handles the login and report requests and parsing. To read an Analytics report you have to create an instance of the ReportRequestor and set the username and password.

Before you can generate a report you will need to find the Analytics account you want to request the report for. Get all your available Analytics account by calling the GetAccounts method and selecting the one you want to use, like so:

C#

IEnumerable<AnalyticsAccountInfo> accounts = requestor.GetAccounts();

AnalyticsAccountInfo account = accounts.First(a => a.Title == "Reimers.dk");

Once you have your account information you can use it to request a report. The ReportRequestor exposes the RequestReport method which returns an IEnumerable<GenericEntry>. The GenericEntry is basically just a container for the Dimensions and Metrics you requested.

In the project code there is also a GetUserCountByLocation method which shows how you can take the GenericEntry list and generate a strongly typed entry based on your own business logic.

All the response parsing is done using LINQ, so you will need .NET 3.5. But then you should be ready to generate your reports.

The complete source code is below. You can use it for your own personal or commercial projects, but please remember to include credits. If you find any bugs or want assistance in generating you Analytics reports send me a message.

C#

ReportRequestor

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

using System.Net;

using System.IO;

using System.Xml.Linq;

using Reimers.Google.Analytics.Reports;

using System.Globalization;

 

namespace Reimers.Google.Analytics

{

    public class ReportRequestor

    {

        #region Fields

 

        private static readonly string requestUrlFormat = "https://www.google.com/analytics/feeds/data?ids={0}&dimensions={1}&metrics={2}&start-date={3}&end-date={4}";

        private static readonly string authUrlFormat = "accountType=GOOGLE&Email={0}&Passwd={1}&source=reimers.dk-analyticsreader-0.1&service=analytics";

        private static CultureInfo ci = CultureInfo.GetCultureInfo("en-US");

        private string _token = null;

        private string _username = null;

        private string _password = null;

 

        #endregion

 

        #region Constructor

 

        public ReportRequestor() { }

 

        public ReportRequestor(string email, string password)

        {

            _username = email;

            _password = password;

        }

 

        #endregion

 

        #region Properties

 

        public string Email

        {

            get { return _username; }

            set

            {

                if (!string.Equals(_username, value))

                {

                    _username = value;

                    _token = null;

                }

            }

        }

 

        public string Password

        {

            get { return _password; }

            set

            {

                if (!string.Equals(_password, value))

                {

                    _password = value;

                    _token = null;

                }

            }

        }

 

        #endregion

 

        #region Methods

 

        private string GetToken(string username, string password)

        {

            if (string.IsNullOrEmpty(_username) || string.IsNullOrEmpty(_password))

            {

                throw new ArgumentNullException("Username, Password", "Username and/or password not set");

            }

 

            string authBody = string.Format(authUrlFormat, username, password);

            HttpWebRequest req = (HttpWebRequest)HttpWebRequest.Create("https://www.google.com/accounts/ClientLogin");

            req.Method = "POST";

            req.ContentType = "application/x-www-form-urlencoded";

            req.UserAgent = "Reimers.dk req";

            Stream stream = req.GetRequestStream();

            StreamWriter sw = new StreamWriter(stream);

            sw.Write(authBody);

            sw.Close();

            sw.Dispose();

            HttpWebResponse response = (HttpWebResponse)req.GetResponse();

            StreamReader sr = new StreamReader(response.GetResponseStream());

            string token = sr.ReadToEnd();

            string[] tokens = token.Split(new string[] { "\n" }, StringSplitOptions.RemoveEmptyEntries);

            foreach (string item in tokens)

            {

                if (item.StartsWith("Auth="))

                {

                    return item.Replace("Auth=", "");

                }

            }

            return string.Empty;

        }

 

        public IEnumerable<AnalyticsAccountInfo> GetAccounts()

        {

            if (string.IsNullOrEmpty(_token))

            {

                _token = GetToken(_username, _password);

            }

            HttpWebRequest req = (HttpWebRequest)HttpWebRequest.Create("https://www.google.com/analytics/feeds/accounts/default");

            req.Headers.Add("Authorization: GoogleLogin auth=" + _token);

            HttpWebResponse response = (HttpWebResponse)req.GetResponse();

            Stream responseStream = response.GetResponseStream();

            StreamReader sr = new StreamReader(responseStream);

            string responseXml = sr.ReadToEnd();

            XDocument doc = XDocument.Parse(responseXml);

            XNamespace dxpSpace = doc.Root.GetNamespaceOfPrefix("dxp");

            XNamespace defaultSpace = doc.Root.GetDefaultNamespace();

 

            var entries = from en in doc.Root.Descendants(defaultSpace + "entry")

                          select new AnalyticsAccountInfo

                          {

                              AccountID = en.Elements(dxpSpace + "property").Where(xe => xe.Attribute("name").Value == "ga:accountId").First().Attribute("value").Value,

                              AccountName = en.Elements(dxpSpace + "property").Where(xe => xe.Attribute("name").Value == "ga:accountName").First().Attribute("value").Value,

                              ID = en.Element(defaultSpace + "id").Value,

                              Title = en.Element(defaultSpace + "title").Value,

                              ProfileID = en.Elements(dxpSpace + "property").Where(xe => xe.Attribute("name").Value == "ga:profileId").First().Attribute("value").Value,

                              WebPropertyID = en.Elements(dxpSpace + "property").Where(xe => xe.Attribute("name").Value == "ga:webPropertyId").First().Attribute("value").Value

                          };

            return entries;

        }

 

        private XDocument getReport(AnalyticsAccountInfo account, IEnumerable<Dimension> dimensions, IEnumerable<Metric> metrics, DateTime from, DateTime to)

        {

            if (string.IsNullOrEmpty(_token))

            {

                _token = GetToken(_username, _password);

            }

            StringBuilder dims = new StringBuilder();

            foreach (Dimension item in dimensions)

            {

                dims.Append("ga:" + item.ToString() + ",");

            }

            StringBuilder mets = new StringBuilder();

            foreach (Metric item in metrics)

            {

                mets.Append("ga:" + item.ToString() + ",");

            }

            string requestUrl = string.Format(requestUrlFormat, "ga:" + account.ProfileID, dims.ToString().Trim(",".ToCharArray()), mets.ToString().Trim(",".ToCharArray()), from.ToString("yyyy-MM-dd"), to.ToString("yyyy-MM-dd"));

            HttpWebRequest req = (HttpWebRequest)HttpWebRequest.Create(requestUrl);

            req.Headers.Add("Authorization: GoogleLogin auth=" + _token);

            HttpWebResponse response = (HttpWebResponse)req.GetResponse();

            Stream responseStream = response.GetResponseStream();

            string responseXml = new StreamReader(responseStream, Encoding.UTF8, true).ReadToEnd();

            XDocument doc = XDocument.Parse(responseXml);

            return doc;

        }

 

        public IEnumerable<GenericEntry> RequestReport(AnalyticsAccountInfo account, IEnumerable<Dimension> dimensions, IEnumerable<Metric> metrics, DateTime from, DateTime to)

        {

            XDocument doc = getReport(account, dimensions, metrics, from, to);

            XNamespace dxpSpace = doc.Root.GetNamespaceOfPrefix("dxp");

            XNamespace defaultSpace = doc.Root.GetDefaultNamespace();

            var gr = from r in doc.Root.Descendants(defaultSpace + "entry")

                    select new GenericEntry

                    {

                        Dimensions = new List<KeyValuePair<Dimension, string>>(

                            from rd in r.Elements(dxpSpace + "dimension")

                            select new KeyValuePair<Dimension, string>(

                                (Dimension)Enum.Parse(typeof(Dimension), rd.Attribute("name").Value.Replace("ga:", ""), true),

                                rd.Attribute("value").Value)),

                        Metrics = new List<KeyValuePair<Metric, string>>(

                            from rm in r.Elements(dxpSpace + "metric")

                            select new KeyValuePair<Metric, string>(

                                (Metric)Enum.Parse(typeof(Metric), rm.Attribute("name").Value.Replace("ga:", ""), true),

                                rm.Attribute("value").Value))

                    };

 

            return gr;

        }

 

        public IEnumerable<CityReport> GetUserCountByLocation(AnalyticsAccountInfo account, DateTime from, DateTime to)

        {

            IEnumerable<GenericEntry> report = RequestReport(account, new Dimension[] { Dimension.city, Dimension.latitude, Dimension.longitude }, new Metric[] { Metric.visits }, from, to);

            var cr = from r in report

                    select new CityReport

                    {

                        City = r.Dimensions.First(d => d.Key == Dimension.city).Value,

                        Latitude = Convert.ToDouble(r.Dimensions.First(d => d.Key == Dimension.latitude).Value, ci),

                        Longitude = Convert.ToDouble(r.Dimensions.First(d => d.Key == Dimension.longitude).Value, ci),

                        Count = Convert.ToInt32(r.Metrics.First(m => m.Key == Metric.visits).Value)

                    };

            return cr;

        }

 

        #endregion

    }

}

AnalyticsAccountInfo

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

 

namespace Reimers.Google.Analytics

{

    public class AnalyticsAccountInfo

    {

        #region Fields

 

        private string _id = null;

        private string _title = null;

        private string _accountId = null;

        private string _accountName = null;

        private string _profileId = null;

        private string _webProperty = null;

 

        #endregion

 

        #region Properties

 

        public string ID

        {

            get { return _id; }

            set { _id = value; }

        }

 

        public string Title

        {

            get { return _title; }

            set { _title = value; }

        }

 

        public string AccountID

        {

            get { return _accountId; }

            set { _accountId = value; }

        }

 

        public string AccountName

        {

            get { return _accountName; }

            set { _accountName = value; }

        }

 

        public string ProfileID

        {

            get { return _profileId; }

            set { _profileId = value; }

        }

 

        public string WebPropertyID

        {

            get { return _webProperty; }

            set { _webProperty = value; }

        }

 

        #endregion

    }

}

GenericEntry

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

 

namespace Reimers.Google.Analytics

{

    public class GenericEntry

    {

        #region Fields

 

        List<KeyValuePair<Dimension, string>> _dimensions = null;

        List<KeyValuePair<Metric, string>> _metrics = null;

 

        #endregion

 

        #region Properties

 

        public List<KeyValuePair<Dimension, string>> Dimensions

        {

            get { return _dimensions; }

            set { _dimensions = value; }

        }

 

        public List<KeyValuePair<Metric, string>> Metrics

        {

            get { return _metrics; }

            set { _metrics = value; }

        }

 

        #endregion

    }

}

CityReport

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

 

namespace Reimers.Google.Analytics.Reports

{

    public class CityReport

    {

        #region Fields

 

        private string _city = string.Empty;

        private double _lat = 0;

        private double _lng = 0;

        private int _count = 0;

 

        #endregion

 

        #region Properties

 

        public string City

        {

            get { return _city; }

            set { _city = value; }

        }

 

        public double Latitude

        {

            get { return _lat; }

            set { _lat = value; }

        }

 

        public double Longitude

        {

            get { return _lng; }

            set { _lng = value; }

        }

 

        public int Count

        {

            get { return _count; }

            set { _count = value; }

        }

 

        #endregion

    }

}

Dimension

namespace Reimers.Google.Analytics

{

    public enum Dimension

    {

        browser = 0,

        browserVersion = 1,

        city = 2,

        connectionSpeed = 3,

        continent = 4,

        countOfVisits = 5,

        country = 6,

        date = 7,

        day = 8,

        daysSinceLastVisit = 9,

        flashVersion = 10,

        hostname = 11,

        hour = 12,

        javaEnabled = 13,

        language = 14,

        latitude = 15,

        longitude = 16,

        month = 17,

        networkDomain = 18,

        networkLocation = 19,

        pageDepth = 20,

        operatingSystem = 21,

        operatingSystemVersion = 22,

        region = 23,

        screenColors = 24,

        screenResolution = 25,

        subContinent = 25,

        userDefinedValue = 26,

        visitorType = 26,

        week = 27,

        year = 28,

        adContent = 29,

        adGroup = 30,

        adSlot = 31,

        adSlotPosition = 32,

        campaign = 33,

        keyword = 34,

        medium = 35,

        referralPath = 36,

        source = 37,

        exitPagePath = 38,

        landingPagePath = 39,

        pagePath = 40,

        pageTitle = 41,

        affiliation = 42,

        daysToTransaction = 43,

        productCategory = 44,

        productName = 45,

        productSku = 46,

        transactionId = 47,

        searchCategory = 48,

        searchDestinationPage = 49,

        searchKeyword = 50,

        searchKeywordRefinement = 51,

        searchStartPage = 52,

        searchUsed = 53

    }

}

Metric

namespace Reimers.Google.Analytics

{

    public enum Metric

    {

        bounces = 0,

        entrances = 1,

        exits = 2,

        newVisits = 3,

        pageviews = 4,

        timeOnPage = 5,

        timeOnSite = 6,

        visitors = 7,

        visits = 8,

        adCost = 9,

        adClicks = 10,

        CPC = 11,

        CPM = 12,

        CTR = 13,

        impressions = 14,

        uniquePageviews = 15,

        itemQuantity = 16,

        itemRevenue = 17,

        transactionRevenue = 18,

        transactions = 19,

        transactionShipping = 20,

        transactionTax = 21,

        uniquePurchases = 22,

        searchDepth = 23,

        searchDuration = 24,

        searchExits = 25,

        searchRefinements = 26,

        searchUniques = 27,

        searchVisits = 28,

        goal1Completions = 29,

        goal2Completions = 30,

        goal3Completions = 31,

        goal4Completions = 32,

        goalCompletionsAll = 33,

        goal1Starts = 34,

        goal2Starts = 35,

        goal3Starts = 36,

        goal4Starts = 37,

        goalStartsAll = 38,

        goal1Value = 39,

        goal2Value = 40,

        goal3Value = 41,

        goal4Value = 42,

        goalValueAll = 43

    }

}

Published 9. maj 2009 13:59 by jjrdk

Comments

 

Alex Maitland said:

Though you might be interested in this post on google groups.

<a href="http://groups.google.com/group/gdata-dotnet-client-library/browse_thread/thread/ed58226b16eaff5b">Analytics support for .NET first Beta now in subversion</a>

maj 21, 2009 14:06
 

Dman100 said:

Hi Jacob,

Do you have an example of creating a report?  I've successfully authenticated, but am having problems understanding how to generate a report.

ReportRequestor requestor = new ReportRequestor("xxxxxx@gmail.com", "xxxxx");

IEnumerable<AnalyticsAccountInfo> accounts = requestor.GetAccounts();

AnalyticsAccountInfo account = accounts.First(a => a.ProfileID == "xxxxxxx");

Is there an example that I can download to see how to call the RequestReport method and assign to the IENumerable <GenericEntry> and display the report data?

Regards.

juli 5, 2009 22:22
 

jjrdk said:

As mentioned in the post above, the GetUserCountByLocation is an example of how you pass in specific criteria and get a report back that you can then map to your own business logic.

You can use the same logic for any report criteria you want.

juli 5, 2009 22:32
 

shiraazz said:

I am getting an error (Bad Request) when calling Request report,

what do you suggest?

juli 9, 2009 13:37
 

jjrdk said:

I would suggest that you give me some information to go on. I don't know what request you are sending, so I can't say what is bad about it.

juli 9, 2009 13:44
 

shiraazz said:

My code is below, i have changed your RequestReport function to accept Lists instead of IEnumerable

Getting account info works fine, it throws an exception in RequestReport at this line:

HttpWebResponse response = (HttpWebResponse)req.GetResponse();

///////////////////////////////

ReportRequestor req = new ReportRequestor("email","password");

           List< AnalyticsAccountInfo > accInfList = req.GetAccounts().ToList();

           List< List< GenericEntry > > genLists = new List<List<GenericEntry>>();

           List<Metric> metList = new List<Metric>();

           List<Dimension> dimList = new List<Dimension>();

           metList.Add(Metric.pageviews);

           dimList.Add(Dimension.country);

           dimList.Add(Dimension.city);

           foreach (AnalyticsAccountInfo accInf in accInfList)

           {

              genLists.Add( req.RequestReport(accInf, dimList,metList , DateTime.Now.AddYears(-5), DateTime.Now));

           }

juli 9, 2009 14:46
 

jjrdk said:

The change from IEnumerable<T> to List<T> is unnecessary since List<T> is an IEnumerable<T>.

From your code sample, the only thing I can see that could be wrong is that you request report from 5 years back. Is your account really that old?

juli 9, 2009 14:56
 

shiraazz said:

Thanks, that was the problem

juli 9, 2009 15:23
 

Process XML in ASP.NET | Unidev .NET Technology Blog said:

juli 14, 2009 16:56
 

thomasabcd said:

Hi,

I am a total novice regarding LINQ, so I have a hard time creating a custom report. Could you please show an example of how to get the number of pageviews for a specific page within a given timeframe?

thanks

Thomas

september 6, 2009 01:28
 

jjrdk said:

As I write in the blog post, the GetUserCountByLocation method is an example of how to create a specific report from a generic. Just replace the passed dimensions with what you want to measure and change the returned class.

september 6, 2009 10:28
 

Fabian said:

Hi,

I have a problem converting the code to VB.

Being a novice to LINQ, I am trying to get your code to work in VB.Net.

The code where you get the collection of the attributes of each element in the source collection, like

var cr = from r in report

        select new CityReport

                  { ... };

return cr;

should be converted to VB, as far as I understand, to:

Dim cr = From r In report _

   Select New CityReport()

...

Return cr

This however gives me errorcodes on the syntax.

Is there an alternative way?

Thanks!

september 28, 2009 14:43
 

jjrdk said:

I guess you could change the constructor of the CityReport to take the property values and set them this way.

september 30, 2009 15:40
 

jjrdk said:

I had a look at MSDN and I belive the VB.NET syntax would be:

select New CityReport With

                   {

                       .City = r.Dimensions.First(d => d.Key == Dimension.city).Value,

                       .Latitude = Convert.ToDouble(r.Dimensions.First(d => d.Key == Dimension.latitude).Value, ci),

                       .Longitude = Convert.ToDouble(r.Dimensions.First(d => d.Key == Dimension.longitude).Value, ci),

                       .Count = Convert.ToInt32(r.Metrics.First(m => m.Key == Metric.visits).Value)

                   }

september 30, 2009 15:48
 

Fabian said:

The matter is that I did not have Framework 3.5 installed, which supports LINQ.

Thanks anyway!

oktober 5, 2009 15:22
 

snafu7x7 said:

hey Jacob, I grabbed your code from the SVN link you provided but it appears to be incomplete as neither the Reimers.Google or the Reimers.Google2010 projects will compile, it appears to be missing the assembly Reimers.dll but I was unable to find this in the repo anywhere. Is that something you can email me or check into SVN.

Thanks for posting this entry, this looks to be a good implementation for GA

oktober 26, 2009 21:20
 

jjrdk said:

The reimers.dll is in the Reimers folder in the SVN, so you will need to get that as well. The Reimers.Google project should reference it correctly if you keep the folder structure.

Let me know if you are still having trouble.

oktober 26, 2009 21:44
 

mc72 said:

Wow, this could be very useful in a project I am working on.  But I am an ASP.NET newbie (relatively).   Is there any documentation on how I would implement this in a web project.  For example, how would I bind the report to a listview or other ASP.net control?

Thanks.

Mike

oktober 29, 2009 00:54
 

tallfiji said:

I copied the code above and created a new C# project.  However it won't compile because it doensn't like the var object being used.  Can someone tell me what I'm doing wrong?  I'm using .net 3.5 sp1 and I can't figure out what is the issue.

november 4, 2009 19:55
 

Displaying Google Analytics Data in ASP.NET | SolidDotNet.com said:

november 7, 2009 04:41
 

codebounce.com said:

Your story was featured in codebounce.com! Here is the link to vote it up and promote it: http://www.codebounce.com/ASPNET/Google-Analytics-Reader-for-NET

november 13, 2009 17:21
 

chandu said:

Hi Reimers,

            U have done a great job with this article.I have used your code in

my project.Everything is working fine,only exception though the data is not accurate

enough with that of google analytics website.Please help me with this as this is the only  problem standing in my way.

november 19, 2009 08:51
 

Femah said:

Fantastic - thanks man.

december 5, 2009 01:01
 

Omen said:

Jacob, please help, how do you solved the "The request was aborted: Could not create SSL/TLS secure channel." problem?

december 25, 2009 15:22
 

SharePoint Blog - René Hézser said:

Jacob Reimers has written an C# API for accessing Google Ana ...

januar 6, 2010 19:47
 

dkpodder said:

Trying to translate to vb.net...

I'm new to LINQ, and have some errors.

This section is causing the trouble:

var entries = from en in doc.Root.Descendants(defaultSpace + "entry")

                         select new AnalyticsAccountInfo

                         {

                             AccountID = en.Elements(dxpSpace + "property").Where(xe => xe.Attribute("name").Value == "ga:accountId").First().Attribute("value").Value,

                             AccountName = en.Elements(dxpSpace + "property").Where(xe => xe.Attribute("name").Value == "ga:accountName").First().Attribute("value").Value,

                             ID = en.Element(defaultSpace + "id").Value,

                             Title = en.Element(defaultSpace + "title").Value,

                             ProfileID = en.Elements(dxpSpace + "property").Where(xe => xe.Attribute("name").Value == "ga:profileId").First().Attribute("value").Value,

                             WebPropertyID = en.Elements(dxpSpace + "property").Where(xe => xe.Attribute("name").Value == "ga:webPropertyId").First().Attribute("value").Value

                         };

Where do I get a reference to the objects 'x' and 'xe' ?

januar 13, 2010 12:47
 

jjrdk said:

x and xe are the parameter names for the arguments being passed into the lambda expression.

januar 13, 2010 20:14
 

niallinbelfast said:

Has anyone successfully implemented a "RequestReport" from the Requestor? Could you post the code? I can call the function successfully but I can't seem to find the syntax for displaying the pageviews in a label control..

januar 21, 2010 10:23
 

niallinbelfast said:

Ah! I have it..

IEnumerable myData = req.RequestReport(acc, (new Dimension[2] { ((Dimension)41), ((Dimension)40) }) as IEnumerable<Dimension>, (new Metric[1] { ((Metric)4) }) as IEnumerable<Metric>, DateTime.Now.AddDays(-2), DateTime.Now);

        foreach (GenericEntry myReport in myData)

        {

            myString += "Page: " + myReport.Dimensions.First() + " - " + myReport.Dimensions.Last() + " - " + myReport.Metrics.First() + "<br/>";

        }

januar 21, 2010 11:02
 

LeifK said:

Great post Jacob!

Could you please help, I am having trouble getting back metrics for 2 custom variables I have created.

I can get back the standard metrics and data for my site using your code, but not the custom variable dimensions.

The javascript snippet I put in my pages is like this:

   var pageTracker = _gat._getTracker("UA-12957544-1");

   pageTracker._setCustomVar(1, 'Company', '5', 3);

   pageTracker._setCustomVar(2, 'SubscriberId', '2', 2);

   pageTracker._trackPageview();

I have then added these 2 dimensions to your Dimension enum and modified the foreach loop in getReport in ReportRequestor.cs to be like this:

           foreach (Dimension item in dimensions)

           {

               if ((int)item < 54)

               {

                   dims.Append("ga:" + item.ToString() + ",");

               }

               else if ((int)item == 54)

               {

                   dims.Append("ga:customVarValue1" + ",");

               }

               else if ((int)item == 55)

               {

                   dims.Append("ga:customVarValue2" + ",");

               }

           }

In the resulting IEnumerable<GenericEntry> I get "Requested value 'customVarValue1' was not found.  I have also tried passing in ga:customVarName(n) (where n is the name of my custom variable) as specified in http://code.google.com/apis/analytics/docs/gdata/gdataReferenceDimensionsMetrics.html with no luck.

Please help!

februar 12, 2010 07:25
 

jjrdk said:

Hi Leif,

Thanks for bringing up custom variables. I see that I have neglected them previously. I tried adding them to the dimensions enum as you mentioned. I added them as customVarValue1 - customVarValue5 (the 5 custom variables allowed).

It gives me a not defined response. I will have to start tracking some custom variables, but I am reasonably sure this is the correct response.

februar 13, 2010 11:05
 

LeifK said:

Hi Jacob,

Using ga:customVarValue1-5 is the way to do it.  Today I got the code to work (without any changes which is strange).  I only started storing the custom variable values on the day I tried to use the code, so perhaps it takes a day or 2 before the custom variable information is available from google.

Now my next challenge is trying to get back event information, eg putting something like onclick="pageTracker._trackEvent('Pdfs', 'Company6', 'Document2');" for the onclick of a link to a document.  Have you attempted to retrieve this information previously?

If I get it to work I will post how to do it here.

februar 15, 2010 03:25
 

LeifK said:

To get event information you simply pass in ga:eventCategory, ga:eventAction and/or ga:eventLabel depending on what information or combination of information you want to receive about the event(s) you are tracking.

februar 15, 2010 05:19
 

Google Analytics API in C# – Part 1 | The Cyberwizard said:

marts 10, 2010 22:04
 

.intheMeanTime » Blog Archive » Show Popular Stories Using Google Analytics and ASP.net C# and Sort the Results [How To] said:

april 29, 2010 21:24
Anonymous comments are disabled