This project is read-only.

Google Analytics LINQ provider is a tool that allows to build queries and retrieve the Google Analytics data by simple and convenient strongly typed way using the lambdas.

Actually there are no supported LINQ expressions. Because LINQ expressions works only with IEnumerable interface which contains large number of methods that are not supported by Google Analytics API. So to avoid redundancy I refused to use IQueryable interface and as a result of it, only methods that allowed by Google Analytics API are available in this library.

So following clauses are allowed for the Google Analytics query building:

Where Optional. Allows to filter data by Google Analytics data fields (metrics and dimension)
Segment Optional. Allows to filter data by Google Analytics Segments
Select Required. Sets the Google Analytics fields that will be mapped to a result object. At least 1 metric and optional quantity of dimensions must be in this clause. The valid combinations of metrics and dimensions you can check  here. More about metrics and dimensions here.
Order By Optional. Allows to order result set of data by fields of the result object.

After the query is built it's available to retrieve the data asynchronously or synchronously.

Here is an example how to build a query and retrieve the result data set:

   DataContext context = new DataContext(getAnalyticsProfileId(), getAnalyticsService());
   context.Create(DateTime.Now.AddDays(-7), DateTime.Now)
     .Where(x => x.Visitors > 5)
     .Select(x => new { Country = x.Country, Visitors = x.Visitors })
     .OrderBy(x => x.Visitors)
     .ToListAsync(dataSet =>
     {
         foreach (var item in dataSet)
         {
             //do something
         }
     });

Last edited Jan 24, 2014 at 2:06 PM by amuntvcf, version 18