Class: Google::Analytics::Data::V1beta::AnalyticsData::Client

Inherits:
Object
  • Object
show all
Includes:
Paths
Defined in:
lib/google/analytics/data/v1beta/analytics_data/client.rb

Overview

Client for the AnalyticsData service.

Google Analytics reporting data service.

Defined Under Namespace

Classes: Configuration

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Paths

#audience_export_path, #metadata_path, #property_path

Constructor Details

#initialize {|config| ... } ⇒ Client

Create a new AnalyticsData client object.

Examples:


# Create a client using the default configuration
client = ::Google::Analytics::Data::V1beta::AnalyticsData::Client.new

# Create a client using a custom configuration
client = ::Google::Analytics::Data::V1beta::AnalyticsData::Client.new do |config|
  config.timeout = 10.0
end

Yields:

  • (config)

    Configure the AnalyticsData client.

Yield Parameters:



140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
# File 'lib/google/analytics/data/v1beta/analytics_data/client.rb', line 140

def initialize
  # These require statements are intentionally placed here to initialize
  # the gRPC module only when it's required.
  # See https://github.com/googleapis/toolkit/issues/446
  require "gapic/grpc"
  require "google/analytics/data/v1beta/analytics_data_api_services_pb"

  # Create the configuration object
  @config = Configuration.new Client.configure

  # Yield the configuration if needed
  yield @config if block_given?

  # Create credentials
  credentials = @config.credentials
  # Use self-signed JWT if the endpoint is unchanged from default,
  # but only if the default endpoint does not have a region prefix.
  enable_self_signed_jwt = @config.endpoint.nil? ||
                           (@config.endpoint == Configuration::DEFAULT_ENDPOINT &&
                           !@config.endpoint.split(".").first.include?("-"))
  credentials ||= Credentials.default scope: @config.scope,
                                      enable_self_signed_jwt: enable_self_signed_jwt
  if credentials.is_a?(::String) || credentials.is_a?(::Hash)
    credentials = Credentials.new credentials, scope: @config.scope
  end
  @quota_project_id = @config.quota_project
  @quota_project_id ||= credentials.quota_project_id if credentials.respond_to? :quota_project_id

  @operations_client = Operations.new do |config|
    config.credentials = credentials
    config.quota_project = @quota_project_id
    config.endpoint = @config.endpoint
    config.universe_domain = @config.universe_domain
  end

  @analytics_data_stub = ::Gapic::ServiceStub.new(
    ::Google::Analytics::Data::V1beta::BetaAnalyticsData::Stub,
    credentials: credentials,
    endpoint: @config.endpoint,
    endpoint_template: DEFAULT_ENDPOINT_TEMPLATE,
    universe_domain: @config.universe_domain,
    channel_args: @config.channel_args,
    interceptors: @config.interceptors,
    channel_pool_config: @config.channel_pool
  )
end

Instance Attribute Details

#operations_client::Google::Analytics::Data::V1beta::AnalyticsData::Operations (readonly)

Get the associated client for long-running operations.



192
193
194
# File 'lib/google/analytics/data/v1beta/analytics_data/client.rb', line 192

def operations_client
  @operations_client
end

Class Method Details

.configure {|config| ... } ⇒ Client::Configuration

Configure the AnalyticsData Client class.

See Configuration for a description of the configuration fields.

Examples:


# Modify the configuration for all AnalyticsData clients
::Google::Analytics::Data::V1beta::AnalyticsData::Client.configure do |config|
  config.timeout = 10.0
end

Yields:

  • (config)

    Configure the Client client.

Yield Parameters:

Returns:



59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
# File 'lib/google/analytics/data/v1beta/analytics_data/client.rb', line 59

def self.configure
  @configure ||= begin
    namespace = ["Google", "Analytics", "Data", "V1beta"]
    parent_config = while namespace.any?
                      parent_name = namespace.join "::"
                      parent_const = const_get parent_name
                      break parent_const.configure if parent_const.respond_to? :configure
                      namespace.pop
                    end
    default_config = Client::Configuration.new parent_config

    default_config.timeout = 60.0
    default_config.retry_policy = {
      initial_delay: 1.0, max_delay: 60.0, multiplier: 1.3, retry_codes: [2]
    }

    default_config.rpcs.run_report.timeout = 60.0

    default_config.rpcs.run_pivot_report.timeout = 60.0

    default_config.rpcs.batch_run_reports.timeout = 60.0

    default_config.rpcs.batch_run_pivot_reports.timeout = 60.0

    default_config.rpcs..timeout = 60.0

    default_config.rpcs.run_realtime_report.timeout = 60.0

    default_config.rpcs.check_compatibility.timeout = 60.0

    default_config
  end
  yield @configure if block_given?
  @configure
end

Instance Method Details

#batch_run_pivot_reports(request, options = nil) ⇒ ::Google::Analytics::Data::V1beta::BatchRunPivotReportsResponse #batch_run_pivot_reports(property: nil, requests: nil) ⇒ ::Google::Analytics::Data::V1beta::BatchRunPivotReportsResponse

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

Examples:

Basic example

require "google/analytics/data/v1beta"

# Create a client object. The client can be reused for multiple calls.
client = Google::Analytics::Data::V1beta::AnalyticsData::Client.new

# Create a request. To set request fields, pass in keyword arguments.
request = Google::Analytics::Data::V1beta::BatchRunPivotReportsRequest.new

# Call the batch_run_pivot_reports method.
result = client.batch_run_pivot_reports request

# The returned object is of type Google::Analytics::Data::V1beta::BatchRunPivotReportsResponse.
p result

Overloads:

  • #batch_run_pivot_reports(request, options = nil) ⇒ ::Google::Analytics::Data::V1beta::BatchRunPivotReportsResponse

    Pass arguments to batch_run_pivot_reports via a request object, either of type BatchRunPivotReportsRequest or an equivalent Hash.

    Parameters:

    • request (::Google::Analytics::Data::V1beta::BatchRunPivotReportsRequest, ::Hash)

      A request object representing the call parameters. Required. To specify no parameters, or to keep all the default parameter values, pass an empty Hash.

    • options (::Gapic::CallOptions, ::Hash) (defaults to: nil)

      Overrides the default settings for this call, e.g, timeout, retries, etc. Optional.

  • #batch_run_pivot_reports(property: nil, requests: nil) ⇒ ::Google::Analytics::Data::V1beta::BatchRunPivotReportsResponse

    Pass arguments to batch_run_pivot_reports via keyword arguments. Note that at least one keyword argument is required. To specify no parameters, or to keep all the default parameter values, pass an empty Hash as a request object (see above).

    Parameters:

    • property (::String) (defaults to: nil)

      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<::Google::Analytics::Data::V1beta::RunPivotReportRequest, ::Hash>) (defaults to: nil)

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

Yields:

  • (response, operation)

    Access the result along with the RPC operation

Yield Parameters:

Returns:

Raises:

  • (::Google::Cloud::Error)

    if the RPC is aborted.



658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
# File 'lib/google/analytics/data/v1beta/analytics_data/client.rb', line 658

