Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions analytics-admin/QuickStart/QuickStart.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,9 @@ JSON file.

// [START analyticsadmin_quickstart]

using System;
using Google.Analytics.Admin.V1Beta;
using Google.Api.Gax;
using System;

namespace AnalyticsSamples
{
Expand All @@ -60,9 +60,10 @@ class QuickStart
static void Main(string[] args)
{
AnalyticsAdminServiceClient client = AnalyticsAdminServiceClient.Create();
PagedEnumerable<ListAccountsResponse, Account> response =
client.ListAccounts( new ListAccountsRequest() );
foreach( Account account in response )
PagedEnumerable<ListAccountsResponse, Account> response = client.ListAccounts(
new ListAccountsRequest()
);
foreach (Account account in response)
{
Console.WriteLine("Account name: {0}", account.Name);
Console.WriteLine("Display name: {0}", account.DisplayName);
Expand Down
6 changes: 2 additions & 4 deletions analytics-admin/QuickStart/QuickStart.csproj
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFrameworks>net6.0;net462</TargetFrameworks>
<TargetFrameworks Condition=" '$(OS)' != 'Windows_NT' ">net6.0</TargetFrameworks>
<TargetFrameworks>net8.0;net462</TargetFrameworks>
<TargetFrameworks Condition=" '$(OS)' != 'Windows_NT' ">net8.0</TargetFrameworks>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Google.Analytics.Admin.V1Beta" Version="1.0.0-beta10" />
</ItemGroup>

</Project>
29 changes: 20 additions & 9 deletions analytics-data/QuickStart/QuickStart.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,14 @@ dotnet run
*/

// [START analyticsdata_quickstart]
using Google.Analytics.Data.V1Beta;
using System;
using Google.Analytics.Data.V1Beta;

namespace AnalyticsSamples
{
class QuickStart
{
static void SampleRunReport(string propertyId="YOUR-GA4-PROPERTY-ID")
static void SampleRunReport(string propertyId = "YOUR-GA4-PROPERTY-ID")
{
/**
* TODO(developer): Uncomment this variable and replace with your
Expand All @@ -53,9 +53,12 @@ static void SampleRunReport(string propertyId="YOUR-GA4-PROPERTY-ID")
RunReportRequest request = new RunReportRequest
{
Property = "properties/" + propertyId,
Dimensions = { new Dimension{ Name="city"}, },
Metrics = { new Metric{ Name="activeUsers"}, },
DateRanges = { new DateRange{ StartDate="2020-03-31", EndDate="today"}, },
Dimensions = { new Dimension { Name = "city" } },
Metrics = { new Metric { Name = "activeUsers" } },
DateRanges =
{
new DateRange { StartDate = "2020-03-31", EndDate = "today" },
},
};

// Make the request
Expand All @@ -64,17 +67,25 @@ static void SampleRunReport(string propertyId="YOUR-GA4-PROPERTY-ID")

// [START analyticsdata_run_report_response]
Console.WriteLine("Report result:");
foreach(Row row in response.Rows)
foreach (Row row in response.Rows)
{
Console.WriteLine("{0}, {1}", row.DimensionValues[0].Value, row.MetricValues[0].Value);
Console.WriteLine(
"{0}, {1}",
row.DimensionValues[0].Value,
row.MetricValues[0].Value
);
}
// [END analyticsdata_run_report_response]
}

static int Main(string[] args)
{
if (args.Length > 0) {
if (args.Length > 0)
{
SampleRunReport(args[0]);
} else {
}
else
{
SampleRunReport();
}
return 0;
Expand Down
6 changes: 2 additions & 4 deletions analytics-data/QuickStart/QuickStart.csproj
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFrameworks>net6.0;net462</TargetFrameworks>
<TargetFrameworks Condition=" '$(OS)' != 'Windows_NT' ">net6.0</TargetFrameworks>
<TargetFrameworks>net8.0;net462</TargetFrameworks>
<TargetFrameworks Condition=" '$(OS)' != 'Windows_NT' ">net8.0</TargetFrameworks>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Google.Analytics.Data.V1Beta" Version="2.0.0-beta10" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,21 @@ dotnet run
*/

// [START analyticsdata_json_credentials_quickstart]
using System;
using System.IO;
using Google.Analytics.Data.V1Beta;
using Google.Api.Gax;
using System;
using Google.Apis.Auth;
using Google.Apis.Auth.OAuth2;

namespace AnalyticsSamples
{
class QuickStartJsonCredentials
{
static void SampleRunReport(string propertyId="YOUR-GA4-PROPERTY-ID",
string credentialsJsonPath="YOUR-CREDENTIALS-FILE")
static void SampleRunReport(
string propertyId = "YOUR-GA4-PROPERTY-ID",
string credentialsJsonPath = "YOUR-CREDENTIALS-FILE"
)
{
/**
* TODO(developer): Uncomment this variable and replace with your
Expand All @@ -54,11 +59,19 @@ static void SampleRunReport(string propertyId="YOUR-GA4-PROPERTY-ID",
*/
// credentialsJsonPath = "/path/to/credentials.json";

GoogleCredential credential;
using (var stream = new FileStream(credentialsJsonPath, FileMode.Open, FileAccess.Read))
{
credential = CredentialFactory
.FromStream<ServiceAccountCredential>(stream)
.ToGoogleCredential();
}

// Explicitly use service account credentials by specifying
// the private key file.
BetaAnalyticsDataClient client = new BetaAnalyticsDataClientBuilder
{
CredentialsPath = credentialsJsonPath
GoogleCredential = credential,
}.Build();
// [END analyticsdata_json_credentials_initialize]

Expand All @@ -67,9 +80,12 @@ static void SampleRunReport(string propertyId="YOUR-GA4-PROPERTY-ID",
RunReportRequest request = new RunReportRequest
{
Property = "properties/" + propertyId,
Dimensions = { new Dimension{ Name="city"}, },
Metrics = { new Metric{ Name="activeUsers"}, },
DateRanges = { new DateRange{ StartDate="2020-03-31", EndDate="today"}, },
Dimensions = { new Dimension { Name = "city" } },
Metrics = { new Metric { Name = "activeUsers" } },
DateRanges =
{
new DateRange { StartDate = "2020-03-31", EndDate = "today" },
},
};

// Make the request
Expand All @@ -80,17 +96,25 @@ static void SampleRunReport(string propertyId="YOUR-GA4-PROPERTY-ID",
// For more information on processing paged responses, see:
// https://cloud.google.com/dotnet/docs/reference/help/page-streaming
Console.WriteLine("Report result:");
foreach(Row row in response.Rows)
foreach (Row row in response.Rows)
{
Console.WriteLine("{0}, {1}", row.DimensionValues[0].Value, row.MetricValues[0].Value);
Console.WriteLine(
"{0}, {1}",
row.DimensionValues[0].Value,
row.MetricValues[0].Value
);
}
// [END analyticsdata_json_credentials_run_report_response]
}

static int Main(string[] args)
{
if (args.Length > 0) {
if (args.Length > 0)
{
SampleRunReport(args[0], args[1]);
} else {
}
else
{
SampleRunReport();
}
return 0;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFrameworks>net6.0;net462</TargetFrameworks>
<TargetFrameworks Condition=" '$(OS)' != 'Windows_NT' ">net6.0</TargetFrameworks>
<TargetFrameworks>net8.0;net462</TargetFrameworks>
<TargetFrameworks Condition=" '$(OS)' != 'Windows_NT' ">net8.0</TargetFrameworks>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Google.Analytics.Data.V1Beta" Version="2.0.0-beta10" />
</ItemGroup>

</Project>