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
refreshTokenstringThe refresh token for authentication.
clientIdstringThe client identifier.
clientSecretstringThe client secret.
Properties
ClientId
Gets the client identifier.
public string ClientId { get; }
Property Value
RefreshToken
Gets the refresh token used for authentication.
public string RefreshToken { get; }
Property Value
RowsPerDataRequest
Gets or sets the maximum number of rows per data request.
public int RowsPerDataRequest { get; set; }
Property Value
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
tableNamestringThe name of the table that will be created from the query results.
idsstring[]The IDs for the query.
startDatestringThe start date for the query.
endDatestringThe end date for the query.
metricsstring[]The metrics to retrieve.
dimensionsstring[]Optional dimensions for the query.
sortstring[]Optional sort order for the query.
filtersstringOptional filters for the query.
segmentstringOptional segment for the query.
samplingLevelstringOptional sampling level for the query.
startIndexstringOptional starting index for the query.
maxResultstringOptional maximum result count for the query.
Exceptions
- ListLabelException
Thrown if
tableNameis empty.