def batch_run_pivot_reports request, options = nil
  raise ::ArgumentError, "request must be provided" if request.nil?

  request = ::Gapic::Protobuf.coerce request, to: ::Google::Analytics::Data::V1beta::BatchRunPivotReportsRequest

  # Converts hash and nil to an options object
  options = ::Gapic::CallOptions.new(**options.to_h) if options.respond_to? :to_h

  # Customize the options with defaults
   = @config.rpcs.batch_run_pivot_reports..to_h

  # Set x-goog-api-client and x-goog-user-project headers
  [:"x-goog-api-client"] ||= ::Gapic::Headers.x_goog_api_client \
    lib_name: @config.lib_name, lib_version: @config.lib_version,
    gapic_version: ::Google::Analytics::Data::V1beta::VERSION
  [:"x-goog-user-project"] = @quota_project_id if @quota_project_id

  header_params = {}
  if request.property
    header_params["property"] = request.property
  end

  request_params_header = header_params.map { |k, v| "#{k}=#{v}" }.join("&")
  [:"x-goog-request-params"] ||= request_params_header

  options.apply_defaults timeout:      @config.rpcs.batch_run_pivot_reports.timeout,
                         metadata:     ,
                         retry_policy: @config.rpcs.batch_run_pivot_reports.retry_policy

  options.apply_defaults timeout:      @config.timeout,
                         metadata:     @config.,
                         retry_policy: @config.retry_policy

  @analytics_data_stub.call_rpc :batch_run_pivot_reports, request, options: options do |response, operation|
    yield response, operation if block_given?
    return response
  end
rescue ::GRPC::BadStatus => e
  raise ::Google::Cloud::Error.from_error(e)
end

#batch_run_reports(request, options = nil) ⇒ ::Google::Analytics::Data::V1beta::BatchRunReportsResponse #batch_run_reports(property: nil, requests: nil) ⇒ ::Google::Analytics::Data::V1beta::BatchRunReportsResponse

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

Examples:

Basic example

require "google/analytics/data/v1beta"

# Create a client object. The client can be reused for multiple calls.
client = Google::Analytics::Data::V1beta::AnalyticsData::Client.new

# Create a request. To set request fields, pass in keyword arguments.
request = Google::Analytics::Data::V1beta::BatchRunReportsRequest.new

# Call the batch_run_reports method.
result = client.batch_run_reports request

# The returned object is of type Google::Analytics::Data::V1beta::BatchRunReportsResponse.
p result

Overloads:

  • #batch_run_reports(request, options = nil) ⇒ ::Google::Analytics::Data::V1beta::BatchRunReportsResponse

    Pass arguments to batch_run_reports via a request object, either of type BatchRunReportsRequest or an equivalent Hash.

    Parameters:

    • request (::Google::Analytics::Data::V1beta::BatchRunReportsRequest, ::Hash)

      A request object representing the call parameters. Required. To specify no parameters, or to keep all the default parameter values, pass an empty Hash.

    • options (::Gapic::CallOptions, ::Hash) (defaults to: nil)

      Overrides the default settings for this call, e.g, timeout, retries, etc. Optional.

  • #batch_run_reports(property: nil, requests: nil) ⇒ ::Google::Analytics::Data::V1beta::BatchRunReportsResponse

    Pass arguments to batch_run_reports via keyword arguments. Note that at least one keyword argument is required. To specify no parameters, or to keep all the default parameter values, pass an empty Hash as a request object (see above).

    Parameters:

    • property (::String) (defaults to: nil)

      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<::Google::Analytics::Data::V1beta::RunReportRequest, ::Hash>) (defaults to: nil)

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

Yields:

  • (response, operation)

    Access the result along with the RPC operation

Yield Parameters:

Returns:

Raises:

  • (::Google::Cloud::Error)

    if the RPC is aborted.



561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
# File 'lib/google/analytics/data/v1beta/analytics_data/client.rb', line 561

def batch_run_reports request, options = nil
  raise ::ArgumentError, "request must be provided" if request.nil?

  request = ::Gapic::Protobuf.coerce request, to: ::Google::Analytics::Data::V1beta::BatchRunReportsRequest

  # Converts hash and nil to an options object
  options = ::Gapic::CallOptions.new(**options.to_h) if options.respond_to? :to_h

  # Customize the options with defaults
   = @config.rpcs.batch_run_reports..to_h

  # Set x-goog-api-client and x-goog-user-project headers
  [:"x-goog-api-client"] ||= ::Gapic::Headers.x_goog_api_client \
    lib_name: @config.lib_name, lib_version: @config.lib_version,
    gapic_version: ::Google::Analytics::Data::V1beta::VERSION
  [:"x-goog-user-project"] = @quota_project_id if @quota_project_id

  header_params = {}
  if request.property
    header_params["property"] = request.property
  end

  request_params_header = header_params.map { |k, v| "#{k}=#{v}" }.join("&")
  [:"x-goog-request-params"] ||= request_params_header

  options.apply_defaults timeout:      @config.rpcs.batch_run_reports.timeout,
                         metadata:     ,
                         retry_policy: @config.rpcs.batch_run_reports.retry_policy

  options.apply_defaults timeout:      @config.timeout,
                         metadata:     @config.,
                         retry_policy: @config.retry_policy

  @analytics_data_stub.call_rpc :batch_run_reports, request, options: options do |response, operation|
    yield response, operation if block_given?
    return response
  end
rescue ::GRPC::BadStatus => e
  raise ::Google::Cloud::Error.from_error(e)
end

#check_compatibility(request, options = nil) ⇒ ::Google::Analytics::Data::V1beta::CheckCompatibilityResponse #check_compatibility(property: nil, dimensions: nil, metrics: nil, dimension_filter: nil, metric_filter: nil, compatibility_filter: nil) ⇒ ::Google::Analytics::Data::V1beta::CheckCompatibilityResponse

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.

Examples:

Basic example

require "google/analytics/data/v1beta"

# Create a client object. The client can be reused for multiple calls.
client = Google::Analytics::Data::V1beta::AnalyticsData::Client.new

# Create a request. To set request fields, pass in keyword arguments.
request = Google::Analytics::Data::V1beta::CheckCompatibilityRequest.new

# Call the check_compatibility method.
result = client.check_compatibility request

# The returned object is of type Google::Analytics::Data::V1beta::CheckCompatibilityResponse.
p result

Overloads:

  • #check_compatibility(request, options = nil) ⇒ ::Google::Analytics::Data::V1beta::CheckCompatibilityResponse

    Pass arguments to check_compatibility via a request object, either of type CheckCompatibilityRequest or an equivalent Hash.

    Parameters:

    • request (::Google::Analytics::Data::V1beta::CheckCompatibilityRequest, ::Hash)

      A request object representing the call parameters. Required. To specify no parameters, or to keep all the default parameter values, pass an empty Hash.

    • options (::Gapic::CallOptions, ::Hash) (defaults to: nil)

      Overrides the default settings for this call, e.g, timeout, retries, etc. Optional.

  • #check_compatibility(property: nil, dimensions: nil, metrics: nil, dimension_filter: nil, metric_filter: nil, compatibility_filter: nil) ⇒ ::Google::Analytics::Data::V1beta::CheckCompatibilityResponse

    Pass arguments to check_compatibility via keyword arguments. Note that at least one keyword argument is required. To specify no parameters, or to keep all the default parameter values, pass an empty Hash as a request object (see above).

    Parameters:

