BetaAnalyticsDataClient

BetaAnalyticsDataClient

Google Analytics reporting data service.

Constructor

new BetaAnalyticsDataClient(optionsopt)

Construct an instance of BetaAnalyticsDataClient.

Parameters:
Name Type Attributes Description
options object <optional>

The configuration object. The options accepted by the constructor are described in detail in this document. The common options are:

Properties
Name Type Attributes Description
credentials object <optional>

Credentials object.

Properties
Name Type Attributes Description
client_email string <optional>
private_key string <optional>
email string <optional>

Account email address. Required when using a .pem or .p12 keyFilename.

keyFilename string <optional>

Full path to the a .json, .pem, or .p12 key downloaded from the Google Developers Console. If you provide a path to a JSON file, the projectId option below is not necessary. NOTE: .pem and .p12 require you to specify options.email as well.

port number <optional>

The port on which to connect to the remote host.

projectId string <optional>

The project ID from the Google Developer's Console, e.g. 'grape-spaceship-123'. We will also check the environment variable GCLOUD_PROJECT for your project ID. If your app is running in an environment which supports Application Default Credentials, your project ID will be detected automatically.

apiEndpoint string <optional>

The domain name of the API remote host.

clientConfig gax.ClientConfig <optional>

Client configuration override. Follows the structure of gapicConfig.

fallback boolean <optional>

Use HTTP fallback mode. In fallback mode, a special browser-compatible transport implementation is used instead of gRPC transport. In browser context (if the window object is defined) the fallback mode is enabled automatically; set options.fallback to false if you need to override this behavior.

Members

apiEndpoint

The DNS address for this API service - same as servicePath(), exists for compatibility reasons.

port

The port for this API service.

scopes

The scopes needed to make gRPC calls for every method defined in this service.

servicePath

The DNS address for this API service.

Methods

batchRunPivotReports(request, optionsopt) → {Promise}

Returns multiple pivot reports in a batch. All reports must be for the same GA4 Property.

Parameters:
Name Type Attributes Description
request Object

The request object that will be sent.

Properties
Name Type Description
property string

A Google Analytics GA4 property identifier whose events are tracked. Specified in the URL path and not the body. To learn more, see where to find your Property ID. This property must be specified for the batch. The property within RunPivotReportRequest may either be unspecified or consistent with this property.

Example: properties/1234

requests Array.<number>

Individual requests. Each request has a separate pivot report response. Each batch request is allowed up to 5 requests.

options object <optional>

Call options. See CallOptions for more details.

Returns:
Type Description
Promise
Example
const [response] = await client.batchRunPivotReports(request);

batchRunReports(request, optionsopt) → {Promise}

Returns multiple reports in a batch. All reports must be for the same GA4 Property.

Parameters:
Name Type Attributes Description
request Object

The request object that will be sent.

Properties
Name Type Description
property string

A Google Analytics GA4 property identifier whose events are tracked. Specified in the URL path and not the body. To learn more, see where to find your Property ID. This property must be specified for the batch. The property within RunReportRequest may either be unspecified or consistent with this property.

Example: properties/1234

requests Array.<number>

Individual requests. Each request has a separate report response. Each batch request is allowed up to 5 requests.

options object <optional>

Call options. See CallOptions for more details.

Returns:
Type Description
Promise
  • The promise which resolves to an array. The first element of the array is an object representing BatchRunReportsResponse. Please see the documentation for more details and examples.
Example
const [response] = await client.batchRunReports(request);

checkCompatibility(request, optionsopt) → {Promise}

This compatibility method lists dimensions and metrics that can be added to a report request and maintain compatibility. This method fails if the request's dimensions and metrics are incompatible.

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.

Parameters:
Name Type Attributes Description
request Object

The request object that will be sent.

Properties
Name Type Description
property string

A Google Analytics GA4 property identifier whose events are tracked. To learn more, see where to find your Property ID. property should be the same value as in your runReport request.

Example: properties/1234

Set the Property ID to 0 for compatibility checking on dimensions and metrics common to all properties. In this special mode, this method will not return custom dimensions and metrics.

dimensions Array.<number>

The dimensions in this report. dimensions should be the same value as in your runReport request.

metrics Array.<number>

The metrics in this report. metrics should be the same value as in your runReport request.

dimensionFilter google.analytics.data.v1beta.FilterExpression

The filter clause of dimensions. dimensionFilter should be the same value as in your runReport request.

metricFilter google.analytics.data.v1beta.FilterExpression

The filter clause of metrics. metricFilter should be the same value as in your runReport request

compatibilityFilter google.analytics.data.v1beta.Compatibility

Filters the dimensions and metrics in the response to just this compatibility. Commonly used as ”compatibilityFilter”: “COMPATIBLE” to only return compatible dimensions & metrics.

options object <optional>

Call options. See CallOptions for more details.

Returns:
Type Description
Promise
Example
const [response] = await client.checkCompatibility(request);

close() → {Promise}

