@BetaApi @Generated(value="by gapic-generator-java") public class BetaAnalyticsDataClient extends Object implements com.google.api.gax.core.BackgroundResource
This class provides the ability to make remote calls to the backing service through method calls that map to API methods. Sample code to get started:
try (BetaAnalyticsDataClient betaAnalyticsDataClient = BetaAnalyticsDataClient.create()) {
RunReportRequest request =
RunReportRequest.newBuilder()
.setProperty("property-993141291")
.addAllDimensions(new ArrayList<Dimension>())
.addAllMetrics(new ArrayList<Metric>())
.addAllDateRanges(new ArrayList<DateRange>())
.setDimensionFilter(FilterExpression.newBuilder().build())
.setMetricFilter(FilterExpression.newBuilder().build())
.setOffset(-1019779949)
.setLimit(102976443)
.addAllMetricAggregations(new ArrayList<MetricAggregation>())
.addAllOrderBys(new ArrayList<OrderBy>())
.setCurrencyCode("currencyCode1004773790")
.setCohortSpec(CohortSpec.newBuilder().build())
.setKeepEmptyRows(true)
.setReturnPropertyQuota(true)
.build();
RunReportResponse response = betaAnalyticsDataClient.runReport(request);
}
Note: close() needs to be called on the BetaAnalyticsDataClient object to clean up resources such as threads. In the example above, try-with-resources is used, which automatically calls close().
The surface of this class includes several types of Java methods for each of the API's methods:
See the individual methods for example code.
Many parameters require resource names to be formatted in a particular way. To assist with these names, this class includes a format method for each type of name, and additionally a parse method to extract the individual identifiers contained within names that are returned.
This class can be customized by passing in a custom instance of BetaAnalyticsDataSettings to create(). For example:
To customize credentials:
BetaAnalyticsDataSettings betaAnalyticsDataSettings =
BetaAnalyticsDataSettings.newBuilder()
.setCredentialsProvider(FixedCredentialsProvider.create(myCredentials))
.build();
BetaAnalyticsDataClient betaAnalyticsDataClient =
BetaAnalyticsDataClient.create(betaAnalyticsDataSettings);
To customize the endpoint:
BetaAnalyticsDataSettings betaAnalyticsDataSettings =
BetaAnalyticsDataSettings.newBuilder().setEndpoint(myEndpoint).build();
BetaAnalyticsDataClient betaAnalyticsDataClient =
BetaAnalyticsDataClient.create(betaAnalyticsDataSettings);
Please refer to the GitHub repository's samples for more quickstart code snippets.
| Modifier | Constructor and Description |
|---|---|
protected |
BetaAnalyticsDataClient(BetaAnalyticsDataSettings settings)
Constructs an instance of BetaAnalyticsDataClient, using the given settings.
|
protected |
BetaAnalyticsDataClient(BetaAnalyticsDataStub stub) |
| Modifier and Type | Method and Description |
|---|---|
boolean |
awaitTermination(long duration,
TimeUnit unit) |
BatchRunPivotReportsResponse |
batchRunPivotReports(BatchRunPivotReportsRequest request)
Returns multiple pivot reports in a batch.
|
com.google.api.gax.rpc.UnaryCallable<BatchRunPivotReportsRequest,BatchRunPivotReportsResponse> |
batchRunPivotReportsCallable()
Returns multiple pivot reports in a batch.
|
BatchRunReportsResponse |
batchRunReports(BatchRunReportsRequest request)
Returns multiple reports in a batch.
|
com.google.api.gax.rpc.UnaryCallable<BatchRunReportsRequest,BatchRunReportsResponse> |
batchRunReportsCallable()
Returns multiple reports in a batch.
|
CheckCompatibilityResponse |
checkCompatibility(CheckCompatibilityRequest request)
This compatibility method lists dimensions and metrics that can be added to a report request
and maintain compatibility.
|
com.google.api.gax.rpc.UnaryCallable<CheckCompatibilityRequest,CheckCompatibilityResponse> |
checkCompatibilityCallable()
This compatibility method lists dimensions and metrics that can be added to a report request
and maintain compatibility.
|
void |
close() |
static BetaAnalyticsDataClient |
create()
Constructs an instance of BetaAnalyticsDataClient with default settings.
|
static BetaAnalyticsDataClient |
create(BetaAnalyticsDataSettings settings)
Constructs an instance of BetaAnalyticsDataClient, using the given settings.
|
static BetaAnalyticsDataClient |
create(BetaAnalyticsDataStub stub)
Constructs an instance of BetaAnalyticsDataClient, using the given stub for making calls.
|
Metadata |
getMetadata(GetMetadataRequest request)
Returns metadata for dimensions and metrics available in reporting methods.
|
Metadata |
getMetadata(MetadataName name)
Returns metadata for dimensions and metrics available in reporting methods.
|
Metadata |
getMetadata(String name)
Returns metadata for dimensions and metrics available in reporting methods.
|
com.google.api.gax.rpc.UnaryCallable<GetMetadataRequest,Metadata> |
getMetadataCallable()
Returns metadata for dimensions and metrics available in reporting methods.
|
BetaAnalyticsDataSettings |
getSettings() |
BetaAnalyticsDataStub |
getStub() |
boolean |
isShutdown() |
boolean |
isTerminated() |
RunPivotReportResponse |
runPivotReport(RunPivotReportRequest request)
Returns a customized pivot report of your Google Analytics event data.
|
com.google.api.gax.rpc.UnaryCallable<RunPivotReportRequest,RunPivotReportResponse> |
runPivotReportCallable()
Returns a customized pivot report of your Google Analytics event data.
|
RunRealtimeReportResponse |
runRealtimeReport(RunRealtimeReportRequest request)
The Google Analytics Realtime API returns a customized report of realtime event data for your
property.
|
com.google.api.gax.rpc.UnaryCallable<RunRealtimeReportRequest,RunRealtimeReportResponse> |
runRealtimeReportCallable()
The Google Analytics Realtime API returns a customized report of realtime event data for your
property.
|
RunReportResponse |
runReport(RunReportRequest request)
Returns a customized report of your Google Analytics event data.
|
com.google.api.gax.rpc.UnaryCallable<RunReportRequest,RunReportResponse> |
runReportCallable()
Returns a customized report of your Google Analytics event data.
|
void |
shutdown() |
void |
shutdownNow() |
protected BetaAnalyticsDataClient(BetaAnalyticsDataSettings settings) throws IOException
IOException@BetaApi(value="A restructuring of stub classes is planned, so this may break in the future") protected BetaAnalyticsDataClient(BetaAnalyticsDataStub stub)
public static final BetaAnalyticsDataClient create() throws IOException
IOExceptionpublic static final BetaAnalyticsDataClient create(BetaAnalyticsDataSettings settings) throws IOException
IOException@BetaApi(value="A restructuring of stub classes is planned, so this may break in the future") public static final BetaAnalyticsDataClient create(BetaAnalyticsDataStub stub)
public final BetaAnalyticsDataSettings getSettings()
@BetaApi(value="A restructuring of stub classes is planned, so this may break in the future") public BetaAnalyticsDataStub getStub()
public final RunReportResponse runReport(RunReportRequest request)
Sample code:
try (BetaAnalyticsDataClient betaAnalyticsDataClient = BetaAnalyticsDataClient.create()) {
RunReportRequest request =
RunReportRequest.newBuilder()
.setProperty("property-993141291")
.addAllDimensions(new ArrayList<Dimension>())
.addAllMetrics(new ArrayList<Metric>())
.addAllDateRanges(new ArrayList<DateRange>())
.setDimensionFilter(FilterExpression.newBuilder().build())
.setMetricFilter(FilterExpression.newBuilder().build())
.setOffset(-1019779949)
.setLimit(102976443)
.addAllMetricAggregations(new ArrayList<MetricAggregation>())
.addAllOrderBys(new ArrayList<OrderBy>())
.setCurrencyCode("currencyCode1004773790")
.setCohortSpec(CohortSpec.newBuilder().build())
.setKeepEmptyRows(true)
.setReturnPropertyQuota(true)
.build();
RunReportResponse response = betaAnalyticsDataClient.runReport(request);
}
request - The request object containing all of the parameters for the API call.com.google.api.gax.rpc.ApiException - if the remote call failspublic final com.google.api.gax.rpc.UnaryCallable<RunReportRequest,RunReportResponse> runReportCallable()
Sample code:
try (BetaAnalyticsDataClient betaAnalyticsDataClient = BetaAnalyticsDataClient.create()) {
RunReportRequest request =
RunReportRequest.newBuilder()
.setProperty("property-993141291")
.addAllDimensions(new ArrayList<Dimension>())
.addAllMetrics(new ArrayList<Metric>())
.addAllDateRanges(new ArrayList<DateRange>())
.setDimensionFilter(FilterExpression.newBuilder().build())
.setMetricFilter(FilterExpression.newBuilder().build())
.setOffset(-1019779949)
.setLimit(102976443)
.addAllMetricAggregations(new ArrayList<MetricAggregation>())
.addAllOrderBys(new ArrayList<OrderBy>())
.setCurrencyCode("currencyCode1004773790")
.setCohortSpec(CohortSpec.newBuilder().build())
.setKeepEmptyRows(true)
.setReturnPropertyQuota(true)
.build();
ApiFuture<RunReportResponse> future =
betaAnalyticsDataClient.runReportCallable().futureCall(request);
// Do something.
RunReportResponse response = future.get();
}
public final RunPivotReportResponse runPivotReport(RunPivotReportRequest request)
Sample code:
try (BetaAnalyticsDataClient betaAnalyticsDataClient = BetaAnalyticsDataClient.create()) {
RunPivotReportRequest request =
RunPivotReportRequest.newBuilder()
.setProperty("property-993141291")
.addAllDimensions(new ArrayList<Dimension>())
.addAllMetrics(new ArrayList<Metric>())
.addAllDateRanges(new ArrayList<DateRange>())
.addAllPivots(new ArrayList<Pivot>())
.setDimensionFilter(FilterExpression.newBuilder().build())
.setMetricFilter(FilterExpression.newBuilder().build())
.setCurrencyCode("currencyCode1004773790")
.setCohortSpec(CohortSpec.newBuilder().build())
.setKeepEmptyRows(true)
.setReturnPropertyQuota(true)
.build();
RunPivotReportResponse response = betaAnalyticsDataClient.runPivotReport(request);
}
request - The request object containing all of the parameters for the API call.com.google.api.gax.rpc.ApiException - if the remote call failspublic final com.google.api.gax.rpc.UnaryCallable<RunPivotReportRequest,RunPivotReportResponse> runPivotReportCallable()
Sample code:
try (BetaAnalyticsDataClient betaAnalyticsDataClient = BetaAnalyticsDataClient.create()) {
RunPivotReportRequest request =
RunPivotReportRequest.newBuilder()
.setProperty("property-993141291")
.addAllDimensions(new ArrayList<Dimension>())
.addAllMetrics(new ArrayList<Metric>())
.addAllDateRanges(new ArrayList<DateRange>())
.addAllPivots(new ArrayList<Pivot>())
.setDimensionFilter(FilterExpression.newBuilder().build())
.setMetricFilter(FilterExpression.newBuilder().build())
.setCurrencyCode("currencyCode1004773790")
.setCohortSpec(CohortSpec.newBuilder().build())
.setKeepEmptyRows(true)
.setReturnPropertyQuota(true)
.build();
ApiFuture<RunPivotReportResponse> future =
betaAnalyticsDataClient.runPivotReportCallable().futureCall(request);
// Do something.
RunPivotReportResponse response = future.get();
}
public final BatchRunReportsResponse batchRunReports(BatchRunReportsRequest request)
Sample code:
try (BetaAnalyticsDataClient betaAnalyticsDataClient = BetaAnalyticsDataClient.create()) {
BatchRunReportsRequest request =
BatchRunReportsRequest.newBuilder()
.setProperty("property-993141291")
.addAllRequests(new ArrayList<RunReportRequest>())
.build();
BatchRunReportsResponse response = betaAnalyticsDataClient.batchRunReports(request);
}
request - The request object containing all of the parameters for the API call.com.google.api.gax.rpc.ApiException - if the remote call failspublic final com.google.api.gax.rpc.UnaryCallable<BatchRunReportsRequest,BatchRunReportsResponse> batchRunReportsCallable()
Sample code:
try (BetaAnalyticsDataClient betaAnalyticsDataClient = BetaAnalyticsDataClient.create()) {
BatchRunReportsRequest request =
BatchRunReportsRequest.newBuilder()
.setProperty("property-993141291")
.addAllRequests(new ArrayList<RunReportRequest>())
.build();
ApiFuture<BatchRunReportsResponse> future =
betaAnalyticsDataClient.batchRunReportsCallable().futureCall(request);
// Do something.
BatchRunReportsResponse response = future.get();
}
public final BatchRunPivotReportsResponse batchRunPivotReports(BatchRunPivotReportsRequest request)
Sample code:
try (BetaAnalyticsDataClient betaAnalyticsDataClient = BetaAnalyticsDataClient.create()) {
BatchRunPivotReportsRequest request =
BatchRunPivotReportsRequest.newBuilder()
.setProperty("property-993141291")
.addAllRequests(new ArrayList<RunPivotReportRequest>())
.build();
BatchRunPivotReportsResponse response = betaAnalyticsDataClient.batchRunPivotReports(request);
}
request - The request object containing all of the parameters for the API call.com.google.api.gax.rpc.ApiException - if the remote call failspublic final com.google.api.gax.rpc.UnaryCallable<BatchRunPivotReportsRequest,BatchRunPivotReportsResponse> batchRunPivotReportsCallable()
Sample code:
try (BetaAnalyticsDataClient betaAnalyticsDataClient = BetaAnalyticsDataClient.create()) {
BatchRunPivotReportsRequest request =
BatchRunPivotReportsRequest.newBuilder()
.setProperty("property-993141291")
.addAllRequests(new ArrayList<RunPivotReportRequest>())
.build();
ApiFuture<BatchRunPivotReportsResponse> future =
betaAnalyticsDataClient.batchRunPivotReportsCallable().futureCall(request);
// Do something.
BatchRunPivotReportsResponse response = future.get();
}
public final Metadata getMetadata(MetadataName name)
For example if a custom metric with parameter name `levels_unlocked` is registered to a property, the Metadata response will contain `customEvent:levels_unlocked`. Universal metadata are dimensions and metrics applicable to any property such as `country` and `totalUsers`.
Sample code:
try (BetaAnalyticsDataClient betaAnalyticsDataClient = BetaAnalyticsDataClient.create()) {
MetadataName name = MetadataName.of("[PROPERTY]");
Metadata response = betaAnalyticsDataClient.getMetadata(name);
}
name - Required. The resource name of the metadata to retrieve. This name field is
specified in the URL path and not URL parameters. Property is a numeric Google Analytics
GA4 Property identifier. To learn more, see [where to find your Property
ID](https://developers.google.com/analytics/devguides/reporting/data/v1/property-id).
Example: properties/1234/metadata
Set the Property ID to 0 for dimensions and metrics common to all properties. In this special mode, this method will not return custom dimensions and metrics.
com.google.api.gax.rpc.ApiException - if the remote call failspublic final Metadata getMetadata(String name)
For example if a custom metric with parameter name `levels_unlocked` is registered to a property, the Metadata response will contain `customEvent:levels_unlocked`. Universal metadata are dimensions and metrics applicable to any property such as `country` and `totalUsers`.
Sample code:
try (BetaAnalyticsDataClient betaAnalyticsDataClient = BetaAnalyticsDataClient.create()) {
String name = MetadataName.of("[PROPERTY]").toString();
Metadata response = betaAnalyticsDataClient.getMetadata(name);
}
name - Required. The resource name of the metadata to retrieve. This name field is
specified in the URL path and not URL parameters. Property is a numeric Google Analytics
GA4 Property identifier. To learn more, see [where to find your Property
ID](https://developers.google.com/analytics/devguides/reporting/data/v1/property-id).
Example: properties/1234/metadata
Set the Property ID to 0 for dimensions and metrics common to all properties. In this special mode, this method will not return custom dimensions and metrics.
com.google.api.gax.rpc.ApiException - if the remote call failspublic final Metadata getMetadata(GetMetadataRequest request)
For example if a custom metric with parameter name `levels_unlocked` is registered to a property, the Metadata response will contain `customEvent:levels_unlocked`. Universal metadata are dimensions and metrics applicable to any property such as `country` and `totalUsers`.
Sample code:
try (BetaAnalyticsDataClient betaAnalyticsDataClient = BetaAnalyticsDataClient.create()) {
GetMetadataRequest request =
GetMetadataRequest.newBuilder().setName(MetadataName.of("[PROPERTY]").toString()).build();
Metadata response = betaAnalyticsDataClient.getMetadata(request);
}
request - The request object containing all of the parameters for the API call.com.google.api.gax.rpc.ApiException - if the remote call failspublic final com.google.api.gax.rpc.UnaryCallable<GetMetadataRequest,Metadata> getMetadataCallable()
For example if a custom metric with parameter name `levels_unlocked` is registered to a property, the Metadata response will contain `customEvent:levels_unlocked`. Universal metadata are dimensions and metrics applicable to any property such as `country` and `totalUsers`.
Sample code:
try (BetaAnalyticsDataClient betaAnalyticsDataClient = BetaAnalyticsDataClient.create()) {
GetMetadataRequest request =
GetMetadataRequest.newBuilder().setName(MetadataName.of("[PROPERTY]").toString()).build();
ApiFuture<Metadata> future =
betaAnalyticsDataClient.getMetadataCallable().futureCall(request);
// Do something.
Metadata response = future.get();
}
public final RunRealtimeReportResponse runRealtimeReport(RunRealtimeReportRequest request)
Sample code:
try (BetaAnalyticsDataClient betaAnalyticsDataClient = BetaAnalyticsDataClient.create()) {
RunRealtimeReportRequest request =
RunRealtimeReportRequest.newBuilder()
.setProperty("property-993141291")
.addAllDimensions(new ArrayList<Dimension>())
.addAllMetrics(new ArrayList<Metric>())
.setDimensionFilter(FilterExpression.newBuilder().build())
.setMetricFilter(FilterExpression.newBuilder().build())
.setLimit(102976443)
.addAllMetricAggregations(new ArrayList<MetricAggregation>())
.addAllOrderBys(new ArrayList<OrderBy>())
.setReturnPropertyQuota(true)
.addAllMinuteRanges(new ArrayList<MinuteRange>())
.build();
RunRealtimeReportResponse response = betaAnalyticsDataClient.runRealtimeReport(request);
}
request - The request object containing all of the parameters for the API call.com.google.api.gax.rpc.ApiException - if the remote call failspublic final com.google.api.gax.rpc.UnaryCallable<RunRealtimeReportRequest,RunRealtimeReportResponse> runRealtimeReportCallable()
Sample code:
try (BetaAnalyticsDataClient betaAnalyticsDataClient = BetaAnalyticsDataClient.create()) {
RunRealtimeReportRequest request =
RunRealtimeReportRequest.newBuilder()
.setProperty("property-993141291")
.addAllDimensions(new ArrayList<Dimension>())
.addAllMetrics(new ArrayList<Metric>())
.setDimensionFilter(FilterExpression.newBuilder().build())
.setMetricFilter(FilterExpression.newBuilder().build())
.setLimit(102976443)
.addAllMetricAggregations(new ArrayList<MetricAggregation>())
.addAllOrderBys(new ArrayList<OrderBy>())
.setReturnPropertyQuota(true)
.addAllMinuteRanges(new ArrayList<MinuteRange>())
.build();
ApiFuture<RunRealtimeReportResponse> future =
betaAnalyticsDataClient.runRealtimeReportCallable().futureCall(request);
// Do something.
RunRealtimeReportResponse response = future.get();
}
public final CheckCompatibilityResponse checkCompatibility(CheckCompatibilityRequest request)
In Google Analytics, reports fail if they request incompatible dimensions and/or metrics; in that case, you will need to remove dimensions and/or metrics from the incompatible report until the report is compatible.
The Realtime and Core reports have different compatibility rules. This method checks compatibility for Core reports.
Sample code:
try (BetaAnalyticsDataClient betaAnalyticsDataClient = BetaAnalyticsDataClient.create()) {
CheckCompatibilityRequest request =
CheckCompatibilityRequest.newBuilder()
.setProperty("property-993141291")
.addAllDimensions(new ArrayList<Dimension>())
.addAllMetrics(new ArrayList<Metric>())
.setDimensionFilter(FilterExpression.newBuilder().build())
.setMetricFilter(FilterExpression.newBuilder().build())
.setCompatibilityFilter(Compatibility.forNumber(0))
.build();
CheckCompatibilityResponse response = betaAnalyticsDataClient.checkCompatibility(request);
}
request - The request object containing all of the parameters for the API call.com.google.api.gax.rpc.ApiException - if the remote call failspublic final com.google.api.gax.rpc.UnaryCallable<CheckCompatibilityRequest,CheckCompatibilityResponse> checkCompatibilityCallable()
In Google Analytics, reports fail if they request incompatible dimensions and/or metrics; in that case, you will need to remove dimensions and/or metrics from the incompatible report until the report is compatible.
The Realtime and Core reports have different compatibility rules. This method checks compatibility for Core reports.
Sample code:
try (BetaAnalyticsDataClient betaAnalyticsDataClient = BetaAnalyticsDataClient.create()) {
CheckCompatibilityRequest request =
CheckCompatibilityRequest.newBuilder()
.setProperty("property-993141291")
.addAllDimensions(new ArrayList<Dimension>())
.addAllMetrics(new ArrayList<Metric>())
.setDimensionFilter(FilterExpression.newBuilder().build())
.setMetricFilter(FilterExpression.newBuilder().build())
.setCompatibilityFilter(Compatibility.forNumber(0))
.build();
ApiFuture<CheckCompatibilityResponse> future =
betaAnalyticsDataClient.checkCompatibilityCallable().futureCall(request);
// Do something.
CheckCompatibilityResponse response = future.get();
}
public final void close()
close in interface AutoCloseablepublic void shutdown()
shutdown in interface com.google.api.gax.core.BackgroundResourcepublic boolean isShutdown()
isShutdown in interface com.google.api.gax.core.BackgroundResourcepublic boolean isTerminated()
isTerminated in interface com.google.api.gax.core.BackgroundResourcepublic void shutdownNow()
shutdownNow in interface com.google.api.gax.core.BackgroundResourcepublic boolean awaitTermination(long duration,
TimeUnit unit)
throws InterruptedException
awaitTermination in interface com.google.api.gax.core.BackgroundResourceInterruptedExceptionCopyright © 2022 Google LLC. All rights reserved.