Yields:

  • (response, operation)

    Access the result along with the RPC operation

Yield Parameters:

Returns:

Raises:

  • (::Google::Cloud::Error)

    if the RPC is aborted.



1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
# File 'lib/google/analytics/data/v1beta/analytics_data/client.rb', line 1008

def check_compatibility request, options = nil
  raise ::ArgumentError, "request must be provided" if request.nil?

  request = ::Gapic::Protobuf.coerce request, to: ::Google::Analytics::Data::V1beta::CheckCompatibilityRequest

  # Converts hash and nil to an options object
  options = ::Gapic::CallOptions.new(**options.to_h) if options.respond_to? :to_h

  # Customize the options with defaults
   = @config.rpcs.check_compatibility..to_h

  # Set x-goog-api-client and x-goog-user-project headers
  [:"x-goog-api-client"] ||= ::Gapic::Headers.x_goog_api_client \
    lib_name: @config.lib_name, lib_version: @config.lib_version,
    gapic_version: ::Google::Analytics::Data::V1beta::VERSION
  [:"x-goog-user-project"] = @quota_project_id if @quota_project_id

  header_params = {}
  if request.property
    header_params["property"] = request.property
  end

  request_params_header = header_params.map { |k, v| "#{k}=#{v}" }.join("&")
  [:"x-goog-request-params"] ||= request_params_header

  options.apply_defaults timeout:      @config.rpcs.check_compatibility.timeout,
                         metadata:     ,
                         retry_policy: @config.rpcs.check_compatibility.retry_policy

  options.apply_defaults timeout:      @config.timeout,
                         metadata:     @config.,
                         retry_policy: @config.retry_policy

  @analytics_data_stub.call_rpc :check_compatibility, request, options: options do |response, operation|
    yield response, operation if block_given?
    return response
  end
rescue ::GRPC::BadStatus => e
  raise ::Google::Cloud::Error.from_error(e)
end

#configure {|config| ... } ⇒ Client::Configuration

Configure the AnalyticsData Client instance.

The configuration is set to the derived mode, meaning that values can be changed, but structural changes (adding new fields, etc.) are not allowed. Structural changes should be made on configure.

See Configuration for a description of the configuration fields.

Yields:

  • (config)

    Configure the Client client.

Yield Parameters:

Returns:



110
111
112
113
# File 'lib/google/analytics/data/v1beta/analytics_data/client.rb', line 110

def configure
  yield @config if block_given?
  @config
end

#create_audience_export(request, options = nil) ⇒ ::Gapic::Operation #create_audience_export(parent: nil, audience_export: nil) ⇒ ::Gapic::Operation

Creates an audience export for later retrieval. This method quickly returns the audience export's resource name and initiates a long running asynchronous request to form an audience export. To export the users in an audience export, first create the audience export through this method and then send the audience resource name to the QueryAudienceExport method.

See Creating an Audience Export for an introduction to Audience Exports with examples.

An audience export is a snapshot of the users currently in the audience at the time of audience export creation. Creating audience exports for one audience on different days will return different results as users enter and exit the audience.

Audiences in Google Analytics 4 allow you to segment your users in the ways that are important to your business. To learn more, see https://support.google.com/analytics/answer/9267572. Audience exports contain the users in each audience.

Audience Export APIs have some methods at alpha and other methods at beta stability. The intention is to advance methods to beta stability after some feedback and adoption. To give your feedback on this API, complete the Google Analytics Audience Export API Feedback form.

Examples:

Basic example

require "google/analytics/data/v1beta"

# Create a client object. The client can be reused for multiple calls.
client = Google::Analytics::Data::V1beta::AnalyticsData::Client.new

# Create a request. To set request fields, pass in keyword arguments.
request = Google::Analytics::Data::V1beta::CreateAudienceExportRequest.new

# Call the create_audience_export method.
result = client.create_audience_export request

# The returned object is of type Gapic::Operation. You can use it to
# check the status of an operation, cancel it, or wait for results.
# Here is how to wait for a response.
result.wait_until_done! timeout: 60
if result.response?
  p result.response
else
  puts "No response received."
end

Overloads:

  • #create_audience_export(request, options = nil) ⇒ ::Gapic::Operation

    Pass arguments to create_audience_export via a request object, either of type CreateAudienceExportRequest or an equivalent Hash.

    Parameters:

    • request (::Google::Analytics::Data::V1beta::CreateAudienceExportRequest, ::Hash)

      A request object representing the call parameters. Required. To specify no parameters, or to keep all the default parameter values, pass an empty Hash.

    • options (::Gapic::CallOptions, ::Hash) (defaults to: nil)

      Overrides the default settings for this call, e.g, timeout, retries, etc. Optional.

  • #create_audience_export(parent: nil, audience_export: nil) ⇒ ::Gapic::Operation

    Pass arguments to create_audience_export via keyword arguments. Note that at least one keyword argument is required. To specify no parameters, or to keep all the default parameter values, pass an empty Hash as a request object (see above).

    Parameters:

    • parent (::String) (defaults to: nil)

      Required. The parent resource where this audience export will be created. Format: properties/{property}

    • audience_export (::Google::Analytics::Data::V1beta::AudienceExport, ::Hash) (defaults to: nil)

      Required. The audience export to create.

Yields:

  • (response, operation)

    Access the result along with the RPC operation

Yield Parameters:

  • response (::Gapic::Operation)
  • operation (::GRPC::ActiveCall::Operation)

Returns:

  • (::Gapic::Operation)

Raises:

  • (::Google::Cloud::Error)

    if the RPC is aborted.



1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
# File 'lib/google/analytics/data/v1beta/analytics_data/client.rb', line 1127

def create_audience_export request, options = nil
  raise ::ArgumentError, "request must be provided" if request.nil?

  request = ::Gapic::Protobuf.coerce request, to: ::Google::Analytics::Data::V1beta::CreateAudienceExportRequest

  # Converts hash and nil to an options object
  options = ::Gapic::CallOptions.new(**options.to_h) if options.respond_to? :to_h

  # Customize the options with defaults
   = @config.rpcs.create_audience_export..to_h

  # Set x-goog-api-client and x-goog-user-project headers
  [:"x-goog-api-client"] ||= ::Gapic::Headers.x_goog_api_client \
    lib_name: @config.lib_name, lib_version: @config.lib_version,
    gapic_version: ::Google::Analytics::Data::V1beta::VERSION
  [:"x-goog-user-project"] = @quota_project_id if @quota_project_id

  header_params = {}
  if request.parent
    header_params["parent"] = request.parent
  end

  request_params_header = header_params.map { |k, v| "#{k}=#{v}" }.join("&")
  [:"x-goog-request-params"] ||= request_params_header

  options.apply_defaults timeout:      @config.rpcs.create_audience_export.timeout,
                         metadata:     ,
                         retry_policy: @config.rpcs.create_audience_export.retry_policy

  options.apply_defaults timeout:      @config.timeout,
                         metadata:     @config.,
                         retry_policy: @config.retry_policy

  @analytics_data_stub.call_rpc :create_audience_export, request, options: options do |response, operation|
    response = ::Gapic::Operation.new response, @operations_client, options: options
    yield response, operation if block_given?
    return response
  end