Terminate the gRPC channel and close the client.

The client will no longer be usable and all future behavior is undefined.

Returns:
Type Description
Promise

A promise that resolves when the client is closed.

getMetadata(request, optionsopt) → {Promise}

Returns metadata for dimensions and metrics available in reporting methods. Used to explore the dimensions and metrics. In this method, a Google Analytics GA4 Property Identifier is specified in the request, and the metadata response includes Custom dimensions and metrics as well as Universal metadata.

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.

Parameters:
Name Type Attributes Description
request Object

The request object that will be sent.

Properties
Name Type Description
name string

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.

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.

options object <optional>

Call options. See CallOptions for more details.

Returns:
Type Description
Promise
  • The promise which resolves to an array. The first element of the array is an object representing Metadata. Please see the documentation for more details and examples.
Example
const [response] = await client.getMetadata(request);

getProjectId() → {Promise}

Return the project ID used by this class.

Returns:
Type Description
Promise

A promise that resolves to string containing the project ID.

initialize() → {Promise}

Initialize the client. Performs asynchronous operations (such as authentication) and prepares the client. This function will be called automatically when any class method is called for the first time, but if you need to initialize it before calling an actual method, feel free to call initialize() directly.

You can await on this method if you want to make sure the client is initialized.

Returns:
Type Description
Promise

A promise that resolves to an authenticated service stub.

matchPropertyFromMetadataName(metadataName) → {string}

Parse the property from Metadata resource.

Parameters:
Name Type Description
metadataName string

A fully-qualified path representing Metadata resource.

Returns:
Type Description
string

A string representing the property.

metadataPath(property) → {string}

Return a fully-qualified metadata resource name string.

Parameters:
Name Type Description
property string
Returns:
Type Description
string

Resource name string.

runPivotReport(request, optionsopt) → {Promise}

Returns a customized pivot report of your Google Analytics event data. Pivot reports are more advanced and expressive formats than regular reports. In a pivot report, dimensions are only visible if they are included in a pivot. Multiple pivots can be specified to further dissect your data.

Parameters:
Name Type Attributes Description
request Object

The request object that will be sent.

Properties
Name Type Description
property string

A Google Analytics GA4 property identifier whose events are tracked. Specified in the URL path and not the body. To learn more, see where to find your Property ID. Within a batch request, this property should either be unspecified or consistent with the batch-level property.

Example: properties/1234

dimensions Array.<number>

The dimensions requested. All defined dimensions must be used by one of the following: dimension_expression, dimension_filter, pivots, order_bys.

metrics Array.<number>

The metrics requested, at least one metric needs to be specified. All defined metrics must be used by one of the following: metric_expression, metric_filter, order_bys.

dateRanges Array.<number>

The date range to retrieve event data for the report. If multiple date ranges are specified, event data from each date range is used in the report. A special dimension with field name "dateRange" can be included in a Pivot's field names; if included, the report compares between date ranges. In a cohort request, this dateRanges must be unspecified.

pivots Array.<number>

Describes the visual format of the report's dimensions in columns or rows. The union of the fieldNames (dimension names) in all pivots must be a subset of dimension names defined in Dimensions. No two pivots can share a dimension. A dimension is only visible if it appears in a pivot.

dimensionFilter google.analytics.data.v1beta.FilterExpression

The filter clause of dimensions. Dimensions must be requested to be used in this filter. Metrics cannot be used in this filter.

metricFilter google.analytics.data.v1beta.FilterExpression

The filter clause of metrics. Applied at post aggregation phase, similar to SQL having-clause. Metrics must be requested to be used in this filter. Dimensions cannot be used in this filter.

currencyCode string

A currency code in ISO4217 format, such as "AED", "USD", "JPY". If the field is empty, the report uses the property's default currency.

cohortSpec google.analytics.data.v1beta.CohortSpec

Cohort group associated with this request. If there is a cohort group in the request the 'cohort' dimension must be present.

keepEmptyRows boolean

If false or unspecified, each row with all metrics equal to 0 will not be returned. If true, these rows will be returned if they are not separately removed by a filter.

returnPropertyQuota boolean

Toggles whether to return the current state of this Analytics Property's quota. Quota is returned in PropertyQuota.

options object <optional>

Call options. See CallOptions for more details.

Returns:
Type Description
Promise
  • The promise which resolves to an array. The first element of the array is an object representing RunPivotReportResponse. Please see the documentation for more details and examples.
Example
const [response] = await client.runPivotReport(request);

runRealtimeReport(request, optionsopt) → {Promise}

The Google Analytics Realtime API returns a customized report of realtime event data for your property. These reports show events and usage from the last 30 minutes.

Parameters:
Name Type Attributes Description
request Object

The request object that will be sent.

Properties
Name Type Description
property string

A Google Analytics GA4 property identifier whose events are tracked. Specified in the URL path and not the body. To learn more, see where to find your Property ID.

Example: properties/1234

dimensions Array.<number>

The dimensions requested and displayed.

