Skip to content

Commit 88e97f3

Browse files
feat: add GetCalculatedMetric, CreateCalculatedMetric, ListCalculatedMetrics, UpdateCalculatedMetric, DeleteCalculatedMetric methods to the Admin API v1alpha (#6999)
feat: add the `CALCULATED_METRIC` option to the `ChangeHistoryResourceType` enum feat: add the `calculated_metric` field to the `ChangeHistoryResource.resource` oneof field feat: add the `CalculatedMetric` resource PiperOrigin-RevId: 601235502 Source-Link: googleapis/googleapis@a88065a Source-Link: googleapis/googleapis-gen@e7b5094 Copy-Tag: eyJwIjoiQW5hbHl0aWNzQWRtaW4vLk93bEJvdC55YW1sIiwiaCI6ImU3YjUwOTQ0ZTY2MzdiNzBiY2VkZDBiYWI1ZDY2NmIyZjIyZWY3NTcifQ==
1 parent 2abac50 commit 88e97f3

29 files changed

Lines changed: 3303 additions & 15 deletions

AnalyticsAdmin/metadata/V1Alpha/AnalyticsAdmin.php

Lines changed: 30 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
912 Bytes
Binary file not shown.
Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
<?php
2+
/*
3+
* Copyright 2024 Google LLC
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* https://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
/*
19+
* GENERATED CODE WARNING
20+
* This file was automatically generated - do not edit!
21+
*/
22+
23+
require_once __DIR__ . '/../../../vendor/autoload.php';
24+
25+
// [START analyticsadmin_v1alpha_generated_AnalyticsAdminService_CreateCalculatedMetric_sync]
26+
use Google\Analytics\Admin\V1alpha\CalculatedMetric;
27+
use Google\Analytics\Admin\V1alpha\CalculatedMetric\MetricUnit;
28+
use Google\Analytics\Admin\V1alpha\Client\AnalyticsAdminServiceClient;
29+
use Google\Analytics\Admin\V1alpha\CreateCalculatedMetricRequest;
30+
use Google\ApiCore\ApiException;
31+
32+
/**
33+
* Creates a CalculatedMetric.
34+
*
35+
* @param string $formattedParent Format: properties/{property_id}
36+
* Example: properties/1234
37+
* Please see {@see AnalyticsAdminServiceClient::propertyName()} for help formatting this field.
38+
* @param string $calculatedMetricId The ID to use for the calculated metric which will become the
39+
* final component of the calculated metric's resource name.
40+
*
41+
* This value should be 1-80 characters and valid characters are
42+
* /[a-zA-Z0-9_]/, no spaces allowed. calculated_metric_id must be unique
43+
* between all calculated metrics under a property. The calculated_metric_id
44+
* is used when referencing this calculated metric from external APIs, for
45+
* example, "calcMetric:{calculated_metric_id}".
46+
* @param string $calculatedMetricDisplayName Display name for this calculated metric as shown in the
47+
* Google Analytics UI. Max length 82 characters.
48+
* @param int $calculatedMetricMetricUnit The type for the calculated metric's value.
49+
* @param string $calculatedMetricFormula The calculated metric's definition. Maximum number of unique
50+
* referenced custom metrics is 5. Formulas supports the following operations:
51+
* + (addition), - (subtraction), - (negative), * (multiplication), /
52+
* (division), () (parenthesis). Any valid real numbers are acceptable that
53+
* fit in a Long (64bit integer) or a Double (64 bit floating point number).
54+
* Example formula:
55+
* "( customEvent:parameter_name + cartPurchaseQuantity ) / 2.0"
56+
*/
57+
function create_calculated_metric_sample(
58+
string $formattedParent,
59+
string $calculatedMetricId,
60+
string $calculatedMetricDisplayName,
61+
int $calculatedMetricMetricUnit,
62+
string $calculatedMetricFormula
63+
): void {
64+
// Create a client.
65+
$analyticsAdminServiceClient = new AnalyticsAdminServiceClient();
66+
67+
// Prepare the request message.
68+
$calculatedMetric = (new CalculatedMetric())
69+
->setDisplayName($calculatedMetricDisplayName)
70+
->setMetricUnit($calculatedMetricMetricUnit)
71+
->setFormula($calculatedMetricFormula);
72+
$request = (new CreateCalculatedMetricRequest())
73+
->setParent($formattedParent)
74+
->setCalculatedMetricId($calculatedMetricId)
75+
->setCalculatedMetric($calculatedMetric);
76+
77+
// Call the API and handle any network failures.
78+
try {
79+
/** @var CalculatedMetric $response */
80+
$response = $analyticsAdminServiceClient->createCalculatedMetric($request);
81+
printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString());
82+
} catch (ApiException $ex) {
83+
printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage());
84+
}
85+
}
86+
87+
/**
88+
* Helper to execute the sample.
89+
*
90+
* This sample has been automatically generated and should be regarded as a code
91+
* template only. It will require modifications to work:
92+
* - It may require correct/in-range values for request initialization.
93+
* - It may require specifying regional endpoints when creating the service client,
94+
* please see the apiEndpoint client configuration option for more details.
95+
*/
96+
function callSample(): void
97+
{
98+
$formattedParent = AnalyticsAdminServiceClient::propertyName('[PROPERTY]');
99+
$calculatedMetricId = '[CALCULATED_METRIC_ID]';
100+
$calculatedMetricDisplayName = '[DISPLAY_NAME]';
101+
$calculatedMetricMetricUnit = MetricUnit::METRIC_UNIT_UNSPECIFIED;
102+
$calculatedMetricFormula = '[FORMULA]';
103+
104+
create_calculated_metric_sample(
105+
$formattedParent,
106+
$calculatedMetricId,
107+
$calculatedMetricDisplayName,
108+
$calculatedMetricMetricUnit,
109+
$calculatedMetricFormula
110+
);
111+
}
112+
// [END analyticsadmin_v1alpha_generated_AnalyticsAdminService_CreateCalculatedMetric_sync]
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
<?php
2+
/*
3+
* Copyright 2024 Google LLC
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* https://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
/*
19+
* GENERATED CODE WARNING
20+
* This file was automatically generated - do not edit!
21+
*/
22+
23+
require_once __DIR__ . '/../../../vendor/autoload.php';
24+
25+
// [START analyticsadmin_v1alpha_generated_AnalyticsAdminService_DeleteCalculatedMetric_sync]
26+
use Google\Analytics\Admin\V1alpha\Client\AnalyticsAdminServiceClient;
27+
use Google\Analytics\Admin\V1alpha\DeleteCalculatedMetricRequest;
28+
use Google\ApiCore\ApiException;
29+
30+
/**
31+
* Deletes a CalculatedMetric on a property.
32+
*
33+
* @param string $formattedName The name of the CalculatedMetric to delete.
34+
* Format: properties/{property_id}/calculatedMetrics/{calculated_metric_id}
35+
* Example: properties/1234/calculatedMetrics/Metric01
36+
* Please see {@see AnalyticsAdminServiceClient::calculatedMetricName()} for help formatting this field.
37+
*/
38+
function delete_calculated_metric_sample(string $formattedName): void
39+
{
40+
// Create a client.
41+
$analyticsAdminServiceClient = new AnalyticsAdminServiceClient();
42+
43+
// Prepare the request message.
44+
$request = (new DeleteCalculatedMetricRequest())
45+
->setName($formattedName);
46+
47+
// Call the API and handle any network failures.
48+
try {
49+
$analyticsAdminServiceClient->deleteCalculatedMetric($request);
50+
printf('Call completed successfully.' . PHP_EOL);
51+
} catch (ApiException $ex) {
52+
printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage());
53+
}
54+
}
55+
56+
/**
57+
* Helper to execute the sample.
58+
*
59+
* This sample has been automatically generated and should be regarded as a code
60+
* template only. It will require modifications to work:
61+
* - It may require correct/in-range values for request initialization.
62+
* - It may require specifying regional endpoints when creating the service client,
63+
* please see the apiEndpoint client configuration option for more details.
64+
*/
65+
function callSample(): void
66+
{
67+
$formattedName = AnalyticsAdminServiceClient::calculatedMetricName(
68+
'[PROPERTY]',
69+
'[CALCULATED_METRIC]'
70+
);
71+
72+
delete_calculated_metric_sample($formattedName);
73+
}
74+
// [END analyticsadmin_v1alpha_generated_AnalyticsAdminService_DeleteCalculatedMetric_sync]
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
<?php
2+
/*
3+
* Copyright 2024 Google LLC
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* https://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
/*
19+
* GENERATED CODE WARNING
20+
* This file was automatically generated - do not edit!
21+
*/
22+
23+
require_once __DIR__ . '/../../../vendor/autoload.php';
24+
25+
// [START analyticsadmin_v1alpha_generated_AnalyticsAdminService_GetCalculatedMetric_sync]
26+
use Google\Analytics\Admin\V1alpha\CalculatedMetric;
27+
use Google\Analytics\Admin\V1alpha\Client\AnalyticsAdminServiceClient;
28+
use Google\Analytics\Admin\V1alpha\GetCalculatedMetricRequest;
29+
use Google\ApiCore\ApiException;
30+
31+
/**
32+
* Lookup for a single CalculatedMetric.
33+
*
34+
* @param string $formattedName The name of the CalculatedMetric to get.
35+
* Format: properties/{property_id}/calculatedMetrics/{calculated_metric_id}
36+
* Example: properties/1234/calculatedMetrics/Metric01
37+
* Please see {@see AnalyticsAdminServiceClient::calculatedMetricName()} for help formatting this field.
38+
*/
39+
function get_calculated_metric_sample(string $formattedName): void
40+
{
41+
// Create a client.
42+
$analyticsAdminServiceClient = new AnalyticsAdminServiceClient();
43+
44+
// Prepare the request message.
45+
$request = (new GetCalculatedMetricRequest())
46+
->setName($formattedName);
47+
48+
// Call the API and handle any network failures.
49+
try {
50+
/** @var CalculatedMetric $response */
51+
$response = $analyticsAdminServiceClient->getCalculatedMetric($request);
52+
printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString());
53+
} catch (ApiException $ex) {
54+
printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage());
55+
}
56+
}
57+
58+
/**
59+
* Helper to execute the sample.
60+
*
61+
* This sample has been automatically generated and should be regarded as a code
62+
* template only. It will require modifications to work:
63+
* - It may require correct/in-range values for request initialization.
64+
* - It may require specifying regional endpoints when creating the service client,
65+
* please see the apiEndpoint client configuration option for more details.
66+
*/
67+
function callSample(): void
68+
{
69+
$formattedName = AnalyticsAdminServiceClient::calculatedMetricName(
70+
'[PROPERTY]',
71+
'[CALCULATED_METRIC]'
72+
);
73+
74+
get_calculated_metric_sample($formattedName);
75+
}
76+
// [END analyticsadmin_v1alpha_generated_AnalyticsAdminService_GetCalculatedMetric_sync]

0 commit comments

Comments
 (0)