Table of Contents

Class GoogleAnalyticsDataProvider

Namespace
combit.Reporting.DataProviders
Assembly
combit.ListLabel31.CrossPlatform.dll

Provides a data provider implementation for Google Analytics data.

public sealed class GoogleAnalyticsDataProvider : IDataProvider, ISupportsLogger
Inheritance
GoogleAnalyticsDataProvider
Implements
Inherited Members

Examples

The following example demonstrates how to use the GoogleAnalyticsDataProvider to export a report to PDF:

// Initialize the provider with OAuth credentials
GoogleAnalyticsDataProvider provider = new GoogleAnalyticsDataProvider(
    "your_refresh_token",
    "your_client_id.apps.googleusercontent.com",
    "your_client_secret");

// Optional: Configure row limit per request
provider.RowsPerDataRequest = 5000;

// Add a query for website traffic data
provider.AddQuery(
    tableName: "WebsiteTraffic",
    ids: new[] { "ga:123456789" }, // Your Analytics View ID
    startDate: "2024-01-01",
    endDate: "2024-12-31",
    metrics: new[] { "ga:sessions", "ga:pageviews", "ga:users" },
    dimensions: new[] { "ga:date", "ga:country" },
    sort: new[] { "-ga:sessions" }, // Sort by sessions descending
    filters: "ga:country==United States");

// Add another query for conversion data
provider.AddQuery(
    tableName: "Conversions",
    ids: new[] { "ga:123456789" },
    startDate: "2024-01-01",
    endDate: "2024-12-31",
    metrics: new[] { "ga:goal1Completions", "ga:transactions", "ga:transactionRevenue" },
    dimensions: new[] { "ga:date", "ga:source", "ga:medium" });

// Create a ListLabel reporting engine instance and assign the provider as the data source.
using ListLabel listLabel = new ListLabel();
listLabel.DataSource = provider;

// Configure export settings to generate a PDF.
ExportConfiguration exportConfiguration = new ExportConfiguration(LlExportTarget.Pdf, exportFilePath, projectFilePath);
exportConfiguration.ShowResult = true;

// Export the report to PDF.
listLabel.Export(exportConfiguration);

Remarks

The GoogleAnalyticsDataProvider class implements IDataProvider and ISupportsLogger to enable access to Google Analytics data through the Google Analytics Reporting API. The provider uses OAuth 2.0 authentication with refresh tokens to maintain access to Analytics data. Users can define custom queries with dimensions, metrics, filters, and segments to retrieve specific Analytics data. Each query becomes a table in the provider, allowing complex reporting scenarios with multiple data views. The provider automatically handles token refresh and supports configurable row limits per request to manage API quota usage. This is useful for creating reports that combine Analytics data with other data sources or for generating custom Analytics reports using List & Label's reporting capabilities.

Constructors

GoogleAnalyticsDataProvider(string, string, string)

Initializes a new instance of the GoogleAnalyticsDataProvider class.

public GoogleAnalyticsDataProvider(string refreshToken, string clientId, string clientSecret)

Parameters

refreshToken string

The refresh token for authentication.

clientId string

The client identifier.

clientSecret string

The client secret.

Properties

ClientId

Gets the client identifier.

public string ClientId { get; }

Property Value

string

RefreshToken

Gets the refresh token used for authentication.

public string RefreshToken { get; }

Property Value

string

RowsPerDataRequest

Gets or sets the maximum number of rows per data request.

public int RowsPerDataRequest { get; set; }

Property Value

int

Methods

AddQuery(string, string[], string, string, string[], string[]?, string[]?, string?, string?, string?, string?, string?)

Adds a new Google Analytics query to the provider.

public void AddQuery(string tableName, string[] ids, string startDate, string endDate, string[] metrics, string[]? dimensions = null, string[]? sort = null, string? filters = null, string? segment = null, string? samplingLevel = null, string? startIndex = null, string? maxResult = null)

Parameters

tableName string

The name of the table that will be created from the query results.

ids string[]

The IDs for the query.

startDate string

The start date for the query.

endDate string

The end date for the query.

metrics string[]

The metrics to retrieve.

dimensions string[]

Optional dimensions for the query.

sort string[]

Optional sort order for the query.

filters string

Optional filters for the query.

segment string

Optional segment for the query.

samplingLevel string

Optional sampling level for the query.

startIndex string

Optional starting index for the query.

maxResult string

Optional maximum result count for the query.

Exceptions

ListLabelException

Thrown if tableName is empty.