Skip to content

Commit ceb128c

Browse files
committed
Merge branch 'quickstart'
2 parents b5943da + 75c91ac commit ceb128c

5 files changed

Lines changed: 134 additions & 36 deletions

File tree

analytics-data/AnalyticsData.sln

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ VisualStudioVersion = 15.0.26124.0
55
MinimumVisualStudioVersion = 15.0.26124.0
66
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "QuickStart", "QuickStart\QuickStart.csproj", "{7D9C4AE6-192A-4A99-9933-6AF9F4FE5ECA}"
77
EndProject
8+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "QuickStartJsonCredentials", "QuickStartJsonCredentials\QuickStartJsonCredentials.csproj", "{82CAE36B-3FBE-4DAA-8A23-5D15A15BF1B0}"
9+
EndProject
810
Global
911
GlobalSection(SolutionConfigurationPlatforms) = preSolution
1012
Debug|Any CPU = Debug|Any CPU
@@ -30,5 +32,17 @@ Global
3032
{7D9C4AE6-192A-4A99-9933-6AF9F4FE5ECA}.Release|x64.Build.0 = Release|Any CPU
3133
{7D9C4AE6-192A-4A99-9933-6AF9F4FE5ECA}.Release|x86.ActiveCfg = Release|Any CPU
3234
{7D9C4AE6-192A-4A99-9933-6AF9F4FE5ECA}.Release|x86.Build.0 = Release|Any CPU
35+
{82CAE36B-3FBE-4DAA-8A23-5D15A15BF1B0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
36+
{82CAE36B-3FBE-4DAA-8A23-5D15A15BF1B0}.Debug|Any CPU.Build.0 = Debug|Any CPU
37+
{82CAE36B-3FBE-4DAA-8A23-5D15A15BF1B0}.Debug|x64.ActiveCfg = Debug|Any CPU
38+
{82CAE36B-3FBE-4DAA-8A23-5D15A15BF1B0}.Debug|x64.Build.0 = Debug|Any CPU
39+
{82CAE36B-3FBE-4DAA-8A23-5D15A15BF1B0}.Debug|x86.ActiveCfg = Debug|Any CPU
40+
{82CAE36B-3FBE-4DAA-8A23-5D15A15BF1B0}.Debug|x86.Build.0 = Debug|Any CPU
41+
{82CAE36B-3FBE-4DAA-8A23-5D15A15BF1B0}.Release|Any CPU.ActiveCfg = Release|Any CPU
42+
{82CAE36B-3FBE-4DAA-8A23-5D15A15BF1B0}.Release|Any CPU.Build.0 = Release|Any CPU
43+
{82CAE36B-3FBE-4DAA-8A23-5D15A15BF1B0}.Release|x64.ActiveCfg = Release|Any CPU
44+
{82CAE36B-3FBE-4DAA-8A23-5D15A15BF1B0}.Release|x64.Build.0 = Release|Any CPU
45+
{82CAE36B-3FBE-4DAA-8A23-5D15A15BF1B0}.Release|x86.ActiveCfg = Release|Any CPU
46+
{82CAE36B-3FBE-4DAA-8A23-5D15A15BF1B0}.Release|x86.Build.0 = Release|Any CPU
3347
EndGlobalSection
3448
EndGlobal

analytics-data/QuickStart/QuickStart.cs

Lines changed: 12 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -26,52 +26,29 @@ dotnet restore
2626
dotnet run
2727
*/
2828

29-
// [START google_analytics_data_quickstart]
29+
// [START analyticsdata_quickstart]
3030
using Google.Analytics.Data.V1Beta;
31-
using Google.Api.Gax;
3231
using System;
3332

3433
namespace AnalyticsSamples
3534
{
3635
class QuickStart
3736
{
38-
static void SampleRunReport(string propertyId="YOUR-GA4-PROPERTY-ID", string credentialsJsonPath="")
37+
static void SampleRunReport(string propertyId="YOUR-GA4-PROPERTY-ID")
3938
{
4039
/**
4140
* TODO(developer): Uncomment this variable and replace with your
4241
* Google Analytics 4 property ID before running the sample.
4342
*/
4443
// propertyId = "YOUR-GA4-PROPERTY-ID";
4544

46-
// [START google_analytics_data_initialize]
47-
/**
48-
* TODO(developer): Uncomment this variable and replace with a valid path to
49-
* the credentials.json file for your service account downloaded from the
50-
* Cloud Console.
51-
* Otherwise, default service account credentials will be derived from
52-
* the GOOGLE_APPLICATION_CREDENTIALS environment variable.
53-
*/
54-
// credentialsJsonPath = "/path/to/credentials.json";
55-
56-
BetaAnalyticsDataClient client;
57-
if(String.IsNullOrEmpty(credentialsJsonPath))
58-
{
59-
// Using a default constructor instructs the client to use the credentials
60-
// specified in GOOGLE_APPLICATION_CREDENTIALS environment variable.
61-
client = BetaAnalyticsDataClient.Create();
62-
}
63-
else
64-
{
65-
// Explicitly use service account credentials by specifying
66-
// the private key file.
67-
client = new BetaAnalyticsDataClientBuilder
68-
{
69-
CredentialsPath = credentialsJsonPath
70-
}.Build();
71-
}
72-
// [END google_analytics_data_initialize]
45+
// [START analyticsdata_initialize]
46+
// Using a default constructor instructs the client to use the credentials
47+
// specified in GOOGLE_APPLICATION_CREDENTIALS environment variable.
48+
BetaAnalyticsDataClient client = BetaAnalyticsDataClient.Create();
49+
// [END analyticsdata_initialize]
7350

74-
// [START google_analytics_data_run_report]
51+
// [START analyticsdata_run_report]
7552
// Initialize request argument(s)
7653
RunReportRequest request = new RunReportRequest
7754
{
@@ -83,9 +60,9 @@ static void SampleRunReport(string propertyId="YOUR-GA4-PROPERTY-ID", string cre
8360

8461
// Make the request
8562
PagedEnumerable<RunReportResponse, DimensionHeader> response = client.RunReport(request);
86-
// [END google_analytics_data_run_report]
63+
// [END analyticsdata_run_report]
8764

88-
// [START google_analytics_data_print_report]
65+
// [START analyticsdata_run_report_response]
8966
Console.WriteLine("Report result:");
9067
foreach(RunReportResponse page in response.AsRawResponses())
9168
{
@@ -94,7 +71,7 @@ static void SampleRunReport(string propertyId="YOUR-GA4-PROPERTY-ID", string cre
9471
Console.WriteLine("{0}, {1}", row.DimensionValues[0].Value, row.MetricValues[0].Value);
9572
}
9673
}
97-
// [END google_analytics_data_print_report]
74+
// [END analyticsdata_run_report_response]
9875
}
9976
static int Main(string[] args)
10077
{
@@ -103,4 +80,4 @@ static int Main(string[] args)
10380
}
10481
}
10582
}
106-
// [END google_analytics_data_quickstart]
83+
// [END analyticsdata_quickstart]

analytics-data/QuickStart/QuickStart.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
</PropertyGroup>
77

88
<ItemGroup>
9-
<PackageReference Include="Google.Analytics.Data.V1Beta" Version="1.0.0-beta01" />
9+
<PackageReference Include="Google.Analytics.Data.V1Beta" Version="1.0.0-beta02" />
1010
</ItemGroup>
1111

1212
</Project>
Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
// Copyright(c) 2020 Google Inc.
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License"); you may not
4+
// use this file except in compliance with the License. You may obtain a copy of
5+
// the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
11+
// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12+
// License for the specific language governing permissions and limitations under
13+
// the License.
14+
15+
/* Google Analytics Data API sample quickstart application.
16+
17+
Before you start the application, please review the comments starting with
18+
"TODO(developer)" and update the code to use correct values.
19+
20+
This application demonstrates the usage of the Analytics Data API using service
21+
account credentials.
22+
23+
Usage:
24+
cd analytics-data/QuickStartJsonCredentials
25+
dotnet restore
26+
dotnet run
27+
*/
28+
29+
// [START analyticsdata_json_credentials_quickstart]
30+
using Google.Analytics.Data.V1Beta;
31+
using System;
32+
33+
namespace AnalyticsSamples
34+
{
35+
class QuickStartJsonCredentials
36+
{
37+
static void SampleRunReport(string propertyId="YOUR-GA4-PROPERTY-ID", string credentialsJsonPath="")
38+
{
39+
/**
40+
* TODO(developer): Uncomment this variable and replace with your
41+
* Google Analytics 4 property ID before running the sample.
42+
*/
43+
// propertyId = "YOUR-GA4-PROPERTY-ID";
44+
45+
// [START analyticsdata_json_credentials_initialize]
46+
/**
47+
* TODO(developer): Uncomment this variable and replace with a valid path to
48+
* the credentials.json file for your service account downloaded from the
49+
* Cloud Console.
50+
* Otherwise, default service account credentials will be derived from
51+
* the GOOGLE_APPLICATION_CREDENTIALS environment variable.
52+
*/
53+
// credentialsJsonPath = "/path/to/credentials.json";
54+
55+
// Explicitly use service account credentials by specifying
56+
// the private key file.
57+
BetaAnalyticsDataClient client = new BetaAnalyticsDataClientBuilder
58+
{
59+
CredentialsPath = credentialsJsonPath
60+
}.Build();
61+
// [END analyticsdata_json_credentials_initialize]
62+
63+
// [START analyticsdata_json_credentials_run_report]
64+
// Initialize request argument(s)
65+
RunReportRequest request = new RunReportRequest
66+
{
67+
Property = "property/" + propertyId,
68+
Dimensions = { new Dimension{ Name="city"}, },
69+
Metrics = { new Metric{ Name="activeUsers"}, },
70+
DateRanges = { new DateRange{ StartDate="2020-03-31", EndDate="today"}, },
71+
};
72+
73+
// Make the request
74+
PagedEnumerable<RunReportResponse, DimensionHeader> response = client.RunReport(request);
75+
// [END analyticsdata_json_credentials_run_report]
76+
77+
// [START analyticsdata_json_credentials_run_report_response]
78+
Console.WriteLine("Report result:");
79+
foreach(RunReportResponse page in response.AsRawResponses())
80+
{
81+
foreach(Row row in page.Rows)
82+
{
83+
Console.WriteLine("{0}, {1}", row.DimensionValues[0].Value, row.MetricValues[0].Value);
84+
}
85+
}
86+
// [END analyticsdata_json_credentials_run_report_response]
87+
}
88+
static int Main(string[] args)
89+
{
90+
SampleRunReport();
91+
return 0;
92+
}
93+
}
94+
}
95+
// [END analyticsdata_json_credentials_quickstart]
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<OutputType>Exe</OutputType>
5+
<TargetFramework>netcoreapp3.1</TargetFramework>
6+
</PropertyGroup>
7+
8+
<ItemGroup>
9+
<PackageReference Include="Google.Analytics.Data.V1Beta" Version="1.0.0-beta02" />
10+
</ItemGroup>
11+
12+
</Project>

0 commit comments

Comments
 (0)