/
BetaAnalyticsDataGapicClient.php
1569 lines (1475 loc) · 65.3 KB
/
BetaAnalyticsDataGapicClient.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
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
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
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
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
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
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
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
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
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
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
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
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
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
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<?php
/*
* Copyright 2021 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/*
* GENERATED CODE WARNING
* Generated by gapic-generator-php from the file
* https://github.com/googleapis/googleapis/blob/master/google/analytics/data/v1beta/analytics_data_api.proto
* Updates to the above are reflected here through a refresh process.
*
* @experimental
*/
namespace Google\Analytics\Data\V1beta\Gapic;
use Google\Analytics\Data\V1beta\AudienceExport;
use Google\Analytics\Data\V1beta\BatchRunPivotReportsRequest;
use Google\Analytics\Data\V1beta\BatchRunPivotReportsResponse;
use Google\Analytics\Data\V1beta\BatchRunReportsRequest;
use Google\Analytics\Data\V1beta\BatchRunReportsResponse;
use Google\Analytics\Data\V1beta\CheckCompatibilityRequest;
use Google\Analytics\Data\V1beta\CheckCompatibilityResponse;
use Google\Analytics\Data\V1beta\CohortSpec;
use Google\Analytics\Data\V1beta\Compatibility;
use Google\Analytics\Data\V1beta\CreateAudienceExportRequest;
use Google\Analytics\Data\V1beta\DateRange;
use Google\Analytics\Data\V1beta\Dimension;
use Google\Analytics\Data\V1beta\FilterExpression;
use Google\Analytics\Data\V1beta\GetAudienceExportRequest;
use Google\Analytics\Data\V1beta\GetMetadataRequest;
use Google\Analytics\Data\V1beta\ListAudienceExportsRequest;
use Google\Analytics\Data\V1beta\ListAudienceExportsResponse;
use Google\Analytics\Data\V1beta\Metadata;
use Google\Analytics\Data\V1beta\Metric;
use Google\Analytics\Data\V1beta\MetricAggregation;
use Google\Analytics\Data\V1beta\MinuteRange;
use Google\Analytics\Data\V1beta\OrderBy;
use Google\Analytics\Data\V1beta\Pivot;
use Google\Analytics\Data\V1beta\QueryAudienceExportRequest;
use Google\Analytics\Data\V1beta\QueryAudienceExportResponse;
use Google\Analytics\Data\V1beta\RunPivotReportRequest;
use Google\Analytics\Data\V1beta\RunPivotReportResponse;
use Google\Analytics\Data\V1beta\RunRealtimeReportRequest;
use Google\Analytics\Data\V1beta\RunRealtimeReportResponse;
use Google\Analytics\Data\V1beta\RunReportRequest;
use Google\Analytics\Data\V1beta\RunReportResponse;
use Google\ApiCore\ApiException;
use Google\ApiCore\CredentialsWrapper;
use Google\ApiCore\GapicClientTrait;
use Google\ApiCore\LongRunning\OperationsClient;
use Google\ApiCore\OperationResponse;
use Google\ApiCore\PathTemplate;
use Google\ApiCore\RequestParamsHeaderDescriptor;
use Google\ApiCore\RetrySettings;
use Google\ApiCore\Transport\TransportInterface;
use Google\ApiCore\ValidationException;
use Google\Auth\FetchAuthTokenInterface;
use Google\LongRunning\Operation;
/**
* Service Description: Google Analytics reporting data service.
*
* 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:
*
* ```
* $betaAnalyticsDataClient = new BetaAnalyticsDataClient();
* try {
* $response = $betaAnalyticsDataClient->batchRunPivotReports();
* } finally {
* $betaAnalyticsDataClient->close();
* }
* ```
*
* 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 parseName method to extract the individual identifiers
* contained within formatted names that are returned by the API.
*
* @experimental
*
* @deprecated Please use the new service client {@see \Google\Analytics\Data\V1beta\Client\BetaAnalyticsDataClient}.
*/
class BetaAnalyticsDataGapicClient
{
use GapicClientTrait;
/** The name of the service. */
const SERVICE_NAME = 'google.analytics.data.v1beta.BetaAnalyticsData';
/**
* The default address of the service.
*
* @deprecated SERVICE_ADDRESS_TEMPLATE should be used instead.
*/
const SERVICE_ADDRESS = 'analyticsdata.googleapis.com';
/** The address template of the service. */
private const SERVICE_ADDRESS_TEMPLATE = 'analyticsdata.UNIVERSE_DOMAIN';
/** The default port of the service. */
const DEFAULT_SERVICE_PORT = 443;
/** The name of the code generator, to be included in the agent header. */
const CODEGEN_NAME = 'gapic';
/** The default scopes required by the service. */
public static $serviceScopes = [
'https://www.googleapis.com/auth/analytics',
'https://www.googleapis.com/auth/analytics.readonly',
];
private static $audienceExportNameTemplate;
private static $metadataNameTemplate;
private static $propertyNameTemplate;
private static $pathTemplateMap;
private $operationsClient;
private static function getClientDefaults()
{
return [
'serviceName' => self::SERVICE_NAME,
'apiEndpoint' =>
self::SERVICE_ADDRESS . ':' . self::DEFAULT_SERVICE_PORT,
'clientConfig' =>
__DIR__ .
'/../resources/beta_analytics_data_client_config.json',
'descriptorsConfigPath' =>
__DIR__ .
'/../resources/beta_analytics_data_descriptor_config.php',
'gcpApiConfigPath' =>
__DIR__ . '/../resources/beta_analytics_data_grpc_config.json',
'credentialsConfig' => [
'defaultScopes' => self::$serviceScopes,
],
'transportConfig' => [
'rest' => [
'restClientConfigPath' =>
__DIR__ .
'/../resources/beta_analytics_data_rest_client_config.php',
],
],
];
}
private static function getAudienceExportNameTemplate()
{
if (self::$audienceExportNameTemplate == null) {
self::$audienceExportNameTemplate = new PathTemplate(
'properties/{property}/audienceExports/{audience_export}'
);
}
return self::$audienceExportNameTemplate;
}
private static function getMetadataNameTemplate()
{
if (self::$metadataNameTemplate == null) {
self::$metadataNameTemplate = new PathTemplate(
'properties/{property}/metadata'
);
}
return self::$metadataNameTemplate;
}
private static function getPropertyNameTemplate()
{
if (self::$propertyNameTemplate == null) {
self::$propertyNameTemplate = new PathTemplate(
'properties/{property}'
);
}
return self::$propertyNameTemplate;
}
private static function getPathTemplateMap()
{
if (self::$pathTemplateMap == null) {
self::$pathTemplateMap = [
'audienceExport' => self::getAudienceExportNameTemplate(),
'metadata' => self::getMetadataNameTemplate(),
'property' => self::getPropertyNameTemplate(),
];
}
return self::$pathTemplateMap;
}
/**
* Formats a string containing the fully-qualified path to represent a
* audience_export resource.
*
* @param string $property
* @param string $audienceExport
*
* @return string The formatted audience_export resource.
*
* @experimental
*/
public static function audienceExportName($property, $audienceExport)
{
return self::getAudienceExportNameTemplate()->render([
'property' => $property,
'audience_export' => $audienceExport,
]);
}
/**
* Formats a string containing the fully-qualified path to represent a metadata
* resource.
*
* @param string $property
*
* @return string The formatted metadata resource.
*
* @experimental
*/
public static function metadataName($property)
{
return self::getMetadataNameTemplate()->render([
'property' => $property,
]);
}
/**
* Formats a string containing the fully-qualified path to represent a property
* resource.
*
* @param string $property
*
* @return string The formatted property resource.
*
* @experimental
*/
public static function propertyName($property)
{
return self::getPropertyNameTemplate()->render([
'property' => $property,
]);
}
/**
* Parses a formatted name string and returns an associative array of the components in the name.
* The following name formats are supported:
* Template: Pattern
* - audienceExport: properties/{property}/audienceExports/{audience_export}
* - metadata: properties/{property}/metadata
* - property: properties/{property}
*
* The optional $template argument can be supplied to specify a particular pattern,
* and must match one of the templates listed above. If no $template argument is
* provided, or if the $template argument does not match one of the templates
* listed, then parseName will check each of the supported templates, and return
* the first match.
*
* @param string $formattedName The formatted name string
* @param string $template Optional name of template to match
*
* @return array An associative array from name component IDs to component values.
*
* @throws ValidationException If $formattedName could not be matched.
*
* @experimental
*/
public static function parseName($formattedName, $template = null)
{
$templateMap = self::getPathTemplateMap();
if ($template) {
if (!isset($templateMap[$template])) {
throw new ValidationException(
"Template name $template does not exist"
);
}
return $templateMap[$template]->match($formattedName);
}
foreach ($templateMap as $templateName => $pathTemplate) {
try {
return $pathTemplate->match($formattedName);
} catch (ValidationException $ex) {
// Swallow the exception to continue trying other path templates
}
}
throw new ValidationException(
"Input did not match any known format. Input: $formattedName"
);
}
/**
* Return an OperationsClient object with the same endpoint as $this.
*
* @return OperationsClient
*
* @experimental
*/
public function getOperationsClient()
{
return $this->operationsClient;
}
/**
* Resume an existing long running operation that was previously started by a long
* running API method. If $methodName is not provided, or does not match a long
* running API method, then the operation can still be resumed, but the
* OperationResponse object will not deserialize the final response.
*
* @param string $operationName The name of the long running operation
* @param string $methodName The name of the method used to start the operation
*
* @return OperationResponse
*
* @experimental
*/
public function resumeOperation($operationName, $methodName = null)
{
$options = isset($this->descriptors[$methodName]['longRunning'])
? $this->descriptors[$methodName]['longRunning']
: [];
$operation = new OperationResponse(
$operationName,
$this->getOperationsClient(),
$options
);
$operation->reload();
return $operation;
}
/**
* Constructor.
*
* @param array $options {
* Optional. Options for configuring the service API wrapper.
*
* @type string $apiEndpoint
* The address of the API remote host. May optionally include the port, formatted
* as "<uri>:<port>". Default 'analyticsdata.googleapis.com:443'.
* @type string|array|FetchAuthTokenInterface|CredentialsWrapper $credentials
* The credentials to be used by the client to authorize API calls. This option
* accepts either a path to a credentials file, or a decoded credentials file as a
* PHP array.
* *Advanced usage*: In addition, this option can also accept a pre-constructed
* {@see \Google\Auth\FetchAuthTokenInterface} object or
* {@see \Google\ApiCore\CredentialsWrapper} object. Note that when one of these
* objects are provided, any settings in $credentialsConfig will be ignored.
* @type array $credentialsConfig
* Options used to configure credentials, including auth token caching, for the
* client. For a full list of supporting configuration options, see
* {@see \Google\ApiCore\CredentialsWrapper::build()} .
* @type bool $disableRetries
* Determines whether or not retries defined by the client configuration should be
* disabled. Defaults to `false`.
* @type string|array $clientConfig
* Client method configuration, including retry settings. This option can be either
* a path to a JSON file, or a PHP array containing the decoded JSON data. By
* default this settings points to the default client config file, which is
* provided in the resources folder.
* @type string|TransportInterface $transport
* The transport used for executing network requests. May be either the string
* `rest` or `grpc`. Defaults to `grpc` if gRPC support is detected on the system.
* *Advanced usage*: Additionally, it is possible to pass in an already
* instantiated {@see \Google\ApiCore\Transport\TransportInterface} object. Note
* that when this object is provided, any settings in $transportConfig, and any
* $apiEndpoint setting, will be ignored.
* @type array $transportConfig
* Configuration options that will be used to construct the transport. Options for
* each supported transport type should be passed in a key for that transport. For
* example:
* $transportConfig = [
* 'grpc' => [...],
* 'rest' => [...],
* ];
* See the {@see \Google\ApiCore\Transport\GrpcTransport::build()} and
* {@see \Google\ApiCore\Transport\RestTransport::build()} methods for the
* supported options.
* @type callable $clientCertSource
* A callable which returns the client cert as a string. This can be used to
* provide a certificate and private key to the transport layer for mTLS.
* }
*
* @throws ValidationException
*
* @experimental
*/
public function __construct(array $options = [])
{
$clientOptions = $this->buildClientOptions($options);
$this->setClientOptions($clientOptions);
$this->operationsClient = $this->createOperationsClient($clientOptions);
}
/**
* Returns multiple pivot reports in a batch. All reports must be for the same
* GA4 Property.
*
* Sample code:
* ```
* $betaAnalyticsDataClient = new BetaAnalyticsDataClient();
* try {
* $response = $betaAnalyticsDataClient->batchRunPivotReports();
* } finally {
* $betaAnalyticsDataClient->close();
* }
* ```
*
* @param array $optionalArgs {
* Optional.
*
* @type string $property
* 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](https://developers.google.com/analytics/devguides/reporting/data/v1/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
* @type RunPivotReportRequest[] $requests
* Individual requests. Each request has a separate pivot report response.
* Each batch request is allowed up to 5 requests.
* @type RetrySettings|array $retrySettings
* Retry settings to use for this call. Can be a {@see RetrySettings} object, or an
* associative array of retry settings parameters. See the documentation on
* {@see RetrySettings} for example usage.
* }
*
* @return \Google\Analytics\Data\V1beta\BatchRunPivotReportsResponse
*
* @throws ApiException if the remote call fails
*
* @experimental
*/
public function batchRunPivotReports(array $optionalArgs = [])
{
$request = new BatchRunPivotReportsRequest();
$requestParamHeaders = [];
if (isset($optionalArgs['property'])) {
$request->setProperty($optionalArgs['property']);
$requestParamHeaders['property'] = $optionalArgs['property'];
}
if (isset($optionalArgs['requests'])) {
$request->setRequests($optionalArgs['requests']);
}
$requestParams = new RequestParamsHeaderDescriptor(
$requestParamHeaders
);
$optionalArgs['headers'] = isset($optionalArgs['headers'])
? array_merge($requestParams->getHeader(), $optionalArgs['headers'])
: $requestParams->getHeader();
return $this->startCall(
'BatchRunPivotReports',
BatchRunPivotReportsResponse::class,
$optionalArgs,
$request
)->wait();
}
/**
* Returns multiple reports in a batch. All reports must be for the same
* GA4 Property.
*
* Sample code:
* ```
* $betaAnalyticsDataClient = new BetaAnalyticsDataClient();
* try {
* $response = $betaAnalyticsDataClient->batchRunReports();
* } finally {
* $betaAnalyticsDataClient->close();
* }
* ```
*
* @param array $optionalArgs {
* Optional.
*
* @type string $property
* 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](https://developers.google.com/analytics/devguides/reporting/data/v1/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
* @type RunReportRequest[] $requests
* Individual requests. Each request has a separate report response. Each
* batch request is allowed up to 5 requests.
* @type RetrySettings|array $retrySettings
* Retry settings to use for this call. Can be a {@see RetrySettings} object, or an
* associative array of retry settings parameters. See the documentation on
* {@see RetrySettings} for example usage.
* }
*
* @return \Google\Analytics\Data\V1beta\BatchRunReportsResponse
*
* @throws ApiException if the remote call fails
*
* @experimental
*/
public function batchRunReports(array $optionalArgs = [])
{
$request = new BatchRunReportsRequest();
$requestParamHeaders = [];
if (isset($optionalArgs['property'])) {
$request->setProperty($optionalArgs['property']);
$requestParamHeaders['property'] = $optionalArgs['property'];
}
if (isset($optionalArgs['requests'])) {
$request->setRequests($optionalArgs['requests']);
}
$requestParams = new RequestParamsHeaderDescriptor(
$requestParamHeaders
);
$optionalArgs['headers'] = isset($optionalArgs['headers'])
? array_merge($requestParams->getHeader(), $optionalArgs['headers'])
: $requestParams->getHeader();
return $this->startCall(
'BatchRunReports',
BatchRunReportsResponse::class,
$optionalArgs,
$request
)->wait();
}
/**
* 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.
*
* Sample code:
* ```
* $betaAnalyticsDataClient = new BetaAnalyticsDataClient();
* try {
* $response = $betaAnalyticsDataClient->checkCompatibility();
* } finally {
* $betaAnalyticsDataClient->close();
* }
* ```
*
* @param array $optionalArgs {
* Optional.
*
* @type string $property
* A Google Analytics GA4 property identifier whose events are tracked. To
* learn more, see [where to find your Property
* ID](https://developers.google.com/analytics/devguides/reporting/data/v1/property-id).
* `property` should be the same value as in your `runReport` request.
*
* Example: properties/1234
* @type Dimension[] $dimensions
* The dimensions in this report. `dimensions` should be the same value as in
* your `runReport` request.
* @type Metric[] $metrics
* The metrics in this report. `metrics` should be the same value as in your
* `runReport` request.
* @type FilterExpression $dimensionFilter
* The filter clause of dimensions. `dimensionFilter` should be the same value
* as in your `runReport` request.
* @type FilterExpression $metricFilter
* The filter clause of metrics. `metricFilter` should be the same value as in
* your `runReport` request
* @type int $compatibilityFilter
* Filters the dimensions and metrics in the response to just this
* compatibility. Commonly used as `”compatibilityFilter”: “COMPATIBLE”`
* to only return compatible dimensions & metrics.
* For allowed values, use constants defined on {@see \Google\Analytics\Data\V1beta\Compatibility}
* @type RetrySettings|array $retrySettings
* Retry settings to use for this call. Can be a {@see RetrySettings} object, or an
* associative array of retry settings parameters. See the documentation on
* {@see RetrySettings} for example usage.
* }
*
* @return \Google\Analytics\Data\V1beta\CheckCompatibilityResponse
*
* @throws ApiException if the remote call fails
*
* @experimental
*/
public function checkCompatibility(array $optionalArgs = [])
{
$request = new CheckCompatibilityRequest();
$requestParamHeaders = [];
if (isset($optionalArgs['property'])) {
$request->setProperty($optionalArgs['property']);
$requestParamHeaders['property'] = $optionalArgs['property'];
}
if (isset($optionalArgs['dimensions'])) {
$request->setDimensions($optionalArgs['dimensions']);
}
if (isset($optionalArgs['metrics'])) {
$request->setMetrics($optionalArgs['metrics']);
}
if (isset($optionalArgs['dimensionFilter'])) {
$request->setDimensionFilter($optionalArgs['dimensionFilter']);
}
if (isset($optionalArgs['metricFilter'])) {
$request->setMetricFilter($optionalArgs['metricFilter']);
}
if (isset($optionalArgs['compatibilityFilter'])) {
$request->setCompatibilityFilter(
$optionalArgs['compatibilityFilter']
);
}
$requestParams = new RequestParamsHeaderDescriptor(
$requestParamHeaders
);
$optionalArgs['headers'] = isset($optionalArgs['headers'])
? array_merge($requestParams->getHeader(), $optionalArgs['headers'])
: $requestParams->getHeader();
return $this->startCall(
'CheckCompatibility',
CheckCompatibilityResponse::class,
$optionalArgs,
$request
)->wait();
}
/**
* 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](https://developers.google.com/analytics/devguides/reporting/data/v1/audience-list-basics)
* 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](https://forms.gle/EeA5u5LW6PEggtCEA) form.
*
* Sample code:
* ```
* $betaAnalyticsDataClient = new BetaAnalyticsDataClient();
* try {
* $formattedParent = $betaAnalyticsDataClient->propertyName('[PROPERTY]');
* $audienceExport = new AudienceExport();
* $operationResponse = $betaAnalyticsDataClient->createAudienceExport($formattedParent, $audienceExport);
* $operationResponse->pollUntilComplete();
* if ($operationResponse->operationSucceeded()) {
* $result = $operationResponse->getResult();
* // doSomethingWith($result)
* } else {
* $error = $operationResponse->getError();
* // handleError($error)
* }
* // Alternatively:
* // start the operation, keep the operation name, and resume later
* $operationResponse = $betaAnalyticsDataClient->createAudienceExport($formattedParent, $audienceExport);
* $operationName = $operationResponse->getName();
* // ... do other work
* $newOperationResponse = $betaAnalyticsDataClient->resumeOperation($operationName, 'createAudienceExport');
* while (!$newOperationResponse->isDone()) {
* // ... do other work
* $newOperationResponse->reload();
* }
* if ($newOperationResponse->operationSucceeded()) {
* $result = $newOperationResponse->getResult();
* // doSomethingWith($result)
* } else {
* $error = $newOperationResponse->getError();
* // handleError($error)
* }
* } finally {
* $betaAnalyticsDataClient->close();
* }
* ```
*
* @param string $parent Required. The parent resource where this audience export will be created.
* Format: `properties/{property}`
* @param AudienceExport $audienceExport Required. The audience export to create.
* @param array $optionalArgs {
* Optional.
*
* @type RetrySettings|array $retrySettings
* Retry settings to use for this call. Can be a {@see RetrySettings} object, or an
* associative array of retry settings parameters. See the documentation on
* {@see RetrySettings} for example usage.
* }
*
* @return \Google\ApiCore\OperationResponse
*
* @throws ApiException if the remote call fails
*
* @experimental
*/
public function createAudienceExport(
$parent,
$audienceExport,
array $optionalArgs = []
) {
$request = new CreateAudienceExportRequest();
$requestParamHeaders = [];
$request->setParent($parent);
$request->setAudienceExport($audienceExport);
$requestParamHeaders['parent'] = $parent;
$requestParams = new RequestParamsHeaderDescriptor(
$requestParamHeaders
);
$optionalArgs['headers'] = isset($optionalArgs['headers'])
? array_merge($requestParams->getHeader(), $optionalArgs['headers'])
: $requestParams->getHeader();
return $this->startOperationsCall(
'CreateAudienceExport',
$optionalArgs,
$request,
$this->getOperationsClient()
)->wait();
}
/**
* 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](https://developers.google.com/analytics/devguides/reporting/data/v1/audience-list-basics)
* 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](https://forms.gle/EeA5u5LW6PEggtCEA) form.
*
* Sample code:
* ```
* $betaAnalyticsDataClient = new BetaAnalyticsDataClient();
* try {
* $formattedName = $betaAnalyticsDataClient->audienceExportName('[PROPERTY]', '[AUDIENCE_EXPORT]');
* $response = $betaAnalyticsDataClient->getAudienceExport($formattedName);
* } finally {
* $betaAnalyticsDataClient->close();
* }
* ```
*
* @param string $name Required. The audience export resource name.
* Format: `properties/{property}/audienceExports/{audience_export}`
* @param array $optionalArgs {
* Optional.
*
* @type RetrySettings|array $retrySettings
* Retry settings to use for this call. Can be a {@see RetrySettings} object, or an
* associative array of retry settings parameters. See the documentation on
* {@see RetrySettings} for example usage.
* }
*
* @return \Google\Analytics\Data\V1beta\AudienceExport
*
* @throws ApiException if the remote call fails
*
* @experimental
*/
public function getAudienceExport($name, array $optionalArgs = [])
{
$request = new GetAudienceExportRequest();
$requestParamHeaders = [];
$request->setName($name);
$requestParamHeaders['name'] = $name;
$requestParams = new RequestParamsHeaderDescriptor(
$requestParamHeaders
);
$optionalArgs['headers'] = isset($optionalArgs['headers'])
? array_merge($requestParams->getHeader(), $optionalArgs['headers'])
: $requestParams->getHeader();
return $this->startCall(
'GetAudienceExport',
AudienceExport::class,
$optionalArgs,
$request
)->wait();
}
/**
* 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`.
*
* Sample code:
* ```
* $betaAnalyticsDataClient = new BetaAnalyticsDataClient();
* try {
* $formattedName = $betaAnalyticsDataClient->metadataName('[PROPERTY]');
* $response = $betaAnalyticsDataClient->getMetadata($formattedName);
* } finally {
* $betaAnalyticsDataClient->close();
* }
* ```
*
* @param string $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.
* @param array $optionalArgs {
* Optional.
*
* @type RetrySettings|array $retrySettings
* Retry settings to use for this call. Can be a {@see RetrySettings} object, or an
* associative array of retry settings parameters. See the documentation on
* {@see RetrySettings} for example usage.
* }
*
* @return \Google\Analytics\Data\V1beta\Metadata
*
* @throws ApiException if the remote call fails
*
* @experimental
*/
public function getMetadata($name, array $optionalArgs = [])
{
$request = new GetMetadataRequest();
$requestParamHeaders = [];
$request->setName($name);
$requestParamHeaders['name'] = $name;
$requestParams = new RequestParamsHeaderDescriptor(
$requestParamHeaders
);
$optionalArgs['headers'] = isset($optionalArgs['headers'])
? array_merge($requestParams->getHeader(), $optionalArgs['headers'])
: $requestParams->getHeader();
return $this->startCall(
'GetMetadata',
Metadata::class,
$optionalArgs,
$request
)->wait();
}
/**
* 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](https://developers.google.com/analytics/devguides/reporting/data/v1/audience-list-basics)
* 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](https://forms.gle/EeA5u5LW6PEggtCEA) form.
*
* Sample code:
* ```
* $betaAnalyticsDataClient = new BetaAnalyticsDataClient();
* try {
* $formattedParent = $betaAnalyticsDataClient->propertyName('[PROPERTY]');
* // Iterate over pages of elements
* $pagedResponse = $betaAnalyticsDataClient->listAudienceExports($formattedParent);
* foreach ($pagedResponse->iteratePages() as $page) {
* foreach ($page as $element) {
* // doSomethingWith($element);
* }
* }
* // Alternatively:
* // Iterate through all elements
* $pagedResponse = $betaAnalyticsDataClient->listAudienceExports($formattedParent);
* foreach ($pagedResponse->iterateAllElements() as $element) {
* // doSomethingWith($element);
* }
* } finally {
* $betaAnalyticsDataClient->close();
* }
* ```
*
* @param string $parent Required. All audience exports for this property will be listed in the
* response. Format: `properties/{property}`
* @param array $optionalArgs {
* Optional.
*
* @type int $pageSize
* The maximum number of resources contained in the underlying API
* response. The API may return fewer values in a page, even if
* there are additional values to be retrieved.
* @type string $pageToken
* A page token is used to specify a page of values to be returned.
* If no page token is specified (the default), the first page
* of values will be returned. Any page token used here must have
* been generated by a previous call to the API.
* @type RetrySettings|array $retrySettings
* Retry settings to use for this call. Can be a {@see RetrySettings} object, or an
* associative array of retry settings parameters. See the documentation on
* {@see RetrySettings} for example usage.
* }
*
* @return \Google\ApiCore\PagedListResponse
*
* @throws ApiException if the remote call fails
*
* @experimental
*/
public function listAudienceExports($parent, array $optionalArgs = [])
{
$request = new ListAudienceExportsRequest();
$requestParamHeaders = [];
$request->setParent($parent);
$requestParamHeaders['parent'] = $parent;
if (isset($optionalArgs['pageSize'])) {
$request->setPageSize($optionalArgs['pageSize']);
}
if (isset($optionalArgs['pageToken'])) {
$request->setPageToken($optionalArgs['pageToken']);
}
$requestParams = new RequestParamsHeaderDescriptor(
$requestParamHeaders
);
$optionalArgs['headers'] = isset($optionalArgs['headers'])
? array_merge($requestParams->getHeader(), $optionalArgs['headers'])
: $requestParams->getHeader();
return $this->getPagedListResponse(
'ListAudienceExports',
$optionalArgs,
ListAudienceExportsResponse::class,
$request
);
}
/**
* 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](https://developers.google.com/analytics/devguides/reporting/data/v1/audience-list-basics)
* 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