rescue ::GRPC::BadStatus => e
  raise ::Google::Cloud::Error.from_error(e)
end

#get_audience_export(request, options = nil) ⇒ ::Google::Analytics::Data::V1beta::AudienceExport #get_audience_export(name: nil) ⇒ ::Google::Analytics::Data::V1beta::AudienceExport

Gets configuration metadata about a specific audience export. This method can be used to understand an audience export after it has been created.

See Creating an Audience Export for an introduction to Audience Exports with examples.

Audience Export APIs have some methods at alpha and other methods at beta stability. The intention is to advance methods to beta stability after some feedback and adoption. To give your feedback on this API, complete the Google Analytics Audience Export API Feedback form.

Examples:

Basic example

require "google/analytics/data/v1beta"

# Create a client object. The client can be reused for multiple calls.
client = Google::Analytics::Data::V1beta::AnalyticsData::Client.new

# Create a request. To set request fields, pass in keyword arguments.
request = Google::Analytics::Data::V1beta::GetAudienceExportRequest.new

# Call the get_audience_export method.
result = client.get_audience_export request

# The returned object is of type Google::Analytics::Data::V1beta::AudienceExport.
p result

Overloads:

  • #get_audience_export(request, options = nil) ⇒ ::Google::Analytics::Data::V1beta::AudienceExport

    Pass arguments to get_audience_export via a request object, either of type GetAudienceExportRequest or an equivalent Hash.

    Parameters:

    • request (::Google::Analytics::Data::V1beta::GetAudienceExportRequest, ::Hash)

      A request object representing the call parameters. Required. To specify no parameters, or to keep all the default parameter values, pass an empty Hash.

    • options (::Gapic::CallOptions, ::Hash) (defaults to: nil)

      Overrides the default settings for this call, e.g, timeout, retries, etc. Optional.

  • #get_audience_export(name: nil) ⇒ ::Google::Analytics::Data::V1beta::AudienceExport

    Pass arguments to get_audience_export via keyword arguments. Note that at least one keyword argument is required. To specify no parameters, or to keep all the default parameter values, pass an empty Hash as a request object (see above).

    Parameters:

    • name (::String) (defaults to: nil)

      Required. The audience export resource name. Format: properties/{property}/audienceExports/{audience_export}

Yields:

  • (response, operation)

    Access the result along with the RPC operation

Yield Parameters:

Returns:

Raises:

  • (::Google::Cloud::Error)

    if the RPC is aborted.



1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
# File 'lib/google/analytics/data/v1beta/analytics_data/client.rb', line 1350

def get_audience_export request, options = nil
  raise ::ArgumentError, "request must be provided" if request.nil?

  request = ::Gapic::Protobuf.coerce request, to: ::Google::Analytics::Data::V1beta::GetAudienceExportRequest

  # Converts hash and nil to an options object
  options = ::Gapic::CallOptions.new(**options.to_h) if options.respond_to? :to_h

  # Customize the options with defaults
   = @config.rpcs.get_audience_export..to_h

  # Set x-goog-api-client and x-goog-user-project headers
  [:"x-goog-api-client"] ||= ::Gapic::Headers.x_goog_api_client \
    lib_name: @config.lib_name, lib_version: @config.lib_version,
    gapic_version: ::Google::Analytics::Data::V1beta::VERSION
  [:"x-goog-user-project"] = @quota_project_id if @quota_project_id

  header_params = {}
  if request.name
    header_params["name"] = request.name
  end

  request_params_header = header_params.map { |k, v| "#{k}=#{v}" }.join("&")
  [:"x-goog-request-params"] ||= request_params_header

  options.apply_defaults timeout:      @config.rpcs.get_audience_export.timeout,
                         metadata:     ,
                         retry_policy: @config.rpcs.get_audience_export.retry_policy

  options.apply_defaults timeout:      @config.timeout,
                         metadata:     @config.,
                         retry_policy: @config.retry_policy

  @analytics_data_stub.call_rpc :get_audience_export, request, options: options do |response, operation|
    yield response, operation if block_given?
    return response
  end
rescue ::GRPC::BadStatus => e
  raise ::Google::Cloud::Error.from_error(e)
end

#get_metadata(request, options = nil) ⇒ ::Google::Analytics::Data::V1beta::Metadata #get_metadata(name: nil) ⇒ ::Google::Analytics::Data::V1beta::Metadata

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.

Examples:

Basic example

require "google/analytics/data/v1beta"

# Create a client object. The client can be reused for multiple calls.
client = Google::Analytics::Data::V1beta::AnalyticsData::Client.new

# Create a request. To set request fields, pass in keyword arguments.
request = Google::Analytics::Data::V1beta::GetMetadataRequest.new

# Call the get_metadata method.
result = client. request

# The returned object is of type Google::Analytics::Data::V1beta::Metadata.
p result

Overloads:

  • #get_metadata(request, options = nil) ⇒ ::Google::Analytics::Data::V1beta::Metadata

    Pass arguments to get_metadata via a request object, either of type GetMetadataRequest or an equivalent Hash.

    Parameters:

    • request (::Google::Analytics::Data::V1beta::GetMetadataRequest, ::Hash)

      A request object representing the call parameters. Required. To specify no parameters, or to keep all the default parameter values, pass an empty Hash.

    • options (::Gapic::CallOptions, ::Hash) (defaults to: nil)

      Overrides the default settings for this call, e.g, timeout, retries, etc. Optional.

  • #get_metadata(name: nil) ⇒ ::Google::Analytics::Data::V1beta::Metadata

    Pass arguments to get_metadata via keyword arguments. Note that at least one keyword argument is required. To specify no parameters, or to keep all the default parameter values, pass an empty Hash as a request object (see above).

    Parameters:

    • name (::String) (defaults to: nil)

      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.

Yields:

  • (response, operation)

    Access the result along with the RPC operation

Yield Parameters:

Returns:

Raises:

  • (::Google::Cloud::Error)

    if the RPC is aborted.



762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
# File 'lib/google/analytics/data/v1beta/analytics_data/client.rb', line 762