metrics Array.<number>

The metrics requested and displayed.

dimensionFilter google.analytics.data.v1beta.FilterExpression

The filter clause of dimensions. Dimensions must be requested to be used in this filter. Metrics cannot be used in this filter.

metricFilter google.analytics.data.v1beta.FilterExpression

The filter clause of metrics. Applied at post aggregation phase, similar to SQL having-clause. Metrics must be requested to be used in this filter. Dimensions cannot be used in this filter.

limit number

The number of rows to return. If unspecified, 10,000 rows are returned. The API returns a maximum of 100,000 rows per request, no matter how many you ask for. limit must be positive.

The API can also return fewer rows than the requested limit, if there aren't as many dimension values as the limit. For instance, there are fewer than 300 possible values for the dimension country, so when reporting on only country, you can't get more than 300 rows, even if you set limit to a higher value.

metricAggregations Array.<number>

Aggregation of metrics. Aggregated metric values will be shown in rows where the dimension_values are set to "RESERVED_(MetricAggregation)".

orderBys Array.<number>

Specifies how rows are ordered in the response.

returnPropertyQuota boolean

Toggles whether to return the current state of this Analytics Property's Realtime quota. Quota is returned in PropertyQuota.

minuteRanges Array.<number>

The minute ranges of event data to read. If unspecified, one minute range for the last 30 minutes will be used. If multiple minute ranges are requested, each response row will contain a zero based minute range index. If two minute ranges overlap, the event data for the overlapping minutes is included in the response rows for both minute ranges.

options object <optional>

Call options. See CallOptions for more details.

Returns:
Type Description
Promise
Example
const [response] = await client.runRealtimeReport(request);

runReport(request, optionsopt) → {Promise}

Returns a customized report of your Google Analytics event data. Reports contain statistics derived from data collected by the Google Analytics tracking code. The data returned from the API is as a table with columns for the requested dimensions and metrics. Metrics are individual measurements of user activity on your property, such as active users or event count. Dimensions break down metrics across some common criteria, such as country or event name.

Parameters:
Name Type Attributes Description
request Object

The request object that will be sent.

Properties
Name Type Description
property string

A Google Analytics GA4 property identifier whose events are tracked. Specified in the URL path and not the body. To learn more, see where to find your Property ID. Within a batch request, this property should either be unspecified or consistent with the batch-level property.

Example: properties/1234

dimensions Array.<number>

The dimensions requested and displayed.

metrics Array.<number>

The metrics requested and displayed.

dateRanges Array.<number>

Date ranges of data to read. If multiple date ranges are requested, each response row will contain a zero based date range index. If two date ranges overlap, the event data for the overlapping days is included in the response rows for both date ranges. In a cohort request, this dateRanges must be unspecified.

dimensionFilter google.analytics.data.v1beta.FilterExpression

Dimension filters allow you to ask for only specific dimension values in the report. To learn more, see Fundamentals of Dimension Filters for examples. Metrics cannot be used in this filter.

metricFilter google.analytics.data.v1beta.FilterExpression

The filter clause of metrics. Applied at post aggregation phase, similar to SQL having-clause. Dimensions cannot be used in this filter.

offset number

The row count of the start row. The first row is counted as row 0.

When paging, the first request does not specify offset; or equivalently, sets offset to 0; the first request returns the first limit of rows. The second request sets offset to the limit of the first request; the second request returns the second limit of rows.

To learn more about this pagination parameter, see Pagination.

limit number

The number of rows to return. If unspecified, 10,000 rows are returned. The API returns a maximum of 100,000 rows per request, no matter how many you ask for. limit must be positive.

The API can also return fewer rows than the requested limit, if there aren't as many dimension values as the limit. For instance, there are fewer than 300 possible values for the dimension country, so when reporting on only country, you can't get more than 300 rows, even if you set limit to a higher value.

To learn more about this pagination parameter, see Pagination.

metricAggregations Array.<number>

Aggregation of metrics. Aggregated metric values will be shown in rows where the dimension_values are set to "RESERVED_(MetricAggregation)".

orderBys Array.<number>

Specifies how rows are ordered in the response.

currencyCode string

A currency code in ISO4217 format, such as "AED", "USD", "JPY". If the field is empty, the report uses the property's default currency.

cohortSpec google.analytics.data.v1beta.CohortSpec

Cohort group associated with this request. If there is a cohort group in the request the 'cohort' dimension must be present.

keepEmptyRows boolean

If false or unspecified, each row with all metrics equal to 0 will not be returned. If true, these rows will be returned if they are not separately removed by a filter.

returnPropertyQuota boolean

Toggles whether to return the current state of this Analytics Property's quota. Quota is returned in PropertyQuota.

options object <optional>

Call options. See CallOptions for more details.

Returns:
Type Description
Promise
  • The promise which resolves to an array. The first element of the array is an object representing RunReportResponse. Please see the documentation for more details and examples.
Example
const [response] = await client.runReport(request);