The ADO.NET provider for Google Analytics provides a wide range of features that enable connectivity to Google Analytics from .Net applications . The documentation will help you understand the C1.AdoNet.GoogleAnalytics namespace, which includes all the available classes that can be used to connect and retrieve data from Google Analytics
DataConnectors, are mostly used in combination with other ComponentOne components, such as DataEngine and FlexPivot. The procedure below describes the first steps to use the DataConnector in a console application within Visual Studio.
To use the ADO.NET provider for Google Analytics in an application, the respective NuGet package should be added:
Follow the steps provided below to learn and implement data retrieval using ADO.NET provider for Google Analytics.
C# |
コードのコピー
|
---|---|
const string KeyFile = "*******"; const string ViewId = "************"; |
C# |
コードのコピー
|
---|---|
static void ReadData() { //接続文字列を定義します。 string connectionString = string.Format("Key File={0};View Id={1}", KeyFile, ViewId); //コマンドを定義します。 string sql = "SELECT Source, Sessions FROM Traffic WHERE Sessions > 500 AND StartDate = '14DaysAgo' AND EndDate = 'Today'"; //データを取得します。 using (var con = new C1GoogleAnalyticsConnection(connectionString)) { con.Open(); var command = con.CreateCommand(); command.CommandText = sql; var reader = command.ExecuteReader(); while (reader.Read()) { Console.WriteLine(String.Format("{0} --> \t\t{1}", reader["Source"], reader["Sessions"])); } } } |