def  request, options = nil
  raise ::ArgumentError, "request must be provided" if request.nil?

  request = ::Gapic::Protobuf.coerce request, to: ::Google::Analytics::Data::V1beta::GetMetadataRequest

  # Converts hash and nil to an options object
  options = ::Gapic::CallOptions.new(**options.to_h) if options.respond_to? :to_h

  # Customize the options with defaults
   = @config.rpcs...to_h

  # Set x-goog-api-client and x-goog-user-project headers
  [:"x-goog-api-client"] ||= ::Gapic::Headers.x_goog_api_client \
    lib_name: @config.lib_name, lib_version: @config.lib_version,
    gapic_version: ::Google::Analytics::Data::V1beta::VERSION
  [:"x-goog-user-project"] = @quota_project_id if @quota_project_id

  header_params = {}
  if request.name
    header_params["name"] = request.name
  end

  request_params_header = header_params.map { |k, v| "#{k}=#{v}" }.join("&")
  [:"x-goog-request-params"] ||= request_params_header

  options.apply_defaults timeout:      @config.rpcs..timeout,
                         metadata:     ,
                         retry_policy: @config.rpcs..retry_policy

  options.apply_defaults timeout:      @config.timeout,
                         metadata:     @config.,
                         retry_policy: @config.retry_policy

  @analytics_data_stub.call_rpc :get_metadata, request, options: options do |response, operation|
    yield response, operation if block_given?
    return response
  end
rescue ::GRPC::BadStatus => e
  raise ::Google::Cloud::Error.from_error(e)
end

#list_audience_exports(request, options = nil) ⇒ ::Gapic::PagedEnumerable<::Google::Analytics::Data::V1beta::AudienceExport> #list_audience_exports(parent: nil, page_size: nil, page_token: nil) ⇒ ::Gapic::PagedEnumerable<::Google::Analytics::Data::V1beta::AudienceExport>

Lists all audience exports for a property. This method can be used for you to find and reuse existing audience exports rather than creating unnecessary new audience exports. The same audience can have multiple audience exports that represent the export of users that were in an audience on different days.

See Creating an Audience Export for an introduction to Audience Exports with examples.

Audience Export APIs have some methods at alpha and other methods at beta stability. The intention is to advance methods to beta stability after some feedback and adoption. To give your feedback on this API, complete the Google Analytics Audience Export API Feedback form.

Examples:

Basic example

require "google/analytics/data/v1beta"

# Create a client object. The client can be reused for multiple calls.
client = Google::Analytics::Data::V1beta::AnalyticsData::Client.new

# Create a request. To set request fields, pass in keyword arguments.
request = Google::Analytics::Data::V1beta::ListAudienceExportsRequest.new

# Call the list_audience_exports method.
result = client.list_audience_exports request

# The returned object is of type Gapic::PagedEnumerable. You can iterate
# over elements, and API calls will be issued to fetch pages as needed.
result.each do |item|
  # Each element is of type ::Google::Analytics::Data::V1beta::AudienceExport.
  p item
end

Overloads:

  • #list_audience_exports(request, options = nil) ⇒ ::Gapic::PagedEnumerable<::Google::Analytics::Data::V1beta::AudienceExport>

    Pass arguments to list_audience_exports via a request object, either of type ListAudienceExportsRequest or an equivalent Hash.

    Parameters:

    • request (::Google::Analytics::Data::V1beta::ListAudienceExportsRequest, ::Hash)

      A request object representing the call parameters. Required. To specify no parameters, or to keep all the default parameter values, pass an empty Hash.

    • options (::Gapic::CallOptions, ::Hash) (defaults to: nil)

      Overrides the default settings for this call, e.g, timeout, retries, etc. Optional.

  • #list_audience_exports(parent: nil, page_size: nil, page_token: nil) ⇒ ::Gapic::PagedEnumerable<::Google::Analytics::Data::V1beta::AudienceExport>

    Pass arguments to list_audience_exports via keyword arguments. Note that at least one keyword argument is required. To specify no parameters, or to keep all the default parameter values, pass an empty Hash as a request object (see above).

    Parameters:

    • parent (::String) (defaults to: nil)

      Required. All audience exports for this property will be listed in the response. Format: properties/{property}

    • page_size (::Integer) (defaults to: nil)

      Optional. The maximum number of audience exports to return. The service may return fewer than this value. If unspecified, at most 200 audience exports will be returned. The maximum value is 1000 (higher values will be coerced to the maximum).

    • page_token (::String) (defaults to: nil)

      Optional. A page token, received from a previous ListAudienceExports call. Provide this to retrieve the subsequent page.

      When paginating, all other parameters provided to ListAudienceExports must match the call that provided the page token.

Yields:

  • (response, operation)

    Access the result along with the RPC operation

Yield Parameters:

Returns:

Raises:

  • (::Google::Cloud::Error)

    if the RPC is aborted.



1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
# File 'lib/google/analytics/data/v1beta/analytics_data/client.rb', line 1465

def list_audience_exports request, options = nil
  raise ::ArgumentError, "request must be provided" if request.nil?

  request = ::Gapic::Protobuf.coerce request, to: ::Google::Analytics::Data::V1beta::ListAudienceExportsRequest

  # Converts hash and nil to an options object
  options = ::Gapic::CallOptions.new(**options.to_h) if options.respond_to? :to_h

  # Customize the options with defaults
   = @config.rpcs.list_audience_exports..to_h

  # Set x-goog-api-client and x-goog-user-project headers
  [:"x-goog-api-client"] ||= ::Gapic::Headers.x_goog_api_client \
    lib_name: @config.lib_name, lib_version: @config.lib_version,
    gapic_version: ::Google::Analytics::Data::V1beta::VERSION
  [:"x-goog-user-project"] = @quota_project_id if @quota_project_id

  header_params = {}
  if request.parent
    header_params["parent"] = request.parent
  end

  request_params_header = header_params.map { |k, v| "#{k}=#{v}" }.join("&")
  [:"x-goog-request-params"] ||= request_params_header

  options.apply_defaults timeout:      @config.rpcs.list_audience_exports.timeout,
                         metadata:     ,
                         retry_policy: @config.rpcs.list_audience_exports.retry_policy

  options.apply_defaults timeout:      @config.timeout,
                         metadata:     @config.,
                         retry_policy: @config.retry_policy

  @analytics_data_stub.call_rpc :list_audience_exports, request, options: options do |response, operation|
    response = ::Gapic::PagedEnumerable.new @analytics_data_stub, :list_audience_exports, request, response, operation, options
    yield response, operation if block_given?
    return response
  end
rescue ::GRPC::BadStatus => e
  raise ::Google::Cloud::Error.from_error(e)
end

#query_audience_export(request, options = nil) ⇒ ::Google::Analytics::Data::V1beta::QueryAudienceExportResponse #query_audience_export(name: nil, offset: nil, limit: nil) ⇒ ::Google::Analytics::Data::V1beta::QueryAudienceExportResponse

Retrieves an audience export of users. After creating an audience, the users are not immediately available for exporting. First, a request to CreateAudienceExport is necessary to create an audience export of users, and then second, this method is used to retrieve the users in the audience export.

See Creating an Audience Export for an introduction to Audience Exports with examples.

Audiences in Google Analytics 4 allow you to segment your users in the ways that are important to your business. To learn more, see https://support.google.com/analytics/answer/9267572.

Audience Export APIs have some methods at alpha and other methods at beta stability. The intention is to advance methods to beta stability after some feedback and adoption. To give your feedback on this API, complete the Google Analytics Audience Export API Feedback form.

Examples:

Basic example

require "google/analytics/data/v1beta"

# Create a client object. The client can be reused for multiple calls.
client = Google::Analytics::Data::V1beta::AnalyticsData::Client.new

# Create a request. To set request fields, pass in keyword arguments.
request = Google::Analytics::Data::V1beta::QueryAudienceExportRequest.new

# Call the query_audience_export method.
result = client.query_audience_export request

# The returned object is of type Google::Analytics::Data::V1beta::QueryAudienceExportResponse.
p result

Overloads:

  • #query_audience_export(request, options = nil) ⇒ ::Google::Analytics::Data::V1beta::QueryAudienceExportResponse

    Pass arguments to query_audience_export via a request object, either of type QueryAudienceExportRequest or an equivalent Hash.

    Parameters:

    • request (::Google::Analytics::Data::V1beta::QueryAudienceExportRequest, ::Hash)

      A request object representing the call parameters. Required. To specify no parameters, or to keep all the default parameter values, pass an empty Hash.

    • options (::Gapic::CallOptions, ::Hash) (defaults to: nil)

      Overrides the default settings for this call, e.g, timeout, retries, etc. Optional.

  • #query_audience_export(name: nil, offset: nil, limit: nil) ⇒ ::Google::Analytics::Data::V1beta::QueryAudienceExportResponse

    Pass arguments to query_audience_export via keyword arguments. Note that at least one keyword argument is required. To specify no parameters, or to keep all the default parameter values, pass an empty Hash as a request object (see above).

    Parameters:

    • name (::String) (defaults to: nil)

      Required. The name of the audience export to retrieve users from. Format: properties/{property}/audienceExports/{audience_export}

    • offset (::Integer) (defaults to: nil)

      Optional. 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 (::Integer) (defaults to: nil)

      Optional. The number of rows to return. If unspecified, 10,000 rows are returned. The API returns a maximum of 250,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.

      To learn more about this pagination parameter, see Pagination.

Yields:

  • (response, operation)

    Access the result along with the RPC operation

Yield Parameters:

Returns:

Raises:

  • (::Google::Cloud::Error)

    if the RPC is aborted.



1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
# File 'lib/google/analytics/data/v1beta/analytics_data/client.rb', line 1253

def query_audience_export request, options = nil
  raise ::ArgumentError, "request must be provided" if request.nil?

  request = ::Gapic::Protobuf.coerce request, to: ::Google::Analytics::Data::V1beta::QueryAudienceExportRequest

  # Converts hash and nil to an options object
  options = ::Gapic::CallOptions.new(**options.to_h) if options.respond_to? :to_h

  # Customize the options with defaults
   = @config.rpcs.query_audience_export..to_h

  # Set x-goog-api-client and x-goog-user-project headers
  [:"x-goog-api-client"] ||= ::Gapic::Headers.x_goog_api_client \
    lib_name: @config.lib_name, lib_version: @config.lib_version,
    gapic_version: ::Google::Analytics::Data::V1beta::VERSION
  [:"x-goog-user-project"] = @quota_project_id if @quota_project_id

  header_params = {}
  if request.name
    header_params["name"] = request.name
  end

  request_params_header = header_params.map { |k, v| "#{k}=#{v}" }.join("&")
  [:"x-goog-request-params"] ||= request_params_header

  options.apply_defaults timeout:      @config.rpcs.query_audience_export.timeout,
                         metadata:     ,
                         retry_policy: @config.rpcs.query_audience_export.retry_policy

  options.apply_defaults timeout:      @config.timeout,
                         metadata:     @config.,
                         retry_policy: @config.retry_policy

  @analytics_data_stub.call_rpc :query_audience_export, request, options: options do |response, operation|
    yield response, operation if block_given?
    return response
  end
rescue ::GRPC::BadStatus => e
  raise ::Google::Cloud::Error.from_error(e)
end

#run_pivot_report(request, options = nil) ⇒ ::Google::Analytics::Data::V1beta::RunPivotReportResponse #run_pivot_report(property: nil, dimensions: nil, metrics: nil, date_ranges: nil, pivots: nil, dimension_filter: nil, metric_filter: nil, currency_code: nil, cohort_spec: nil, keep_empty_rows: nil, return_property_quota: nil) ⇒ ::Google::Analytics::Data::V1beta::RunPivotReportResponse

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.

Examples:

Basic example

require "google/analytics/data/v1beta"

# Create a client object. The client can be reused for multiple calls.
client = Google::Analytics::Data::V1beta::AnalyticsData::Client.new

# Create a request. To set request fields, pass in keyword arguments.
request = Google::Analytics::Data::V1beta::RunPivotReportRequest.new

# Call the run_pivot_report method.
result = client.run_pivot_report request

# The returned object is of type Google::Analytics::Data::V1beta::RunPivotReportResponse.
p result

Overloads:

  • #run_pivot_report(request, options = nil) ⇒ ::Google::Analytics::Data::V1beta::RunPivotReportResponse

    Pass arguments to run_pivot_report via a request object, either of type RunPivotReportRequest or an equivalent Hash.

    Parameters:

    • request (::Google::Analytics::Data::V1beta::RunPivotReportRequest, ::Hash)

      A request object representing the call parameters. Required. To specify no parameters, or to keep all the default parameter values, pass an empty Hash.

    • options (::Gapic::CallOptions, ::Hash) (defaults to: nil)

      Overrides the default settings for this call, e.g, timeout, retries, etc. Optional.

  • #run_pivot_report(property: nil, dimensions: nil, metrics: nil, date_ranges: nil, pivots: nil, dimension_filter: nil, metric_filter: nil, currency_code: nil, cohort_spec: nil, keep_empty_rows: nil, return_property_quota: nil) ⇒ ::Google::Analytics::Data::V1beta::RunPivotReportResponse

    Pass arguments to run_pivot_report via keyword arguments. Note that at least one keyword argument is required. To specify no parameters, or to keep all the default parameter values, pass an empty Hash as a request object (see above).

    Parameters:

    • property (::String) (defaults to: nil)

      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<::Google::Analytics::Data::V1beta::Dimension, ::Hash>) (defaults to: nil)

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

    • metrics (::Array<::Google::Analytics::Data::V1beta::Metric, ::Hash>) (defaults to: nil)

      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.

    • date_ranges (::Array<::Google::Analytics::Data::V1beta::DateRange, ::Hash>) (defaults to: nil)

      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<::Google::Analytics::Data::V1beta::Pivot, ::Hash>) (defaults to: nil)

      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.

    • dimension_filter (::Google::Analytics::Data::V1beta::FilterExpression, ::Hash) (defaults to: nil)

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

    • metric_filter (::Google::Analytics::Data::V1beta::FilterExpression, ::Hash) (defaults to: nil)

      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.

    • currency_code (::String) (defaults to: nil)

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

    • cohort_spec (::Google::Analytics::Data::V1beta::CohortSpec, ::Hash) (defaults to: nil)

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

    • keep_empty_rows (::Boolean) (defaults to: nil)

      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.

      Regardless of this keep_empty_rows setting, only data recorded by the Google Analytics (GA4) property can be displayed in a report.

      For example if a property never logs a purchase event, then a query for the eventName dimension and eventCount metric will not have a row eventName: "purchase" and eventCount: 0.

    • return_property_quota (::Boolean) (defaults to: nil)

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

Yields:

  • (response, operation)

    Access the result along with the RPC operation

Yield Parameters:

Returns:

Raises:

  • (::Google::Cloud::Error)

    if the RPC is aborted.



464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
# File 'lib/google/analytics/data/v1beta/analytics_data/client.rb', line 464

def run_pivot_report request, options = nil
  raise ::ArgumentError, "request must be provided" if request.nil?

  request = ::Gapic::Protobuf.coerce request, to: ::Google::Analytics::Data::V1beta::RunPivotReportRequest

  # Converts hash and nil to an options object
  options = ::Gapic::CallOptions.new(**options.to_h) if options.respond_to? :to_h

  # Customize the options with defaults
   = @config.rpcs.run_pivot_report..to_h

  # Set x-goog-api-client and x-goog-user-project headers
  [:"x-goog-api-client"] ||= ::Gapic::Headers.x_goog_api_client \
    lib_name: @config.lib_name, lib_version: @config.lib_version,
    gapic_version: ::Google::Analytics::Data::V1beta::VERSION
  [:"x-goog-user-project"] = @quota_project_id if @quota_project_id

  header_params = {}
  if request.property
    header_params["property"] = request.property
  end

  request_params_header = header_params.map { |k, v| "#{k}=#{v}" }.join("&")
  [:"x-goog-request-params"] ||= request_params_header

  options.apply_defaults timeout:      @config.rpcs.run_pivot_report.timeout,
                         metadata:     ,
                         retry_policy: @config.rpcs.run_pivot_report.retry_policy

  options.apply_defaults timeout:      @config.timeout,
                         metadata:     @config.,
                         retry_policy: @config.retry_policy

  @analytics_data_stub.call_rpc :run_pivot_report, request, options: options do |response, operation|
    yield response, operation if block_given?
    return response
  end
rescue ::GRPC::BadStatus => e
  raise ::Google::Cloud::Error.from_error(e)
end

#run_realtime_report(request, options = nil) ⇒ ::Google::Analytics::Data::V1beta::RunRealtimeReportResponse #run_realtime_report(property: nil, dimensions: nil, metrics: nil, dimension_filter: nil, metric_filter: nil, limit: nil, metric_aggregations: nil, order_bys: nil, return_property_quota: nil, minute_ranges: nil) ⇒ ::Google::Analytics::Data::V1beta::RunRealtimeReportResponse

Returns a customized report of realtime event data for your property. Events appear in realtime reports seconds after they have been sent to the Google Analytics. Realtime reports show events and usage data for the periods of time ranging from the present moment to 30 minutes ago (up to 60 minutes for Google Analytics 360 properties).

For a guide to constructing realtime requests & understanding responses, see Creating a Realtime Report.

Examples:

Basic example

require "google/analytics/data/v1beta"

# Create a client object. The client can be reused for multiple calls.
client = Google::Analytics::Data::V1beta::AnalyticsData::Client.new

# Create a request. To set request fields, pass in keyword arguments.
request = Google::Analytics::Data::V1beta::RunRealtimeReportRequest.new

# Call the run_realtime_report method.
result = client.run_realtime_report request

# The returned object is of type Google::Analytics::Data::V1beta::RunRealtimeReportResponse.
p result

Overloads:

  • #run_realtime_report(request, options = nil) ⇒ ::Google::Analytics::Data::V1beta::RunRealtimeReportResponse

    Pass arguments to run_realtime_report via a request object, either of type RunRealtimeReportRequest or an equivalent Hash.

    Parameters:

    • request (::Google::Analytics::Data::V1beta::RunRealtimeReportRequest, ::Hash)

      A request object representing the call parameters. Required. To specify no parameters, or to keep all the default parameter values, pass an empty Hash.

    • options (::Gapic::CallOptions, ::Hash) (defaults to: nil)

      Overrides the default settings for this call, e.g, timeout, retries, etc. Optional.

  • #run_realtime_report(property: nil, dimensions: nil, metrics: nil, dimension_filter: nil, metric_filter: nil, limit: nil, metric_aggregations: nil, order_bys: nil, return_property_quota: nil, minute_ranges: nil) ⇒ ::Google::Analytics::Data::V1beta::RunRealtimeReportResponse

    Pass arguments to run_realtime_report via keyword arguments. Note that at least one keyword argument is required. To specify no parameters, or to keep all the default parameter values, pass an empty Hash as a request object (see above).

    Parameters:

    • property (::String) (defaults to: nil)

      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<::Google::Analytics::Data::V1beta::Dimension, ::Hash>) (defaults to: nil)

      The dimensions requested and displayed.

    • metrics (::Array<::Google::Analytics::Data::V1beta::Metric, ::Hash>) (defaults to: nil)

      The metrics requested and displayed.

    • dimension_filter (::Google::Analytics::Data::V1beta::FilterExpression, ::Hash) (defaults to: nil)

      The filter clause of dimensions. Metrics cannot be used in this filter.

    • metric_filter (::Google::Analytics::Data::V1beta::FilterExpression, ::Hash) (defaults to: nil)

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

    • limit (::Integer) (defaults to: nil)

      The number of rows to return. If unspecified, 10,000 rows are returned. The API returns a maximum of 250,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.

    • metric_aggregations (::Array<::Google::Analytics::Data::V1beta::MetricAggregation>) (defaults to: nil)

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

    • order_bys (::Array<::Google::Analytics::Data::V1beta::OrderBy, ::Hash>) (defaults to: nil)

      Specifies how rows are ordered in the response.

    • return_property_quota (::Boolean) (defaults to: nil)

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

    • minute_ranges (::Array<::Google::Analytics::Data::V1beta::MinuteRange, ::Hash>) (defaults to: nil)

      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.

Yields:

  • (response, operation)

    Access the result along with the RPC operation

Yield Parameters:

Returns:

Raises:

  • (::Google::Cloud::Error)

    if the RPC is aborted.



893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
# File 'lib/google/analytics/data/v1beta/analytics_data/client.rb', line 893

def run_realtime_report request, options = nil
  raise ::ArgumentError, "request must be provided" if request.nil?

  request = ::Gapic::Protobuf.coerce request, to: ::Google::Analytics::Data::V1beta::RunRealtimeReportRequest

  # Converts hash and nil to an options object
  options = ::Gapic::CallOptions.new(**options.to_h) if options.respond_to? :to_h

  # Customize the options with defaults
   = @config.rpcs.run_realtime_report..to_h

  # Set x-goog-api-client and x-goog-user-project headers
  [:"x-goog-api-client"] ||= ::Gapic::Headers.x_goog_api_client \
    lib_name: @config.lib_name, lib_version: @config.lib_version,
    gapic_version: ::Google::Analytics::Data::V1beta::VERSION
  [:"x-goog-user-project"] = @quota_project_id if @quota_project_id

  header_params = {}
  if request.property
    header_params["property"] = request.property
  end

  request_params_header = header_params.map { |k, v| "#{k}=#{v}" }.join("&")
  [:"x-goog-request-params"] ||= request_params_header

  options.apply_defaults timeout:      @config.rpcs.run_realtime_report.timeout,
                         metadata:     ,
                         retry_policy: @config.rpcs.run_realtime_report.retry_policy

  options.apply_defaults timeout:      @config.timeout,
                         metadata:     @config.,
                         retry_policy: @config.retry_policy

  @analytics_data_stub.call_rpc :run_realtime_report, request, options: options do |response, operation|
    yield response, operation if block_given?
    return response
  end
rescue ::GRPC::BadStatus => e
  raise ::Google::Cloud::Error.from_error(e)
end

#run_report(request, options = nil) ⇒ ::Google::Analytics::Data::V1beta::RunReportResponse #run_report(property: nil, dimensions: nil, metrics: nil, date_ranges: nil, dimension_filter: nil, metric_filter: nil, offset: nil, limit: nil, metric_aggregations: nil, order_bys: nil, currency_code: nil, cohort_spec: nil, keep_empty_rows: nil, return_property_quota: nil) ⇒ ::Google::Analytics::Data::V1beta::RunReportResponse

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.

For a guide to constructing requests & understanding responses, see Creating a Report.

Examples:

Basic example

require "google/analytics/data/v1beta"

# Create a client object. The client can be reused for multiple calls.
client = Google::Analytics::Data::V1beta::AnalyticsData::Client.new

# Create a request. To set request fields, pass in keyword arguments.
request = Google::Analytics::Data::V1beta::RunReportRequest.new

# Call the run_report method.
result = client.run_report request

# The returned object is of type Google::Analytics::Data::V1beta::RunReportResponse.
p result

Overloads:

  • #run_report(request, options = nil) ⇒ ::Google::Analytics::Data::V1beta::RunReportResponse

    Pass arguments to run_report via a request object, either of type RunReportRequest or an equivalent Hash.

    Parameters:

    • request (::Google::Analytics::Data::V1beta::RunReportRequest, ::Hash)

      A request object representing the call parameters. Required. To specify no parameters, or to keep all the default parameter values, pass an empty Hash.

    • options (::Gapic::CallOptions, ::Hash) (defaults to: nil)

      Overrides the default settings for this call, e.g, timeout, retries, etc. Optional.

  • #run_report(property: nil, dimensions: nil, metrics: nil, date_ranges: nil, dimension_filter: nil, metric_filter: nil, offset: nil, limit: nil, metric_aggregations: nil, order_bys: nil, currency_code: nil, cohort_spec: nil, keep_empty_rows: nil, return_property_quota: nil) ⇒ ::Google::Analytics::Data::V1beta::RunReportResponse

    Pass arguments to run_report via keyword arguments. Note that at least one keyword argument is required. To specify no parameters, or to keep all the default parameter values, pass an empty Hash as a request object (see above).

    Parameters:

    • property (::String) (defaults to: nil)

      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<::Google::Analytics::Data::V1beta::Dimension, ::Hash>) (defaults to: nil)

      The dimensions requested and displayed.

    • metrics (::Array<::Google::Analytics::Data::V1beta::Metric, ::Hash>) (defaults to: nil)

      The metrics requested and displayed.

    • date_ranges (::Array<::Google::Analytics::Data::V1beta::DateRange, ::Hash>) (defaults to: nil)

      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.

    • dimension_filter (::Google::Analytics::Data::V1beta::FilterExpression, ::Hash) (defaults to: nil)

      Dimension filters let you 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.

    • metric_filter (::Google::Analytics::Data::V1beta::FilterExpression, ::Hash) (defaults to: nil)

      The filter clause of metrics. Applied after aggregating the report's rows, similar to SQL having-clause. Dimensions cannot be used in this filter.

    • offset (::Integer) (defaults to: nil)

      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 (::Integer) (defaults to: nil)

      The number of rows to return. If unspecified, 10,000 rows are returned. The API returns a maximum of 250,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.

    • metric_aggregations (::Array<::Google::Analytics::Data::V1beta::MetricAggregation>) (defaults to: nil)

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

    • order_bys (::Array<::Google::Analytics::Data::V1beta::OrderBy, ::Hash>) (defaults to: nil)

      Specifies how rows are ordered in the response.

    • currency_code (::String) (defaults to: nil)

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

    • cohort_spec (::Google::Analytics::Data::V1beta::CohortSpec, ::Hash) (defaults to: nil)

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

    • keep_empty_rows (::Boolean) (defaults to: nil)

      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.

      Regardless of this keep_empty_rows setting, only data recorded by the Google Analytics (GA4) property can be displayed in a report.

      For example if a property never logs a purchase event, then a query for the eventName dimension and eventCount metric will not have a row eventName: "purchase" and eventCount: 0.

    • return_property_quota (::Boolean) (defaults to: nil)

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

Yields:

  • (response, operation)

    Access the result along with the RPC operation

Yield Parameters:

Returns:

Raises:

  • (::Google::Cloud::Error)

    if the RPC is aborted.



323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
# File 'lib/google/analytics/data/v1beta/analytics_data/client.rb', line 323

def run_report request, options = nil
  raise ::ArgumentError, "request must be provided" if request.nil?

  request = ::Gapic::Protobuf.coerce request, to: ::Google::Analytics::Data::V1beta::RunReportRequest

  # Converts hash and nil to an options object
  options = ::Gapic::CallOptions.new(**options.to_h) if options.respond_to? :to_h

  # Customize the options with defaults
   = @config.rpcs.run_report..to_h

  # Set x-goog-api-client and x-goog-user-project headers
  [:"x-goog-api-client"] ||= ::Gapic::Headers.x_goog_api_client \
    lib_name: @config.lib_name, lib_version: @config.lib_version,
    gapic_version: ::Google::Analytics::Data::V1beta::VERSION
  [:"x-goog-user-project"] = @quota_project_id if @quota_project_id

  header_params = {}
  if request.property
    header_params["property"] = request.property
  end

  request_params_header = header_params.map { |k, v| "#{k}=#{v}" }.join("&")
  [:"x-goog-request-params"] ||= request_params_header

  options.apply_defaults timeout:      @config.rpcs.run_report.timeout,
                         metadata:     ,
                         retry_policy: @config.rpcs.run_report.retry_policy

  options.apply_defaults timeout:      @config.timeout,
                         metadata:     @config.,
                         retry_policy: @config.retry_policy

  @analytics_data_stub.call_rpc :run_report, request, options: options do |response, operation|
    yield response, operation if block_given?
    return response
  end
rescue ::GRPC::BadStatus => e
  raise ::Google::Cloud::Error.from_error(e)
end

#universe_domainString

The effective universe domain

Returns:

  • (String)


120
121
122
# File 'lib/google/analytics/data/v1beta/analytics_data/client.rb', line 120

def universe_domain
  @analytics_data_stub.universe_domain
end