Google Analytics Admin V1beta Client - Class AnalyticsAdminServiceClient (0.10.0)

Reference documentation and code samples for the Google Analytics Admin V1beta Client class AnalyticsAdminServiceClient.

Service Description: Service Interface for the Analytics Admin API (GA4).

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:

$analyticsAdminServiceClient = new AnalyticsAdminServiceClient();
try {
    $formattedProperty = $analyticsAdminServiceClient->propertyName('[PROPERTY]');
    $acknowledgement = 'acknowledgement';
    $response = $analyticsAdminServiceClient->acknowledgeUserDataCollection($formattedProperty, $acknowledgement);
} finally {
    $analyticsAdminServiceClient->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.

Methods

accountName

Formats a string containing the fully-qualified path to represent a account resource.

Parameter
NameDescription
account string
Returns
TypeDescription
stringThe formatted account resource.

conversionEventName

Formats a string containing the fully-qualified path to represent a conversion_event resource.

Parameters
NameDescription
property string
conversionEvent string
Returns
TypeDescription
stringThe formatted conversion_event resource.

customDimensionName

Formats a string containing the fully-qualified path to represent a custom_dimension resource.

Parameters
NameDescription
property string
customDimension string
Returns
TypeDescription
stringThe formatted custom_dimension resource.

customMetricName

Formats a string containing the fully-qualified path to represent a custom_metric resource.

Parameters
NameDescription
property string
customMetric string
Returns
TypeDescription
stringThe formatted custom_metric resource.

dataRetentionSettingsName

Formats a string containing the fully-qualified path to represent a data_retention_settings resource.

Parameter
NameDescription
property string
Returns
TypeDescription
stringThe formatted data_retention_settings resource.

dataSharingSettingsName

Formats a string containing the fully-qualified path to represent a data_sharing_settings resource.

Parameter
NameDescription
account string
Returns
TypeDescription
stringThe formatted data_sharing_settings resource.

dataStreamName

Formats a string containing the fully-qualified path to represent a data_stream resource.

Parameters
NameDescription
property string
dataStream string
Returns
TypeDescription
stringThe formatted data_stream resource.

firebaseLinkName

Formats a string containing the fully-qualified path to represent a firebase_link resource.

Parameters
NameDescription
property string
firebaseLink string
Returns
TypeDescription
stringThe formatted firebase_link resource.

googleAdsLinkName

Formats a string containing the fully-qualified path to represent a google_ads_link resource.

Parameters
NameDescription
property string
googleAdsLink string
Returns
TypeDescription
stringThe formatted google_ads_link resource.

measurementProtocolSecretName

Formats a string containing the fully-qualified path to represent a measurement_protocol_secret resource.

Parameters
NameDescription
property string
dataStream string
measurementProtocolSecret string
Returns
TypeDescription
stringThe formatted measurement_protocol_secret resource.

propertyName

Formats a string containing the fully-qualified path to represent a property resource.

Parameter
NameDescription
property string
Returns
TypeDescription
stringThe formatted property resource.

parseName

Parses a formatted name string and returns an associative array of the components in the name.

The following name formats are supported: Template: Pattern

  • account: accounts/{account}
  • conversionEvent: properties/{property}/conversionEvents/{conversion_event}
  • customDimension: properties/{property}/customDimensions/{custom_dimension}
  • customMetric: properties/{property}/customMetrics/{custom_metric}
  • dataRetentionSettings: properties/{property}/dataRetentionSettings
  • dataSharingSettings: accounts/{account}/dataSharingSettings
  • dataStream: properties/{property}/dataStreams/{data_stream}
  • firebaseLink: properties/{property}/firebaseLinks/{firebase_link}
  • googleAdsLink: properties/{property}/googleAdsLinks/{google_ads_link}
  • measurementProtocolSecret: properties/{property}/dataStreams/{data_stream}/measurementProtocolSecrets/{measurement_protocol_secret}
  • 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.

Parameters
NameDescription
formattedName string

The formatted name string

template string

Optional name of template to match

Returns
TypeDescription
arrayAn associative array from name component IDs to component values.

__construct

Constructor.

Parameters
NameDescription
options array

Optional. Options for configuring the service API wrapper.

↳ apiEndpoint string

The address of the API remote host. May optionally include the port, formatted as "

↳ credentials string|array|FetchAuthTokenInterface|CredentialsWrapper

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 Google\Auth\FetchAuthTokenInterface object or Google\ApiCore\CredentialsWrapper object. Note that when one of these objects are provided, any settings in $credentialsConfig will be ignored.

↳ credentialsConfig array

Options used to configure credentials, including auth token caching, for the client. For a full list of supporting configuration options, see Google\ApiCore\CredentialsWrapper::build() .

↳ disableRetries bool

Determines whether or not retries defined by the client configuration should be disabled. Defaults to false.

↳ clientConfig string|array

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.

↳ transport string|TransportInterface

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 Google\ApiCore\Transport\TransportInterface object. Note that when this object is provided, any settings in $transportConfig, and any $apiEndpoint setting, will be ignored.

↳ transportConfig array

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 Google\ApiCore\Transport\GrpcTransport::build() and Google\ApiCore\Transport\RestTransport::build() methods for the supported options.

↳ clientCertSource callable

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.

acknowledgeUserDataCollection

Acknowledges the terms of user data collection for the specified property.

This acknowledgement must be completed (either in the Google Analytics UI or via this API) before MeasurementProtocolSecret resources may be created.

Parameters
NameDescription
property string

Required. The property for which to acknowledge user data collection.

acknowledgement string

Required. An acknowledgement that the caller of this method understands the terms of user data collection.

This field must contain the exact value: "I acknowledge that I have the necessary privacy disclosures and rights from my end users for the collection and processing of their data, including the association of such data with the visitation information Google Analytics collects from my site and/or app property."

optionalArgs array

Optional.

↳ retrySettings RetrySettings|array

Retry settings to use for this call. Can be a Google\ApiCore\RetrySettings object, or an associative array of retry settings parameters. See the documentation on Google\ApiCore\RetrySettings for example usage.

Returns
TypeDescription
Google\Analytics\Admin\V1beta\AcknowledgeUserDataCollectionResponse
Example
use Google\Analytics\Admin\V1beta\AcknowledgeUserDataCollectionResponse;
use Google\Analytics\Admin\V1beta\AnalyticsAdminServiceClient;
use Google\ApiCore\ApiException;

/**
 * @param string $formattedProperty The property for which to acknowledge user data collection. Please see
 *                                  {@see AnalyticsAdminServiceClient::propertyName()} for help formatting this field.
 * @param string $acknowledgement   An acknowledgement that the caller of this method understands the terms
 *                                  of user data collection.
 *
 *                                  This field must contain the exact value:
 *                                  "I acknowledge that I have the necessary privacy disclosures and rights
 *                                  from my end users for the collection and processing of their data,
 *                                  including the association of such data with the visitation information
 *                                  Google Analytics collects from my site and/or app property."
 */
function acknowledge_user_data_collection_sample(
    string $formattedProperty,
    string $acknowledgement
): void {
    // Create a client.
    $analyticsAdminServiceClient = new AnalyticsAdminServiceClient();

    // Call the API and handle any network failures.
    try {
        /** @var AcknowledgeUserDataCollectionResponse $response */
        $response = $analyticsAdminServiceClient->acknowledgeUserDataCollection(
            $formattedProperty,
            $acknowledgement
        );
        printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString());
    } catch (ApiException $ex) {
        printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage());
    }
}

/**
 * This sample has been automatically generated and should be regarded as a code
 * template only. It will require modifications to work:
 *  - It may require correct/in-range values for request initialization.
 *  - It may require specifying regional endpoints when creating the service client,
 *    please see the apiEndpoint client configuration option for more details.
 */
function callSample(): void
{
    $formattedProperty = AnalyticsAdminServiceClient::propertyName('[PROPERTY]');
    $acknowledgement = '[ACKNOWLEDGEMENT]';

    acknowledge_user_data_collection_sample($formattedProperty, $acknowledgement);
}

archiveCustomDimension

Archives a CustomDimension on a property.

Parameters
NameDescription
name string

Required. The name of the CustomDimension to archive. Example format: properties/1234/customDimensions/5678

optionalArgs array

Optional.

↳ retrySettings RetrySettings|array

Retry settings to use for this call. Can be a Google\ApiCore\RetrySettings object, or an associative array of retry settings parameters. See the documentation on Google\ApiCore\RetrySettings for example usage.

Example
use Google\Analytics\Admin\V1beta\AnalyticsAdminServiceClient;
use Google\ApiCore\ApiException;

/**
 * @param string $formattedName The name of the CustomDimension to archive.
 *                              Example format: properties/1234/customDimensions/5678
 *                              Please see {@see AnalyticsAdminServiceClient::customDimensionName()} for help formatting this field.
 */
function archive_custom_dimension_sample(string $formattedName): void
{
    // Create a client.
    $analyticsAdminServiceClient = new AnalyticsAdminServiceClient();

    // Call the API and handle any network failures.
    try {
        $analyticsAdminServiceClient->archiveCustomDimension($formattedName);
        printf('Call completed successfully.' . PHP_EOL);
    } catch (ApiException $ex) {
        printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage());
    }
}

/**
 * This sample has been automatically generated and should be regarded as a code
 * template only. It will require modifications to work:
 *  - It may require correct/in-range values for request initialization.
 *  - It may require specifying regional endpoints when creating the service client,
 *    please see the apiEndpoint client configuration option for more details.
 */
function callSample(): void
{
    $formattedName = AnalyticsAdminServiceClient::customDimensionName(
        '[PROPERTY]',
        '[CUSTOM_DIMENSION]'
    );

    archive_custom_dimension_sample($formattedName);
}

archiveCustomMetric

Archives a CustomMetric on a property.

Parameters
NameDescription
name string

Required. The name of the CustomMetric to archive. Example format: properties/1234/customMetrics/5678

optionalArgs array

Optional.

↳ retrySettings RetrySettings|array

Retry settings to use for this call. Can be a Google\ApiCore\RetrySettings object, or an associative array of retry settings parameters. See the documentation on Google\ApiCore\RetrySettings for example usage.

Example
use Google\Analytics\Admin\V1beta\AnalyticsAdminServiceClient;
use Google\ApiCore\ApiException;

/**
 * @param string $formattedName The name of the CustomMetric to archive.
 *                              Example format: properties/1234/customMetrics/5678
 *                              Please see {@see AnalyticsAdminServiceClient::customMetricName()} for help formatting this field.
 */
function archive_custom_metric_sample(string $formattedName): void
{
    // Create a client.
    $analyticsAdminServiceClient = new AnalyticsAdminServiceClient();

    // Call the API and handle any network failures.
    try {
        $analyticsAdminServiceClient->archiveCustomMetric($formattedName);
        printf('Call completed successfully.' . PHP_EOL);
    } catch (ApiException $ex) {
        printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage());
    }
}

/**
 * This sample has been automatically generated and should be regarded as a code
 * template only. It will require modifications to work:
 *  - It may require correct/in-range values for request initialization.
 *  - It may require specifying regional endpoints when creating the service client,
 *    please see the apiEndpoint client configuration option for more details.
 */
function callSample(): void
{
    $formattedName = AnalyticsAdminServiceClient::customMetricName('[PROPERTY]', '[CUSTOM_METRIC]');

    archive_custom_metric_sample($formattedName);
}

createConversionEvent

Creates a conversion event with the specified attributes.

Parameters
NameDescription
conversionEvent Google\Analytics\Admin\V1beta\ConversionEvent

Required. The conversion event to create.

parent string

Required. The resource name of the parent property where this conversion event will be created. Format: properties/123

optionalArgs array

Optional.

↳ retrySettings RetrySettings|array

Retry settings to use for this call. Can be a Google\ApiCore\RetrySettings object, or an associative array of retry settings parameters. See the documentation on Google\ApiCore\RetrySettings for example usage.

Returns
TypeDescription
Google\Analytics\Admin\V1beta\ConversionEvent
Example
use Google\Analytics\Admin\V1beta\AnalyticsAdminServiceClient;
use Google\Analytics\Admin\V1beta\ConversionEvent;
use Google\ApiCore\ApiException;

/**
 * @param string $formattedParent The resource name of the parent property where this conversion event will
 *                                be created. Format: properties/123
 *                                Please see {@see AnalyticsAdminServiceClient::propertyName()} for help formatting this field.
 */
function create_conversion_event_sample(string $formattedParent): void
{
    // Create a client.
    $analyticsAdminServiceClient = new AnalyticsAdminServiceClient();

    // Prepare any non-scalar elements to be passed along with the request.
    $conversionEvent = new ConversionEvent();

    // Call the API and handle any network failures.
    try {
        /** @var ConversionEvent $response */
        $response = $analyticsAdminServiceClient->createConversionEvent($conversionEvent, $formattedParent);
        printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString());
    } catch (ApiException $ex) {
        printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage());
    }
}

/**
 * This sample has been automatically generated and should be regarded as a code
 * template only. It will require modifications to work:
 *  - It may require correct/in-range values for request initialization.
 *  - It may require specifying regional endpoints when creating the service client,
 *    please see the apiEndpoint client configuration option for more details.
 */
function callSample(): void
{
    $formattedParent = AnalyticsAdminServiceClient::propertyName('[PROPERTY]');

    create_conversion_event_sample($formattedParent);
}

createCustomDimension

Creates a CustomDimension.

Parameters
NameDescription
parent string

Required. Example format: properties/1234

customDimension Google\Analytics\Admin\V1beta\CustomDimension

Required. The CustomDimension to create.

optionalArgs array

Optional.

↳ retrySettings RetrySettings|array

Retry settings to use for this call. Can be a Google\ApiCore\RetrySettings object, or an associative array of retry settings parameters. See the documentation on Google\ApiCore\RetrySettings for example usage.

Returns
TypeDescription
Google\Analytics\Admin\V1beta\CustomDimension
Example
use Google\Analytics\Admin\V1beta\AnalyticsAdminServiceClient;
use Google\Analytics\Admin\V1beta\CustomDimension;
use Google\Analytics\Admin\V1beta\CustomDimension\DimensionScope;
use Google\ApiCore\ApiException;

/**
 * @param string $formattedParent              Example format: properties/1234
 *                                             Please see {@see AnalyticsAdminServiceClient::propertyName()} for help formatting this field.
 * @param string $customDimensionParameterName Immutable. Tagging parameter name for this custom dimension.
 *
 *                                             If this is a user-scoped dimension, then this is the user property name.
 *                                             If this is an event-scoped dimension, then this is the event parameter
 *                                             name.
 *
 *                                             May only contain alphanumeric and underscore characters, starting with a
 *                                             letter. Max length of 24 characters for user-scoped dimensions, 40
 *                                             characters for event-scoped dimensions.
 * @param string $customDimensionDisplayName   Display name for this custom dimension as shown in the Analytics UI.
 *                                             Max length of 82 characters, alphanumeric plus space and underscore
 *                                             starting with a letter. Legacy system-generated display names may contain
 *                                             square brackets, but updates to this field will never permit square
 *                                             brackets.
 * @param int    $customDimensionScope         Immutable. The scope of this dimension.
 */
function create_custom_dimension_sample(
    string $formattedParent,
    string $customDimensionParameterName,
    string $customDimensionDisplayName,
    int $customDimensionScope
): void {
    // Create a client.
    $analyticsAdminServiceClient = new AnalyticsAdminServiceClient();

    // Prepare any non-scalar elements to be passed along with the request.
    $customDimension = (new CustomDimension())
        ->setParameterName($customDimensionParameterName)
        ->setDisplayName($customDimensionDisplayName)
        ->setScope($customDimensionScope);

    // Call the API and handle any network failures.
    try {
        /** @var CustomDimension $response */
        $response = $analyticsAdminServiceClient->createCustomDimension($formattedParent, $customDimension);
        printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString());
    } catch (ApiException $ex) {
        printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage());
    }
}

/**
 * This sample has been automatically generated and should be regarded as a code
 * template only. It will require modifications to work:
 *  - It may require correct/in-range values for request initialization.
 *  - It may require specifying regional endpoints when creating the service client,
 *    please see the apiEndpoint client configuration option for more details.
 */
function callSample(): void
{
    $formattedParent = AnalyticsAdminServiceClient::propertyName('[PROPERTY]');
    $customDimensionParameterName = '[PARAMETER_NAME]';
    $customDimensionDisplayName = '[DISPLAY_NAME]';
    $customDimensionScope = DimensionScope::DIMENSION_SCOPE_UNSPECIFIED;

    create_custom_dimension_sample(
        $formattedParent,
        $customDimensionParameterName,
        $customDimensionDisplayName,
        $customDimensionScope
    );
}

createCustomMetric

Creates a CustomMetric.

Parameters
NameDescription
parent string

Required. Example format: properties/1234

customMetric Google\Analytics\Admin\V1beta\CustomMetric

Required. The CustomMetric to create.

optionalArgs array

Optional.

↳ retrySettings RetrySettings|array

Retry settings to use for this call. Can be a Google\ApiCore\RetrySettings object, or an associative array of retry settings parameters. See the documentation on Google\ApiCore\RetrySettings for example usage.

Returns
TypeDescription
Google\Analytics\Admin\V1beta\CustomMetric
Example
use Google\Analytics\Admin\V1beta\AnalyticsAdminServiceClient;
use Google\Analytics\Admin\V1beta\CustomMetric;
use Google\Analytics\Admin\V1beta\CustomMetric\MeasurementUnit;
use Google\Analytics\Admin\V1beta\CustomMetric\MetricScope;
use Google\ApiCore\ApiException;

/**
 * @param string $formattedParent             Example format: properties/1234
 *                                            Please see {@see AnalyticsAdminServiceClient::propertyName()} for help formatting this field.
 * @param string $customMetricParameterName   Immutable. Tagging name for this custom metric.
 *
 *                                            If this is an event-scoped metric, then this is the event parameter
 *                                            name.
 *
 *                                            May only contain alphanumeric and underscore charactes, starting with a
 *                                            letter. Max length of 40 characters for event-scoped metrics.
 * @param string $customMetricDisplayName     Display name for this custom metric as shown in the Analytics UI.
 *                                            Max length of 82 characters, alphanumeric plus space and underscore
 *                                            starting with a letter. Legacy system-generated display names may contain
 *                                            square brackets, but updates to this field will never permit square
 *                                            brackets.
 * @param int    $customMetricMeasurementUnit The type for the custom metric's value.
 * @param int    $customMetricScope           Immutable. The scope of this custom metric.
 */
function create_custom_metric_sample(
    string $formattedParent,
    string $customMetricParameterName,
    string $customMetricDisplayName,
    int $customMetricMeasurementUnit,
    int $customMetricScope
): void {
    // Create a client.
    $analyticsAdminServiceClient = new AnalyticsAdminServiceClient();

    // Prepare any non-scalar elements to be passed along with the request.
    $customMetric = (new CustomMetric())
        ->setParameterName($customMetricParameterName)
        ->setDisplayName($customMetricDisplayName)
        ->setMeasurementUnit($customMetricMeasurementUnit)
        ->setScope($customMetricScope);

    // Call the API and handle any network failures.
    try {
        /** @var CustomMetric $response */
        $response = $analyticsAdminServiceClient->createCustomMetric($formattedParent, $customMetric);
        printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString());
    } catch (ApiException $ex) {
        printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage());
    }
}

/**
 * This sample has been automatically generated and should be regarded as a code
 * template only. It will require modifications to work:
 *  - It may require correct/in-range values for request initialization.
 *  - It may require specifying regional endpoints when creating the service client,
 *    please see the apiEndpoint client configuration option for more details.
 */
function callSample(): void
{
    $formattedParent = AnalyticsAdminServiceClient::propertyName('[PROPERTY]');
    $customMetricParameterName = '[PARAMETER_NAME]';
    $customMetricDisplayName = '[DISPLAY_NAME]';
    $customMetricMeasurementUnit = MeasurementUnit::MEASUREMENT_UNIT_UNSPECIFIED;
    $customMetricScope = MetricScope::METRIC_SCOPE_UNSPECIFIED;

    create_custom_metric_sample(
        $formattedParent,
        $customMetricParameterName,
        $customMetricDisplayName,
        $customMetricMeasurementUnit,
        $customMetricScope
    );
}

createDataStream

Creates a DataStream.

Parameters
NameDescription
parent string

Required. Example format: properties/1234

dataStream Google\Analytics\Admin\V1beta\DataStream

Required. The DataStream to create.

optionalArgs array

Optional.

↳ retrySettings RetrySettings|array

Retry settings to use for this call. Can be a Google\ApiCore\RetrySettings object, or an associative array of retry settings parameters. See the documentation on Google\ApiCore\RetrySettings for example usage.

Returns
TypeDescription
Google\Analytics\Admin\V1beta\DataStream
Example
use Google\Analytics\Admin\V1beta\AnalyticsAdminServiceClient;
use Google\Analytics\Admin\V1beta\DataStream;
use Google\Analytics\Admin\V1beta\DataStream\DataStreamType;
use Google\ApiCore\ApiException;

/**
 * @param string $formattedParent Example format: properties/1234
 *                                Please see {@see AnalyticsAdminServiceClient::propertyName()} for help formatting this field.
 * @param int    $dataStreamType  Immutable. The type of this DataStream resource.
 */
function create_data_stream_sample(string $formattedParent, int $dataStreamType): void
{
    // Create a client.
    $analyticsAdminServiceClient = new AnalyticsAdminServiceClient();

    // Prepare any non-scalar elements to be passed along with the request.
    $dataStream = (new DataStream())
        ->setType($dataStreamType);

    // Call the API and handle any network failures.
    try {
        /** @var DataStream $response */
        $response = $analyticsAdminServiceClient->createDataStream($formattedParent, $dataStream);
        printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString());
    } catch (ApiException $ex) {
        printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage());
    }
}

/**
 * This sample has been automatically generated and should be regarded as a code
 * template only. It will require modifications to work:
 *  - It may require correct/in-range values for request initialization.
 *  - It may require specifying regional endpoints when creating the service client,
 *    please see the apiEndpoint client configuration option for more details.
 */
function callSample(): void
{
    $formattedParent = AnalyticsAdminServiceClient::propertyName('[PROPERTY]');
    $dataStreamType = DataStreamType::DATA_STREAM_TYPE_UNSPECIFIED;

    create_data_stream_sample($formattedParent, $dataStreamType);
}

Creates a FirebaseLink.

Properties can have at most one FirebaseLink.

Parameters
NameDescription
parent string

Required. Format: properties/{property_id} Example: properties/1234

firebaseLink Google\Analytics\Admin\V1beta\FirebaseLink

Required. The Firebase link to create.

optionalArgs array

Optional.

↳ retrySettings RetrySettings|array

Retry settings to use for this call. Can be a Google\ApiCore\RetrySettings object, or an associative array of retry settings parameters. See the documentation on Google\ApiCore\RetrySettings for example usage.

Returns
TypeDescription
Google\Analytics\Admin\V1beta\FirebaseLink
Example
use Google\Analytics\Admin\V1beta\AnalyticsAdminServiceClient;
use Google\Analytics\Admin\V1beta\FirebaseLink;
use Google\ApiCore\ApiException;

/**
 * @param string $formattedParent Format: properties/{property_id}
 *                                Example: properties/1234
 *                                Please see {@see AnalyticsAdminServiceClient::propertyName()} for help formatting this field.
 */
function create_firebase_link_sample(string $formattedParent): void
{
    // Create a client.
    $analyticsAdminServiceClient = new AnalyticsAdminServiceClient();

    // Prepare any non-scalar elements to be passed along with the request.
    $firebaseLink = new FirebaseLink();

    // Call the API and handle any network failures.
    try {
        /** @var FirebaseLink $response */
        $response = $analyticsAdminServiceClient->createFirebaseLink($formattedParent, $firebaseLink);
        printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString());
    } catch (ApiException $ex) {
        printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage());
    }
}

/**
 * This sample has been automatically generated and should be regarded as a code
 * template only. It will require modifications to work:
 *  - It may require correct/in-range values for request initialization.
 *  - It may require specifying regional endpoints when creating the service client,
 *    please see the apiEndpoint client configuration option for more details.
 */
function callSample(): void
{
    $formattedParent = AnalyticsAdminServiceClient::propertyName('[PROPERTY]');

    create_firebase_link_sample($formattedParent);
}

Creates a GoogleAdsLink.

Parameters
NameDescription
parent string

Required. Example format: properties/1234

googleAdsLink Google\Analytics\Admin\V1beta\GoogleAdsLink

Required. The GoogleAdsLink to create.

optionalArgs array

Optional.

↳ retrySettings RetrySettings|array

Retry settings to use for this call. Can be a Google\ApiCore\RetrySettings object, or an associative array of retry settings parameters. See the documentation on Google\ApiCore\RetrySettings for example usage.

Returns
TypeDescription
Google\Analytics\Admin\V1beta\GoogleAdsLink
Example
use Google\Analytics\Admin\V1beta\AnalyticsAdminServiceClient;
use Google\Analytics\Admin\V1beta\GoogleAdsLink;
use Google\ApiCore\ApiException;

/**
 * @param string $formattedParent Example format: properties/1234
 *                                Please see {@see AnalyticsAdminServiceClient::propertyName()} for help formatting this field.
 */
function create_google_ads_link_sample(string $formattedParent): void
{
    // Create a client.
    $analyticsAdminServiceClient = new AnalyticsAdminServiceClient();

    // Prepare any non-scalar elements to be passed along with the request.
    $googleAdsLink = new GoogleAdsLink();

    // Call the API and handle any network failures.
    try {
        /** @var GoogleAdsLink $response */
        $response = $analyticsAdminServiceClient->createGoogleAdsLink($formattedParent, $googleAdsLink);
        printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString());
    } catch (ApiException $ex) {
        printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage());
    }
}

/**
 * This sample has been automatically generated and should be regarded as a code
 * template only. It will require modifications to work:
 *  - It may require correct/in-range values for request initialization.
 *  - It may require specifying regional endpoints when creating the service client,
 *    please see the apiEndpoint client configuration option for more details.
 */
function callSample(): void
{
    $formattedParent = AnalyticsAdminServiceClient::propertyName('[PROPERTY]');

    create_google_ads_link_sample($formattedParent);
}

createMeasurementProtocolSecret

Creates a measurement protocol secret.

Parameters
NameDescription
parent string

Required. The parent resource where this secret will be created. Format: properties/{property}/dataStreams/{dataStream}

measurementProtocolSecret Google\Analytics\Admin\V1beta\MeasurementProtocolSecret

Required. The measurement protocol secret to create.

optionalArgs array

Optional.

↳ retrySettings RetrySettings|array

Retry settings to use for this call. Can be a Google\ApiCore\RetrySettings object, or an associative array of retry settings parameters. See the documentation on Google\ApiCore\RetrySettings for example usage.

Returns
TypeDescription
Google\Analytics\Admin\V1beta\MeasurementProtocolSecret
Example
use Google\Analytics\Admin\V1beta\AnalyticsAdminServiceClient;
use Google\Analytics\Admin\V1beta\MeasurementProtocolSecret;
use Google\ApiCore\ApiException;

/**
 * @param string $formattedParent                      The parent resource where this secret will be created.
 *                                                     Format: properties/{property}/dataStreams/{dataStream}
 *                                                     Please see {@see AnalyticsAdminServiceClient::dataStreamName()} for help formatting this field.
 * @param string $measurementProtocolSecretDisplayName Human-readable display name for this secret.
 */
function create_measurement_protocol_secret_sample(
    string $formattedParent,
    string $measurementProtocolSecretDisplayName
): void {
    // Create a client.
    $analyticsAdminServiceClient = new AnalyticsAdminServiceClient();

    // Prepare any non-scalar elements to be passed along with the request.
    $measurementProtocolSecret = (new MeasurementProtocolSecret())
        ->setDisplayName($measurementProtocolSecretDisplayName);

    // Call the API and handle any network failures.
    try {
        /** @var MeasurementProtocolSecret $response */
        $response = $analyticsAdminServiceClient->createMeasurementProtocolSecret(
            $formattedParent,
            $measurementProtocolSecret
        );
        printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString());
    } catch (ApiException $ex) {
        printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage());
    }
}

/**
 * This sample has been automatically generated and should be regarded as a code
 * template only. It will require modifications to work:
 *  - It may require correct/in-range values for request initialization.
 *  - It may require specifying regional endpoints when creating the service client,
 *    please see the apiEndpoint client configuration option for more details.
 */
function callSample(): void
{
    $formattedParent = AnalyticsAdminServiceClient::dataStreamName('[PROPERTY]', '[DATA_STREAM]');
    $measurementProtocolSecretDisplayName = '[DISPLAY_NAME]';

    create_measurement_protocol_secret_sample($formattedParent, $measurementProtocolSecretDisplayName);
}

createProperty

Creates an "GA4" property with the specified location and attributes.

Parameters
NameDescription
property Google\Analytics\Admin\V1beta\Property

Required. The property to create. Note: the supplied property must specify its parent.

optionalArgs array

Optional.

↳ retrySettings RetrySettings|array

Retry settings to use for this call. Can be a Google\ApiCore\RetrySettings object, or an associative array of retry settings parameters. See the documentation on Google\ApiCore\RetrySettings for example usage.

Returns
TypeDescription
Google\Analytics\Admin\V1beta\Property
Example
use Google\Analytics\Admin\V1beta\AnalyticsAdminServiceClient;
use Google\Analytics\Admin\V1beta\Property;
use Google\ApiCore\ApiException;

/**
 * @param string $propertyDisplayName Human-readable display name for this property.
 *
 *                                    The max allowed display name length is 100 UTF-16 code units.
 * @param string $propertyTimeZone    Reporting Time Zone, used as the day boundary for reports, regardless of
 *                                    where the data originates. If the time zone honors DST, Analytics will
 *                                    automatically adjust for the changes.
 *
 *                                    NOTE: Changing the time zone only affects data going forward, and is not
 *                                    applied retroactively.
 *
 *                                    Format: https://www.iana.org/time-zones
 *                                    Example: "America/Los_Angeles"
 */
function create_property_sample(string $propertyDisplayName, string $propertyTimeZone): void
{
    // Create a client.
    $analyticsAdminServiceClient = new AnalyticsAdminServiceClient();

    // Prepare any non-scalar elements to be passed along with the request.
    $property = (new Property())
        ->setDisplayName($propertyDisplayName)
        ->setTimeZone($propertyTimeZone);

    // Call the API and handle any network failures.
    try {
        /** @var Property $response */
        $response = $analyticsAdminServiceClient->createProperty($property);
        printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString());
    } catch (ApiException $ex) {
        printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage());
    }
}

/**
 * This sample has been automatically generated and should be regarded as a code
 * template only. It will require modifications to work:
 *  - It may require correct/in-range values for request initialization.
 *  - It may require specifying regional endpoints when creating the service client,
 *    please see the apiEndpoint client configuration option for more details.
 */
function callSample(): void
{
    $propertyDisplayName = '[DISPLAY_NAME]';
    $propertyTimeZone = '[TIME_ZONE]';

    create_property_sample($propertyDisplayName, $propertyTimeZone);
}

deleteAccount

Marks target Account as soft-deleted (ie: "trashed") and returns it.

This API does not have a method to restore soft-deleted accounts. However, they can be restored using the Trash Can UI.

If the accounts are not restored before the expiration time, the account and all child resources (eg: Properties, GoogleAdsLinks, Streams, UserLinks) will be permanently purged. https://support.google.com/analytics/answer/6154772

Returns an error if the target is not found.

Parameters
NameDescription
name string

Required. The name of the Account to soft-delete. Format: accounts/{account} Example: "accounts/100"

optionalArgs array

Optional.

↳ retrySettings RetrySettings|array

Retry settings to use for this call. Can be a Google\ApiCore\RetrySettings object, or an associative array of retry settings parameters. See the documentation on Google\ApiCore\RetrySettings for example usage.

Example
use Google\Analytics\Admin\V1beta\AnalyticsAdminServiceClient;
use Google\ApiCore\ApiException;

/**
 * @param string $formattedName The name of the Account to soft-delete.
 *                              Format: accounts/{account}
 *                              Example: "accounts/100"
 *                              Please see {@see AnalyticsAdminServiceClient::accountName()} for help formatting this field.
 */
function delete_account_sample(string $formattedName): void
{
    // Create a client.
    $analyticsAdminServiceClient = new AnalyticsAdminServiceClient();

    // Call the API and handle any network failures.
    try {
        $analyticsAdminServiceClient->deleteAccount($formattedName);
        printf('Call completed successfully.' . PHP_EOL);
    } catch (ApiException $ex) {
        printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage());
    }
}

/**
 * This sample has been automatically generated and should be regarded as a code
 * template only. It will require modifications to work:
 *  - It may require correct/in-range values for request initialization.
 *  - It may require specifying regional endpoints when creating the service client,
 *    please see the apiEndpoint client configuration option for more details.
 */
function callSample(): void
{
    $formattedName = AnalyticsAdminServiceClient::accountName('[ACCOUNT]');

    delete_account_sample($formattedName);
}

deleteConversionEvent

Deletes a conversion event in a property.

Parameters
NameDescription
name string

Required. The resource name of the conversion event to delete. Format: properties/{property}/conversionEvents/{conversion_event} Example: "properties/123/conversionEvents/456"

optionalArgs array

Optional.

↳ retrySettings RetrySettings|array

Retry settings to use for this call. Can be a Google\ApiCore\RetrySettings object, or an associative array of retry settings parameters. See the documentation on Google\ApiCore\RetrySettings for example usage.

Example
use Google\Analytics\Admin\V1beta\AnalyticsAdminServiceClient;
use Google\ApiCore\ApiException;

/**
 * @param string $formattedName The resource name of the conversion event to delete.
 *                              Format: properties/{property}/conversionEvents/{conversion_event}
 *                              Example: "properties/123/conversionEvents/456"
 *                              Please see {@see AnalyticsAdminServiceClient::conversionEventName()} for help formatting this field.
 */
function delete_conversion_event_sample(string $formattedName): void
{
    // Create a client.
    $analyticsAdminServiceClient = new AnalyticsAdminServiceClient();

    // Call the API and handle any network failures.
    try {
        $analyticsAdminServiceClient->deleteConversionEvent($formattedName);
        printf('Call completed successfully.' . PHP_EOL);
    } catch (ApiException $ex) {
        printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage());
    }
}

/**
 * This sample has been automatically generated and should be regarded as a code
 * template only. It will require modifications to work:
 *  - It may require correct/in-range values for request initialization.
 *  - It may require specifying regional endpoints when creating the service client,
 *    please see the apiEndpoint client configuration option for more details.
 */
function callSample(): void
{
    $formattedName = AnalyticsAdminServiceClient::conversionEventName(
        '[PROPERTY]',
        '[CONVERSION_EVENT]'
    );

    delete_conversion_event_sample($formattedName);
}

deleteDataStream

Deletes a DataStream on a property.

Parameters
NameDescription
name string

Required. The name of the DataStream to delete. Example format: properties/1234/dataStreams/5678

optionalArgs array

Optional.

↳ retrySettings RetrySettings|array

Retry settings to use for this call. Can be a Google\ApiCore\RetrySettings object, or an associative array of retry settings parameters. See the documentation on Google\ApiCore\RetrySettings for example usage.

Example
use Google\Analytics\Admin\V1beta\AnalyticsAdminServiceClient;
use Google\ApiCore\ApiException;

/**
 * @param string $formattedName The name of the DataStream to delete.
 *                              Example format: properties/1234/dataStreams/5678
 *                              Please see {@see AnalyticsAdminServiceClient::dataStreamName()} for help formatting this field.
 */
function delete_data_stream_sample(string $formattedName): void
{
    // Create a client.
    $analyticsAdminServiceClient = new AnalyticsAdminServiceClient();

    // Call the API and handle any network failures.
    try {
        $analyticsAdminServiceClient->deleteDataStream($formattedName);
        printf('Call completed successfully.' . PHP_EOL);
    } catch (ApiException $ex) {
        printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage());
    }
}

/**
 * This sample has been automatically generated and should be regarded as a code
 * template only. It will require modifications to work:
 *  - It may require correct/in-range values for request initialization.
 *  - It may require specifying regional endpoints when creating the service client,
 *    please see the apiEndpoint client configuration option for more details.
 */
function callSample(): void
{
    $formattedName = AnalyticsAdminServiceClient::dataStreamName('[PROPERTY]', '[DATA_STREAM]');

    delete_data_stream_sample($formattedName);
}

Deletes a FirebaseLink on a property

Parameters
NameDescription
name string

Required. Format: properties/{property_id}/firebaseLinks/{firebase_link_id} Example: properties/1234/firebaseLinks/5678

optionalArgs array

Optional.

↳ retrySettings RetrySettings|array

Retry settings to use for this call. Can be a Google\ApiCore\RetrySettings object, or an associative array of retry settings parameters. See the documentation on Google\ApiCore\RetrySettings for example usage.

Example
use Google\Analytics\Admin\V1beta\AnalyticsAdminServiceClient;
use Google\ApiCore\ApiException;

/**
 * @param string $formattedName Format: properties/{property_id}/firebaseLinks/{firebase_link_id}
 *                              Example: properties/1234/firebaseLinks/5678
 *                              Please see {@see AnalyticsAdminServiceClient::firebaseLinkName()} for help formatting this field.
 */
function delete_firebase_link_sample(string $formattedName): void
{
    // Create a client.
    $analyticsAdminServiceClient = new AnalyticsAdminServiceClient();

    // Call the API and handle any network failures.
    try {
        $analyticsAdminServiceClient->deleteFirebaseLink($formattedName);
        printf('Call completed successfully.' . PHP_EOL);
    } catch (ApiException $ex) {
        printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage());
    }
}

/**
 * This sample has been automatically generated and should be regarded as a code
 * template only. It will require modifications to work:
 *  - It may require correct/in-range values for request initialization.
 *  - It may require specifying regional endpoints when creating the service client,
 *    please see the apiEndpoint client configuration option for more details.
 */
function callSample(): void
{
    $formattedName = AnalyticsAdminServiceClient::firebaseLinkName('[PROPERTY]', '[FIREBASE_LINK]');

    delete_firebase_link_sample($formattedName);
}

Deletes a GoogleAdsLink on a property

Parameters
NameDescription
name string

Required. Example format: properties/1234/googleAdsLinks/5678

optionalArgs array

Optional.

↳ retrySettings RetrySettings|array

Retry settings to use for this call. Can be a Google\ApiCore\RetrySettings object, or an associative array of retry settings parameters. See the documentation on Google\ApiCore\RetrySettings for example usage.

Example
use Google\Analytics\Admin\V1beta\AnalyticsAdminServiceClient;
use Google\ApiCore\ApiException;

/**
 * @param string $formattedName Example format: properties/1234/googleAdsLinks/5678
 *                              Please see {@see AnalyticsAdminServiceClient::googleAdsLinkName()} for help formatting this field.
 */
function delete_google_ads_link_sample(string $formattedName): void
{
    // Create a client.
    $analyticsAdminServiceClient = new AnalyticsAdminServiceClient();

    // Call the API and handle any network failures.
    try {
        $analyticsAdminServiceClient->deleteGoogleAdsLink($formattedName);
        printf('Call completed successfully.' . PHP_EOL);
    } catch (ApiException $ex) {
        printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage());
    }
}

/**
 * This sample has been automatically generated and should be regarded as a code
 * template only. It will require modifications to work:
 *  - It may require correct/in-range values for request initialization.
 *  - It may require specifying regional endpoints when creating the service client,
 *    please see the apiEndpoint client configuration option for more details.
 */
function callSample(): void
{
    $formattedName = AnalyticsAdminServiceClient::googleAdsLinkName('[PROPERTY]', '[GOOGLE_ADS_LINK]');

    delete_google_ads_link_sample($formattedName);
}

deleteMeasurementProtocolSecret

Deletes target MeasurementProtocolSecret.

Parameters
NameDescription
name string

Required. The name of the MeasurementProtocolSecret to delete. Format: properties/{property}/dataStreams/{dataStream}/measurementProtocolSecrets/{measurementProtocolSecret}

optionalArgs array

Optional.

↳ retrySettings RetrySettings|array

Retry settings to use for this call. Can be a Google\ApiCore\RetrySettings object, or an associative array of retry settings parameters. See the documentation on Google\ApiCore\RetrySettings for example usage.

Example
use Google\Analytics\Admin\V1beta\AnalyticsAdminServiceClient;
use Google\ApiCore\ApiException;

/**
 * @param string $formattedName The name of the MeasurementProtocolSecret to delete.
 *                              Format:
 *                              properties/{property}/dataStreams/{dataStream}/measurementProtocolSecrets/{measurementProtocolSecret}
 *                              Please see {@see AnalyticsAdminServiceClient::measurementProtocolSecretName()} for help formatting this field.
 */
function delete_measurement_protocol_secret_sample(string $formattedName): void
{
    // Create a client.
    $analyticsAdminServiceClient = new AnalyticsAdminServiceClient();

    // Call the API and handle any network failures.
    try {
        $analyticsAdminServiceClient->deleteMeasurementProtocolSecret($formattedName);
        printf('Call completed successfully.' . PHP_EOL);
    } catch (ApiException $ex) {
        printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage());
    }
}

/**
 * This sample has been automatically generated and should be regarded as a code
 * template only. It will require modifications to work:
 *  - It may require correct/in-range values for request initialization.
 *  - It may require specifying regional endpoints when creating the service client,
 *    please see the apiEndpoint client configuration option for more details.
 */
function callSample(): void
{
    $formattedName = AnalyticsAdminServiceClient::measurementProtocolSecretName(
        '[PROPERTY]',
        '[DATA_STREAM]',
        '[MEASUREMENT_PROTOCOL_SECRET]'
    );

    delete_measurement_protocol_secret_sample($formattedName);
}

deleteProperty

Marks target Property as soft-deleted (ie: "trashed") and returns it.

This API does not have a method to restore soft-deleted properties. However, they can be restored using the Trash Can UI.

If the properties are not restored before the expiration time, the Property and all child resources (eg: GoogleAdsLinks, Streams, UserLinks) will be permanently purged. https://support.google.com/analytics/answer/6154772

Returns an error if the target is not found, or is not an GA4 Property.

Parameters
NameDescription
name string

Required. The name of the Property to soft-delete. Format: properties/{property_id} Example: "properties/1000"

optionalArgs array

Optional.

↳ retrySettings RetrySettings|array

Retry settings to use for this call. Can be a Google\ApiCore\RetrySettings object, or an associative array of retry settings parameters. See the documentation on Google\ApiCore\RetrySettings for example usage.

Returns
TypeDescription
Google\Analytics\Admin\V1beta\Property
Example
use Google\Analytics\Admin\V1beta\AnalyticsAdminServiceClient;
use Google\Analytics\Admin\V1beta\Property;
use Google\ApiCore\ApiException;

/**
 * @param string $formattedName The name of the Property to soft-delete.
 *                              Format: properties/{property_id}
 *                              Example: "properties/1000"
 *                              Please see {@see AnalyticsAdminServiceClient::propertyName()} for help formatting this field.
 */
function delete_property_sample(string $formattedName): void
{
    // Create a client.
    $analyticsAdminServiceClient = new AnalyticsAdminServiceClient();

    // Call the API and handle any network failures.
    try {
        /** @var Property $response */
        $response = $analyticsAdminServiceClient->deleteProperty($formattedName);
        printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString());
    } catch (ApiException $ex) {
        printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage());
    }
}

/**
 * This sample has been automatically generated and should be regarded as a code
 * template only. It will require modifications to work:
 *  - It may require correct/in-range values for request initialization.
 *  - It may require specifying regional endpoints when creating the service client,
 *    please see the apiEndpoint client configuration option for more details.
 */
function callSample(): void
{
    $formattedName = AnalyticsAdminServiceClient::propertyName('[PROPERTY]');

    delete_property_sample($formattedName);
}

getAccount

Lookup for a single Account.

Parameters
NameDescription
name string

Required. The name of the account to lookup. Format: accounts/{account} Example: "accounts/100"

optionalArgs array

Optional.

↳ retrySettings RetrySettings|array

Retry settings to use for this call. Can be a Google\ApiCore\RetrySettings object, or an associative array of retry settings parameters. See the documentation on Google\ApiCore\RetrySettings for example usage.

Returns
TypeDescription
Google\Analytics\Admin\V1beta\Account
Example
use Google\Analytics\Admin\V1beta\Account;
use Google\Analytics\Admin\V1beta\AnalyticsAdminServiceClient;
use Google\ApiCore\ApiException;

/**
 * @param string $formattedName The name of the account to lookup.
 *                              Format: accounts/{account}
 *                              Example: "accounts/100"
 *                              Please see {@see AnalyticsAdminServiceClient::accountName()} for help formatting this field.
 */
function get_account_sample(string $formattedName): void
{
    // Create a client.
    $analyticsAdminServiceClient = new AnalyticsAdminServiceClient();

    // Call the API and handle any network failures.
    try {
        /** @var Account $response */
        $response = $analyticsAdminServiceClient->getAccount($formattedName);
        printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString());
    } catch (ApiException $ex) {
        printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage());
    }
}

/**
 * This sample has been automatically generated and should be regarded as a code
 * template only. It will require modifications to work:
 *  - It may require correct/in-range values for request initialization.
 *  - It may require specifying regional endpoints when creating the service client,
 *    please see the apiEndpoint client configuration option for more details.
 */
function callSample(): void
{
    $formattedName = AnalyticsAdminServiceClient::accountName('[ACCOUNT]');

    get_account_sample($formattedName);
}

getConversionEvent

Retrieve a single conversion event.

Parameters
NameDescription
name string

Required. The resource name of the conversion event to retrieve. Format: properties/{property}/conversionEvents/{conversion_event} Example: "properties/123/conversionEvents/456"

optionalArgs array

Optional.

↳ retrySettings RetrySettings|array

Retry settings to use for this call. Can be a Google\ApiCore\RetrySettings object, or an associative array of retry settings parameters. See the documentation on Google\ApiCore\RetrySettings for example usage.

Returns
TypeDescription
Google\Analytics\Admin\V1beta\ConversionEvent
Example
use Google\Analytics\Admin\V1beta\AnalyticsAdminServiceClient;
use Google\Analytics\Admin\V1beta\ConversionEvent;
use Google\ApiCore\ApiException;

/**
 * @param string $formattedName The resource name of the conversion event to retrieve.
 *                              Format: properties/{property}/conversionEvents/{conversion_event}
 *                              Example: "properties/123/conversionEvents/456"
 *                              Please see {@see AnalyticsAdminServiceClient::conversionEventName()} for help formatting this field.
 */
function get_conversion_event_sample(string $formattedName): void
{
    // Create a client.
    $analyticsAdminServiceClient = new AnalyticsAdminServiceClient();

    // Call the API and handle any network failures.
    try {
        /** @var ConversionEvent $response */
        $response = $analyticsAdminServiceClient->getConversionEvent($formattedName);
        printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString());
    } catch (ApiException $ex) {
        printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage());
    }
}

/**
 * This sample has been automatically generated and should be regarded as a code
 * template only. It will require modifications to work:
 *  - It may require correct/in-range values for request initialization.
 *  - It may require specifying regional endpoints when creating the service client,
 *    please see the apiEndpoint client configuration option for more details.
 */
function callSample(): void
{
    $formattedName = AnalyticsAdminServiceClient::conversionEventName(
        '[PROPERTY]',
        '[CONVERSION_EVENT]'
    );

    get_conversion_event_sample($formattedName);
}

getCustomDimension

Lookup for a single CustomDimension.

Parameters
NameDescription
name string

Required. The name of the CustomDimension to get. Example format: properties/1234/customDimensions/5678

optionalArgs array

Optional.

↳ retrySettings RetrySettings|array

Retry settings to use for this call. Can be a Google\ApiCore\RetrySettings object, or an associative array of retry settings parameters. See the documentation on Google\ApiCore\RetrySettings for example usage.

Returns
TypeDescription
Google\Analytics\Admin\V1beta\CustomDimension
Example
use Google\Analytics\Admin\V1beta\AnalyticsAdminServiceClient;
use Google\Analytics\Admin\V1beta\CustomDimension;
use Google\ApiCore\ApiException;

/**
 * @param string $formattedName The name of the CustomDimension to get.
 *                              Example format: properties/1234/customDimensions/5678
 *                              Please see {@see AnalyticsAdminServiceClient::customDimensionName()} for help formatting this field.
 */
function get_custom_dimension_sample(string $formattedName): void
{
    // Create a client.
    $analyticsAdminServiceClient = new AnalyticsAdminServiceClient();

    // Call the API and handle any network failures.
    try {
        /** @var CustomDimension $response */
        $response = $analyticsAdminServiceClient->getCustomDimension($formattedName);
        printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString());
    } catch (ApiException $ex) {
        printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage());
    }
}

/**
 * This sample has been automatically generated and should be regarded as a code
 * template only. It will require modifications to work:
 *  - It may require correct/in-range values for request initialization.
 *  - It may require specifying regional endpoints when creating the service client,
 *    please see the apiEndpoint client configuration option for more details.
 */
function callSample(): void
{
    $formattedName = AnalyticsAdminServiceClient::customDimensionName(
        '[PROPERTY]',
        '[CUSTOM_DIMENSION]'
    );

    get_custom_dimension_sample($formattedName);
}

getCustomMetric

Lookup for a single CustomMetric.

Parameters
NameDescription
name string

Required. The name of the CustomMetric to get. Example format: properties/1234/customMetrics/5678

optionalArgs array

Optional.

↳ retrySettings RetrySettings|array

Retry settings to use for this call. Can be a Google\ApiCore\RetrySettings object, or an associative array of retry settings parameters. See the documentation on Google\ApiCore\RetrySettings for example usage.

Returns
TypeDescription
Google\Analytics\Admin\V1beta\CustomMetric
Example
use Google\Analytics\Admin\V1beta\AnalyticsAdminServiceClient;
use Google\Analytics\Admin\V1beta\CustomMetric;
use Google\ApiCore\ApiException;

/**
 * @param string $formattedName The name of the CustomMetric to get.
 *                              Example format: properties/1234/customMetrics/5678
 *                              Please see {@see AnalyticsAdminServiceClient::customMetricName()} for help formatting this field.
 */
function get_custom_metric_sample(string $formattedName): void
{
    // Create a client.
    $analyticsAdminServiceClient = new AnalyticsAdminServiceClient();

    // Call the API and handle any network failures.
    try {
        /** @var CustomMetric $response */
        $response = $analyticsAdminServiceClient->getCustomMetric($formattedName);
        printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString());
    } catch (ApiException $ex) {
        printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage());
    }
}

/**
 * This sample has been automatically generated and should be regarded as a code
 * template only. It will require modifications to work:
 *  - It may require correct/in-range values for request initialization.
 *  - It may require specifying regional endpoints when creating the service client,
 *    please see the apiEndpoint client configuration option for more details.
 */
function callSample(): void
{
    $formattedName = AnalyticsAdminServiceClient::customMetricName('[PROPERTY]', '[CUSTOM_METRIC]');

    get_custom_metric_sample($formattedName);
}

getDataRetentionSettings

Returns the singleton data retention settings for this property.

Parameters
NameDescription
name string

Required. The name of the settings to lookup. Format: properties/{property}/dataRetentionSettings Example: "properties/1000/dataRetentionSettings"

optionalArgs array

Optional.

↳ retrySettings RetrySettings|array

Retry settings to use for this call. Can be a Google\ApiCore\RetrySettings object, or an associative array of retry settings parameters. See the documentation on Google\ApiCore\RetrySettings for example usage.

Returns
TypeDescription
Google\Analytics\Admin\V1beta\DataRetentionSettings
Example
use Google\Analytics\Admin\V1beta\AnalyticsAdminServiceClient;
use Google\Analytics\Admin\V1beta\DataRetentionSettings;
use Google\ApiCore\ApiException;

/**
 * @param string $formattedName The name of the settings to lookup.
 *                              Format:
 *                              properties/{property}/dataRetentionSettings
 *                              Example: "properties/1000/dataRetentionSettings"
 *                              Please see {@see AnalyticsAdminServiceClient::dataRetentionSettingsName()} for help formatting this field.
 */
function get_data_retention_settings_sample(string $formattedName): void
{
    // Create a client.
    $analyticsAdminServiceClient = new AnalyticsAdminServiceClient();

    // Call the API and handle any network failures.
    try {
        /** @var DataRetentionSettings $response */
        $response = $analyticsAdminServiceClient->getDataRetentionSettings($formattedName);
        printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString());
    } catch (ApiException $ex) {
        printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage());
    }
}

/**
 * This sample has been automatically generated and should be regarded as a code
 * template only. It will require modifications to work:
 *  - It may require correct/in-range values for request initialization.
 *  - It may require specifying regional endpoints when creating the service client,
 *    please see the apiEndpoint client configuration option for more details.
 */
function callSample(): void
{
    $formattedName = AnalyticsAdminServiceClient::dataRetentionSettingsName('[PROPERTY]');

    get_data_retention_settings_sample($formattedName);
}

getDataSharingSettings

Get data sharing settings on an account.

Data sharing settings are singletons.

Parameters
NameDescription
name string

Required. The name of the settings to lookup. Format: accounts/{account}/dataSharingSettings Example: "accounts/1000/dataSharingSettings"

optionalArgs array

Optional.

↳ retrySettings RetrySettings|array

Retry settings to use for this call. Can be a Google\ApiCore\RetrySettings object, or an associative array of retry settings parameters. See the documentation on Google\ApiCore\RetrySettings for example usage.

Returns
TypeDescription
Google\Analytics\Admin\V1beta\DataSharingSettings
Example
use Google\Analytics\Admin\V1beta\AnalyticsAdminServiceClient;
use Google\Analytics\Admin\V1beta\DataSharingSettings;
use Google\ApiCore\ApiException;

/**
 * @param string $formattedName The name of the settings to lookup.
 *                              Format: accounts/{account}/dataSharingSettings
 *                              Example: "accounts/1000/dataSharingSettings"
 *                              Please see {@see AnalyticsAdminServiceClient::dataSharingSettingsName()} for help formatting this field.
 */
function get_data_sharing_settings_sample(string $formattedName): void
{
    // Create a client.
    $analyticsAdminServiceClient = new AnalyticsAdminServiceClient();

    // Call the API and handle any network failures.
    try {
        /** @var DataSharingSettings $response */
        $response = $analyticsAdminServiceClient->getDataSharingSettings($formattedName);
        printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString());
    } catch (ApiException $ex) {
        printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage());
    }
}

/**
 * This sample has been automatically generated and should be regarded as a code
 * template only. It will require modifications to work:
 *  - It may require correct/in-range values for request initialization.
 *  - It may require specifying regional endpoints when creating the service client,
 *    please see the apiEndpoint client configuration option for more details.
 */
function callSample(): void
{
    $formattedName = AnalyticsAdminServiceClient::dataSharingSettingsName('[ACCOUNT]');

    get_data_sharing_settings_sample($formattedName);
}

getDataStream

Lookup for a single DataStream.

Parameters
NameDescription
name string

Required. The name of the DataStream to get. Example format: properties/1234/dataStreams/5678

optionalArgs array

Optional.

↳ retrySettings RetrySettings|array

Retry settings to use for this call. Can be a Google\ApiCore\RetrySettings object, or an associative array of retry settings parameters. See the documentation on Google\ApiCore\RetrySettings for example usage.

Returns
TypeDescription
Google\Analytics\Admin\V1beta\DataStream
Example
use Google\Analytics\Admin\V1beta\AnalyticsAdminServiceClient;
use Google\Analytics\Admin\V1beta\DataStream;
use Google\ApiCore\ApiException;

/**
 * @param string $formattedName The name of the DataStream to get.
 *                              Example format: properties/1234/dataStreams/5678
 *                              Please see {@see AnalyticsAdminServiceClient::dataStreamName()} for help formatting this field.
 */
function get_data_stream_sample(string $formattedName): void
{
    // Create a client.
    $analyticsAdminServiceClient = new AnalyticsAdminServiceClient();

    // Call the API and handle any network failures.
    try {
        /** @var DataStream $response */
        $response = $analyticsAdminServiceClient->getDataStream($formattedName);
        printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString());
    } catch (ApiException $ex) {
        printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage());
    }
}

/**
 * This sample has been automatically generated and should be regarded as a code
 * template only. It will require modifications to work:
 *  - It may require correct/in-range values for request initialization.
 *  - It may require specifying regional endpoints when creating the service client,
 *    please see the apiEndpoint client configuration option for more details.
 */
function callSample(): void
{
    $formattedName = AnalyticsAdminServiceClient::dataStreamName('[PROPERTY]', '[DATA_STREAM]');

    get_data_stream_sample($formattedName);
}

getMeasurementProtocolSecret

Lookup for a single "GA4" MeasurementProtocolSecret.

Parameters
NameDescription
name string

Required. The name of the measurement protocol secret to lookup. Format: properties/{property}/dataStreams/{dataStream}/measurementProtocolSecrets/{measurementProtocolSecret}

optionalArgs array

Optional.

↳ retrySettings RetrySettings|array

Retry settings to use for this call. Can be a Google\ApiCore\RetrySettings object, or an associative array of retry settings parameters. See the documentation on Google\ApiCore\RetrySettings for example usage.

Returns
TypeDescription
Google\Analytics\Admin\V1beta\MeasurementProtocolSecret
Example
use Google\Analytics\Admin\V1beta\AnalyticsAdminServiceClient;
use Google\Analytics\Admin\V1beta\MeasurementProtocolSecret;
use Google\ApiCore\ApiException;

/**
 * @param string $formattedName The name of the measurement protocol secret to lookup.
 *                              Format:
 *                              properties/{property}/dataStreams/{dataStream}/measurementProtocolSecrets/{measurementProtocolSecret}
 *                              Please see {@see AnalyticsAdminServiceClient::measurementProtocolSecretName()} for help formatting this field.
 */
function get_measurement_protocol_secret_sample(string $formattedName): void
{
    // Create a client.
    $analyticsAdminServiceClient = new AnalyticsAdminServiceClient();

    // Call the API and handle any network failures.
    try {
        /** @var MeasurementProtocolSecret $response */
        $response = $analyticsAdminServiceClient->getMeasurementProtocolSecret($formattedName);
        printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString());
    } catch (ApiException $ex) {
        printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage());
    }
}

/**
 * This sample has been automatically generated and should be regarded as a code
 * template only. It will require modifications to work:
 *  - It may require correct/in-range values for request initialization.
 *  - It may require specifying regional endpoints when creating the service client,
 *    please see the apiEndpoint client configuration option for more details.
 */
function callSample(): void
{
    $formattedName = AnalyticsAdminServiceClient::measurementProtocolSecretName(
        '[PROPERTY]',
        '[DATA_STREAM]',
        '[MEASUREMENT_PROTOCOL_SECRET]'
    );

    get_measurement_protocol_secret_sample($formattedName);
}

getProperty

Lookup for a single "GA4" Property.

Parameters
NameDescription
name string

Required. The name of the property to lookup. Format: properties/{property_id} Example: "properties/1000"

optionalArgs array

Optional.

↳ retrySettings RetrySettings|array

Retry settings to use for this call. Can be a Google\ApiCore\RetrySettings object, or an associative array of retry settings parameters. See the documentation on Google\ApiCore\RetrySettings for example usage.

Returns
TypeDescription
Google\Analytics\Admin\V1beta\Property
Example
use Google\Analytics\Admin\V1beta\AnalyticsAdminServiceClient;
use Google\Analytics\Admin\V1beta\Property;
use Google\ApiCore\ApiException;

/**
 * @param string $formattedName The name of the property to lookup.
 *                              Format: properties/{property_id}
 *                              Example: "properties/1000"
 *                              Please see {@see AnalyticsAdminServiceClient::propertyName()} for help formatting this field.
 */
function get_property_sample(string $formattedName): void
{
    // Create a client.
    $analyticsAdminServiceClient = new AnalyticsAdminServiceClient();

    // Call the API and handle any network failures.
    try {
        /** @var Property $response */
        $response = $analyticsAdminServiceClient->getProperty($formattedName);
        printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString());
    } catch (ApiException $ex) {
        printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage());
    }
}

/**
 * This sample has been automatically generated and should be regarded as a code
 * template only. It will require modifications to work:
 *  - It may require correct/in-range values for request initialization.
 *  - It may require specifying regional endpoints when creating the service client,
 *    please see the apiEndpoint client configuration option for more details.
 */
function callSample(): void
{
    $formattedName = AnalyticsAdminServiceClient::propertyName('[PROPERTY]');

    get_property_sample($formattedName);
}

listAccountSummaries

Returns summaries of all accounts accessible by the caller.

Parameters
NameDescription
optionalArgs array

Optional.

↳ pageSize int

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.

↳ pageToken string

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.

↳ retrySettings RetrySettings|array

Retry settings to use for this call. Can be a Google\ApiCore\RetrySettings object, or an associative array of retry settings parameters. See the documentation on Google\ApiCore\RetrySettings for example usage.

Returns
TypeDescription
Google\ApiCore\PagedListResponse
Example
use Google\Analytics\Admin\V1beta\AccountSummary;
use Google\Analytics\Admin\V1beta\AnalyticsAdminServiceClient;
use Google\ApiCore\ApiException;
use Google\ApiCore\PagedListResponse;

/**
 * This sample has been automatically generated and should be regarded as a code
 * template only. It will require modifications to work:
 *  - It may require correct/in-range values for request initialization.
 *  - It may require specifying regional endpoints when creating the service client,
 *    please see the apiEndpoint client configuration option for more details.
 */
function list_account_summaries_sample(): void
{
    // Create a client.
    $analyticsAdminServiceClient = new AnalyticsAdminServiceClient();

    // Call the API and handle any network failures.
    try {
        /** @var PagedListResponse $response */
        $response = $analyticsAdminServiceClient->listAccountSummaries();

        /** @var AccountSummary $element */
        foreach ($response as $element) {
            printf('Element data: %s' . PHP_EOL, $element->serializeToJsonString());
        }
    } catch (ApiException $ex) {
        printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage());
    }
}

listAccounts

Returns all accounts accessible by the caller.

Note that these accounts might not currently have GA4 properties. Soft-deleted (ie: "trashed") accounts are excluded by default. Returns an empty list if no relevant accounts are found.

Parameters
NameDescription
optionalArgs array

Optional.

↳ pageSize int

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.

↳ pageToken string

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.

↳ showDeleted bool

Whether to include soft-deleted (ie: "trashed") Accounts in the results. Accounts can be inspected to determine whether they are deleted or not.

↳ retrySettings RetrySettings|array

Retry settings to use for this call. Can be a Google\ApiCore\RetrySettings object, or an associative array of retry settings parameters. See the documentation on Google\ApiCore\RetrySettings for example usage.

Returns
TypeDescription
Google\ApiCore\PagedListResponse
Example
use Google\Analytics\Admin\V1beta\Account;
use Google\Analytics\Admin\V1beta\AnalyticsAdminServiceClient;
use Google\ApiCore\ApiException;
use Google\ApiCore\PagedListResponse;

/**
 * This sample has been automatically generated and should be regarded as a code
 * template only. It will require modifications to work:
 *  - It may require correct/in-range values for request initialization.
 *  - It may require specifying regional endpoints when creating the service client,
 *    please see the apiEndpoint client configuration option for more details.
 */
function list_accounts_sample(): void
{
    // Create a client.
    $analyticsAdminServiceClient = new AnalyticsAdminServiceClient();

    // Call the API and handle any network failures.
    try {
        /** @var PagedListResponse $response */
        $response = $analyticsAdminServiceClient->listAccounts();

        /** @var Account $element */
        foreach ($response as $element) {
            printf('Element data: %s' . PHP_EOL, $element->serializeToJsonString());
        }
    } catch (ApiException $ex) {
        printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage());
    }
}

listConversionEvents

Returns a list of conversion events in the specified parent property.

Returns an empty list if no conversion events are found.

Parameters
NameDescription
parent string

Required. The resource name of the parent property. Example: 'properties/123'

optionalArgs array

Optional.

↳ pageSize int

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.

↳ pageToken string

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.

↳ retrySettings RetrySettings|array

Retry settings to use for this call. Can be a Google\ApiCore\RetrySettings object, or an associative array of retry settings parameters. See the documentation on Google\ApiCore\RetrySettings for example usage.

Returns
TypeDescription
Google\ApiCore\PagedListResponse
Example
use Google\Analytics\Admin\V1beta\AnalyticsAdminServiceClient;
use Google\Analytics\Admin\V1beta\ConversionEvent;
use Google\ApiCore\ApiException;
use Google\ApiCore\PagedListResponse;

/**
 * @param string $formattedParent The resource name of the parent property.
 *                                Example: 'properties/123'
 *                                Please see {@see AnalyticsAdminServiceClient::propertyName()} for help formatting this field.
 */
function list_conversion_events_sample(string $formattedParent): void
{
    // Create a client.
    $analyticsAdminServiceClient = new AnalyticsAdminServiceClient();

    // Call the API and handle any network failures.
    try {
        /** @var PagedListResponse $response */
        $response = $analyticsAdminServiceClient->listConversionEvents($formattedParent);

        /** @var ConversionEvent $element */
        foreach ($response as $element) {
            printf('Element data: %s' . PHP_EOL, $element->serializeToJsonString());
        }
    } catch (ApiException $ex) {
        printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage());
    }
}

/**
 * This sample has been automatically generated and should be regarded as a code
 * template only. It will require modifications to work:
 *  - It may require correct/in-range values for request initialization.
 *  - It may require specifying regional endpoints when creating the service client,
 *    please see the apiEndpoint client configuration option for more details.
 */
function callSample(): void
{
    $formattedParent = AnalyticsAdminServiceClient::propertyName('[PROPERTY]');

    list_conversion_events_sample($formattedParent);
}

listCustomDimensions

Lists CustomDimensions on a property.

Parameters
NameDescription
parent string

Required. Example format: properties/1234

optionalArgs array

Optional.

↳ pageSize int

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.

↳ pageToken string

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.

↳ retrySettings RetrySettings|array

Retry settings to use for this call. Can be a Google\ApiCore\RetrySettings object, or an associative array of retry settings parameters. See the documentation on Google\ApiCore\RetrySettings for example usage.

Returns
TypeDescription
Google\ApiCore\PagedListResponse
Example
use Google\Analytics\Admin\V1beta\AnalyticsAdminServiceClient;
use Google\Analytics\Admin\V1beta\CustomDimension;
use Google\ApiCore\ApiException;
use Google\ApiCore\PagedListResponse;

/**
 * @param string $formattedParent Example format: properties/1234
 *                                Please see {@see AnalyticsAdminServiceClient::propertyName()} for help formatting this field.
 */
function list_custom_dimensions_sample(string $formattedParent): void
{
    // Create a client.
    $analyticsAdminServiceClient = new AnalyticsAdminServiceClient();

    // Call the API and handle any network failures.
    try {
        /** @var PagedListResponse $response */
        $response = $analyticsAdminServiceClient->listCustomDimensions($formattedParent);

        /** @var CustomDimension $element */
        foreach ($response as $element) {
            printf('Element data: %s' . PHP_EOL, $element->serializeToJsonString());
        }
    } catch (ApiException $ex) {
        printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage());
    }
}

/**
 * This sample has been automatically generated and should be regarded as a code
 * template only. It will require modifications to work:
 *  - It may require correct/in-range values for request initialization.
 *  - It may require specifying regional endpoints when creating the service client,
 *    please see the apiEndpoint client configuration option for more details.
 */
function callSample(): void
{
    $formattedParent = AnalyticsAdminServiceClient::propertyName('[PROPERTY]');

    list_custom_dimensions_sample($formattedParent);
}

listCustomMetrics

Lists CustomMetrics on a property.

Parameters
NameDescription
parent string

Required. Example format: properties/1234

optionalArgs array

Optional.

↳ pageSize int

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.

↳ pageToken string

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.

↳ retrySettings RetrySettings|array

Retry settings to use for this call. Can be a Google\ApiCore\RetrySettings object, or an associative array of retry settings parameters. See the documentation on Google\ApiCore\RetrySettings for example usage.

Returns
TypeDescription
Google\ApiCore\PagedListResponse
Example
use Google\Analytics\Admin\V1beta\AnalyticsAdminServiceClient;
use Google\Analytics\Admin\V1beta\CustomMetric;
use Google\ApiCore\ApiException;
use Google\ApiCore\PagedListResponse;

/**
 * @param string $formattedParent Example format: properties/1234
 *                                Please see {@see AnalyticsAdminServiceClient::propertyName()} for help formatting this field.
 */
function list_custom_metrics_sample(string $formattedParent): void
{
    // Create a client.
    $analyticsAdminServiceClient = new AnalyticsAdminServiceClient();

    // Call the API and handle any network failures.
    try {
        /** @var PagedListResponse $response */
        $response = $analyticsAdminServiceClient->listCustomMetrics($formattedParent);

        /** @var CustomMetric $element */
        foreach ($response as $element) {
            printf('Element data: %s' . PHP_EOL, $element->serializeToJsonString());
        }
    } catch (ApiException $ex) {
        printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage());
    }
}

/**
 * This sample has been automatically generated and should be regarded as a code
 * template only. It will require modifications to work:
 *  - It may require correct/in-range values for request initialization.
 *  - It may require specifying regional endpoints when creating the service client,
 *    please see the apiEndpoint client configuration option for more details.
 */
function callSample(): void
{
    $formattedParent = AnalyticsAdminServiceClient::propertyName('[PROPERTY]');

    list_custom_metrics_sample($formattedParent);
}

listDataStreams

Lists DataStreams on a property.

Parameters
NameDescription
parent string

Required. Example format: properties/1234

optionalArgs array

Optional.

↳ pageSize int

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.

↳ pageToken string

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.

↳ retrySettings RetrySettings|array

Retry settings to use for this call. Can be a Google\ApiCore\RetrySettings object, or an associative array of retry settings parameters. See the documentation on Google\ApiCore\RetrySettings for example usage.

Returns
TypeDescription
Google\ApiCore\PagedListResponse
Example
use Google\Analytics\Admin\V1beta\AnalyticsAdminServiceClient;
use Google\Analytics\Admin\V1beta\DataStream;
use Google\ApiCore\ApiException;
use Google\ApiCore\PagedListResponse;

/**
 * @param string $formattedParent Example format: properties/1234
 *                                Please see {@see AnalyticsAdminServiceClient::propertyName()} for help formatting this field.
 */
function list_data_streams_sample(string $formattedParent): void
{
    // Create a client.
    $analyticsAdminServiceClient = new AnalyticsAdminServiceClient();

    // Call the API and handle any network failures.
    try {
        /** @var PagedListResponse $response */
        $response = $analyticsAdminServiceClient->listDataStreams($formattedParent);

        /** @var DataStream $element */
        foreach ($response as $element) {
            printf('Element data: %s' . PHP_EOL, $element->serializeToJsonString());
        }
    } catch (ApiException $ex) {
        printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage());
    }
}

/**
 * This sample has been automatically generated and should be regarded as a code
 * template only. It will require modifications to work:
 *  - It may require correct/in-range values for request initialization.
 *  - It may require specifying regional endpoints when creating the service client,
 *    please see the apiEndpoint client configuration option for more details.
 */
function callSample(): void
{
    $formattedParent = AnalyticsAdminServiceClient::propertyName('[PROPERTY]');

    list_data_streams_sample($formattedParent);
}

Lists FirebaseLinks on a property.

Properties can have at most one FirebaseLink.

Parameters
NameDescription
parent string

Required. Format: properties/{property_id} Example: properties/1234

optionalArgs array

Optional.

↳ pageSize int

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.

↳ pageToken string

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.

↳ retrySettings RetrySettings|array

Retry settings to use for this call. Can be a Google\ApiCore\RetrySettings object, or an associative array of retry settings parameters. See the documentation on Google\ApiCore\RetrySettings for example usage.

Returns
TypeDescription
Google\ApiCore\PagedListResponse
Example
use Google\Analytics\Admin\V1beta\AnalyticsAdminServiceClient;
use Google\Analytics\Admin\V1beta\FirebaseLink;
use Google\ApiCore\ApiException;
use Google\ApiCore\PagedListResponse;

/**
 * @param string $formattedParent Format: properties/{property_id}
 *                                Example: properties/1234
 *                                Please see {@see AnalyticsAdminServiceClient::propertyName()} for help formatting this field.
 */
function list_firebase_links_sample(string $formattedParent): void
{
    // Create a client.
    $analyticsAdminServiceClient = new AnalyticsAdminServiceClient();

    // Call the API and handle any network failures.
    try {
        /** @var PagedListResponse $response */
        $response = $analyticsAdminServiceClient->listFirebaseLinks($formattedParent);

        /** @var FirebaseLink $element */
        foreach ($response as $element) {
            printf('Element data: %s' . PHP_EOL, $element->serializeToJsonString());
        }
    } catch (ApiException $ex) {
        printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage());
    }
}

/**
 * This sample has been automatically generated and should be regarded as a code
 * template only. It will require modifications to work:
 *  - It may require correct/in-range values for request initialization.
 *  - It may require specifying regional endpoints when creating the service client,
 *    please see the apiEndpoint client configuration option for more details.
 */
function callSample(): void
{
    $formattedParent = AnalyticsAdminServiceClient::propertyName('[PROPERTY]');

    list_firebase_links_sample($formattedParent);
}

Lists GoogleAdsLinks on a property.

Parameters
NameDescription
parent string

Required. Example format: properties/1234

optionalArgs array

Optional.

↳ pageSize int

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.

↳ pageToken string

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.

↳ retrySettings RetrySettings|array

Retry settings to use for this call. Can be a Google\ApiCore\RetrySettings object, or an associative array of retry settings parameters. See the documentation on Google\ApiCore\RetrySettings for example usage.

Returns
TypeDescription
Google\ApiCore\PagedListResponse
Example
use Google\Analytics\Admin\V1beta\AnalyticsAdminServiceClient;
use Google\Analytics\Admin\V1beta\GoogleAdsLink;
use Google\ApiCore\ApiException;
use Google\ApiCore\PagedListResponse;

/**
 * @param string $formattedParent Example format: properties/1234
 *                                Please see {@see AnalyticsAdminServiceClient::propertyName()} for help formatting this field.
 */
function list_google_ads_links_sample(string $formattedParent): void
{
    // Create a client.
    $analyticsAdminServiceClient = new AnalyticsAdminServiceClient();

    // Call the API and handle any network failures.
    try {
        /** @var PagedListResponse $response */
        $response = $analyticsAdminServiceClient->listGoogleAdsLinks($formattedParent);

        /** @var GoogleAdsLink $element */
        foreach ($response as $element) {
            printf('Element data: %s' . PHP_EOL, $element->serializeToJsonString());
        }
    } catch (ApiException $ex) {
        printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage());
    }
}

/**
 * This sample has been automatically generated and should be regarded as a code
 * template only. It will require modifications to work:
 *  - It may require correct/in-range values for request initialization.
 *  - It may require specifying regional endpoints when creating the service client,
 *    please see the apiEndpoint client configuration option for more details.
 */
function callSample(): void
{
    $formattedParent = AnalyticsAdminServiceClient::propertyName('[PROPERTY]');

    list_google_ads_links_sample($formattedParent);
}

listMeasurementProtocolSecrets

Returns child MeasurementProtocolSecrets under the specified parent Property.

Parameters
NameDescription
parent string

Required. The resource name of the parent stream. Format: properties/{property}/dataStreams/{dataStream}/measurementProtocolSecrets

optionalArgs array

Optional.

↳ pageSize int

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.

↳ pageToken string

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.

↳ retrySettings RetrySettings|array

Retry settings to use for this call. Can be a Google\ApiCore\RetrySettings object, or an associative array of retry settings parameters. See the documentation on Google\ApiCore\RetrySettings for example usage.

Returns
TypeDescription
Google\ApiCore\PagedListResponse
Example
use Google\Analytics\Admin\V1beta\AnalyticsAdminServiceClient;
use Google\Analytics\Admin\V1beta\MeasurementProtocolSecret;
use Google\ApiCore\ApiException;
use Google\ApiCore\PagedListResponse;

/**
 * @param string $formattedParent The resource name of the parent stream.
 *                                Format:
 *                                properties/{property}/dataStreams/{dataStream}/measurementProtocolSecrets
 *                                Please see {@see AnalyticsAdminServiceClient::dataStreamName()} for help formatting this field.
 */
function list_measurement_protocol_secrets_sample(string $formattedParent): void
{
    // Create a client.
    $analyticsAdminServiceClient = new AnalyticsAdminServiceClient();

    // Call the API and handle any network failures.
    try {
        /** @var PagedListResponse $response */
        $response = $analyticsAdminServiceClient->listMeasurementProtocolSecrets($formattedParent);

        /** @var MeasurementProtocolSecret $element */
        foreach ($response as $element) {
            printf('Element data: %s' . PHP_EOL, $element->serializeToJsonString());
        }
    } catch (ApiException $ex) {
        printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage());
    }
}

/**
 * This sample has been automatically generated and should be regarded as a code
 * template only. It will require modifications to work:
 *  - It may require correct/in-range values for request initialization.
 *  - It may require specifying regional endpoints when creating the service client,
 *    please see the apiEndpoint client configuration option for more details.
 */
function callSample(): void
{
    $formattedParent = AnalyticsAdminServiceClient::dataStreamName('[PROPERTY]', '[DATA_STREAM]');

    list_measurement_protocol_secrets_sample($formattedParent);
}

listProperties

Returns child Properties under the specified parent Account.

Only "GA4" properties will be returned. Properties will be excluded if the caller does not have access. Soft-deleted (ie: "trashed") properties are excluded by default. Returns an empty list if no relevant properties are found.

Parameters
NameDescription
filter string

Required. An expression for filtering the results of the request. Fields eligible for filtering are: parent:(The resource name of the parent account/property) or ancestor:(The resource name of the parent account) or firebase_project:(The id or number of the linked firebase project). Some examples of filters:

| Filter                      | Description                               |
|-----------------------------|-------------------------------------------|
| parent:accounts/123         | The account with account id: 123.       |
| parent:properties/123       | The property with property id: 123.       |
| ancestor:accounts/123       | The account with account id: 123.         |
| firebase_project:project-id | The firebase project with id: project-id. |
| firebase_project:123        | The firebase project with number: 123.    |
optionalArgs array

Optional.

↳ pageSize int

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.

↳ pageToken string

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.

↳ showDeleted bool

Whether to include soft-deleted (ie: "trashed") Properties in the results. Properties can be inspected to determine whether they are deleted or not.

↳ retrySettings RetrySettings|array

Retry settings to use for this call. Can be a Google\ApiCore\RetrySettings object, or an associative array of retry settings parameters. See the documentation on Google\ApiCore\RetrySettings for example usage.

Returns
TypeDescription
Google\ApiCore\PagedListResponse
Example
use Google\Analytics\Admin\V1beta\AnalyticsAdminServiceClient;
use Google\Analytics\Admin\V1beta\Property;
use Google\ApiCore\ApiException;
use Google\ApiCore\PagedListResponse;

/**
 * @param string $filter An expression for filtering the results of the request.
 *                       Fields eligible for filtering are:
 *                       `parent:`(The resource name of the parent account/property) or
 *                       `ancestor:`(The resource name of the parent account) or
 *                       `firebase_project:`(The id or number of the linked firebase project).
 *                       Some examples of filters:
 *
 *                       ```
 *                       | Filter                      | Description                               |
 *                       |-----------------------------|-------------------------------------------|
 *                       | parent:accounts/123         | The account with account id: 123.       |
 *                       | parent:properties/123       | The property with property id: 123.       |
 *                       | ancestor:accounts/123       | The account with account id: 123.         |
 *                       | firebase_project:project-id | The firebase project with id: project-id. |
 *                       | firebase_project:123        | The firebase project with number: 123.    |
 *                       ```
 */
function list_properties_sample(string $filter): void
{
    // Create a client.
    $analyticsAdminServiceClient = new AnalyticsAdminServiceClient();

    // Call the API and handle any network failures.
    try {
        /** @var PagedListResponse $response */
        $response = $analyticsAdminServiceClient->listProperties($filter);

        /** @var Property $element */
        foreach ($response as $element) {
            printf('Element data: %s' . PHP_EOL, $element->serializeToJsonString());
        }
    } catch (ApiException $ex) {
        printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage());
    }
}

/**
 * This sample has been automatically generated and should be regarded as a code
 * template only. It will require modifications to work:
 *  - It may require correct/in-range values for request initialization.
 *  - It may require specifying regional endpoints when creating the service client,
 *    please see the apiEndpoint client configuration option for more details.
 */
function callSample(): void
{
    $filter = '[FILTER]';

    list_properties_sample($filter);
}

provisionAccountTicket

Requests a ticket for creating an account.

Parameters
NameDescription
optionalArgs array

Optional.

↳ account Account

The account to create.

↳ redirectUri string

Redirect URI where the user will be sent after accepting Terms of Service. Must be configured in Developers Console as a Redirect URI

↳ retrySettings RetrySettings|array

Retry settings to use for this call. Can be a Google\ApiCore\RetrySettings object, or an associative array of retry settings parameters. See the documentation on Google\ApiCore\RetrySettings for example usage.

Returns
TypeDescription
Google\Analytics\Admin\V1beta\ProvisionAccountTicketResponse
Example
use Google\Analytics\Admin\V1beta\AnalyticsAdminServiceClient;
use Google\Analytics\Admin\V1beta\ProvisionAccountTicketResponse;
use Google\ApiCore\ApiException;

/**
 * This sample has been automatically generated and should be regarded as a code
 * template only. It will require modifications to work:
 *  - It may require correct/in-range values for request initialization.
 *  - It may require specifying regional endpoints when creating the service client,
 *    please see the apiEndpoint client configuration option for more details.
 */
function provision_account_ticket_sample(): void
{
    // Create a client.
    $analyticsAdminServiceClient = new AnalyticsAdminServiceClient();

    // Call the API and handle any network failures.
    try {
        /** @var ProvisionAccountTicketResponse $response */
        $response = $analyticsAdminServiceClient->provisionAccountTicket();
        printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString());
    } catch (ApiException $ex) {
        printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage());
    }
}

searchChangeHistoryEvents

Searches through all changes to an account or its children given the specified set of filters.

Parameters
NameDescription
account string

Required. The account resource for which to return change history resources.

optionalArgs array

Optional.

↳ property string

Optional. Resource name for a child property. If set, only return changes made to this property or its child resources.

↳ resourceType int[]

Optional. If set, only return changes if they are for a resource that matches at least one of these types. For allowed values, use constants defined on Google\Analytics\Admin\V1beta\ChangeHistoryResourceType

↳ action int[]

Optional. If set, only return changes that match one or more of these types of actions. For allowed values, use constants defined on Google\Analytics\Admin\V1beta\ActionType

↳ actorEmail string[]

Optional. If set, only return changes if they are made by a user in this list.

↳ earliestChangeTime Timestamp

Optional. If set, only return changes made after this time (inclusive).

↳ latestChangeTime Timestamp

Optional. If set, only return changes made before this time (inclusive).

↳ pageSize int

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.

↳ pageToken string

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.

↳ retrySettings RetrySettings|array

Retry settings to use for this call. Can be a Google\ApiCore\RetrySettings object, or an associative array of retry settings parameters. See the documentation on Google\ApiCore\RetrySettings for example usage.

Returns
TypeDescription
Google\ApiCore\PagedListResponse
Example
use Google\Analytics\Admin\V1beta\AnalyticsAdminServiceClient;
use Google\Analytics\Admin\V1beta\ChangeHistoryEvent;
use Google\ApiCore\ApiException;
use Google\ApiCore\PagedListResponse;

/**
 * @param string $formattedAccount The account resource for which to return change history resources. Please see
 *                                 {@see AnalyticsAdminServiceClient::accountName()} for help formatting this field.
 */
function search_change_history_events_sample(string $formattedAccount): void
{
    // Create a client.
    $analyticsAdminServiceClient = new AnalyticsAdminServiceClient();

    // Call the API and handle any network failures.
    try {
        /** @var PagedListResponse $response */
        $response = $analyticsAdminServiceClient->searchChangeHistoryEvents($formattedAccount);

        /** @var ChangeHistoryEvent $element */
        foreach ($response as $element) {
            printf('Element data: %s' . PHP_EOL, $element->serializeToJsonString());
        }
    } catch (ApiException $ex) {
        printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage());
    }
}

/**
 * This sample has been automatically generated and should be regarded as a code
 * template only. It will require modifications to work:
 *  - It may require correct/in-range values for request initialization.
 *  - It may require specifying regional endpoints when creating the service client,
 *    please see the apiEndpoint client configuration option for more details.
 */
function callSample(): void
{
    $formattedAccount = AnalyticsAdminServiceClient::accountName('[ACCOUNT]');

    search_change_history_events_sample($formattedAccount);
}

updateAccount

Updates an account.

Parameters
NameDescription
account Google\Analytics\Admin\V1beta\Account

Required. The account to update. The account's name field is used to identify the account.

updateMask Google\Protobuf\FieldMask

Required. The list of fields to be updated. Field names must be in snake case (e.g., "field_to_update"). Omitted fields will not be updated. To replace the entire entity, use one path with the string "*" to match all fields.

optionalArgs array

Optional.

↳ retrySettings RetrySettings|array

Retry settings to use for this call. Can be a Google\ApiCore\RetrySettings object, or an associative array of retry settings parameters. See the documentation on Google\ApiCore\RetrySettings for example usage.

Returns
TypeDescription
Google\Analytics\Admin\V1beta\Account
Example
use Google\Analytics\Admin\V1beta\Account;
use Google\Analytics\Admin\V1beta\AnalyticsAdminServiceClient;
use Google\ApiCore\ApiException;
use Google\Protobuf\FieldMask;

/**
 * @param string $accountDisplayName Human-readable display name for this account.
 */
function update_account_sample(string $accountDisplayName): void
{
    // Create a client.
    $analyticsAdminServiceClient = new AnalyticsAdminServiceClient();

    // Prepare any non-scalar elements to be passed along with the request.
    $account = (new Account())
        ->setDisplayName($accountDisplayName);
    $updateMask = new FieldMask();

    // Call the API and handle any network failures.
    try {
        /** @var Account $response */
        $response = $analyticsAdminServiceClient->updateAccount($account, $updateMask);
        printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString());
    } catch (ApiException $ex) {
        printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage());
    }
}

/**
 * This sample has been automatically generated and should be regarded as a code
 * template only. It will require modifications to work:
 *  - It may require correct/in-range values for request initialization.
 *  - It may require specifying regional endpoints when creating the service client,
 *    please see the apiEndpoint client configuration option for more details.
 */
function callSample(): void
{
    $accountDisplayName = '[DISPLAY_NAME]';

    update_account_sample($accountDisplayName);
}

updateCustomDimension

Updates a CustomDimension on a property.

Parameters
NameDescription
updateMask Google\Protobuf\FieldMask

Required. The list of fields to be updated. Omitted fields will not be updated. To replace the entire entity, use one path with the string "*" to match all fields.

optionalArgs array

Optional.

↳ customDimension CustomDimension

The CustomDimension to update

↳ retrySettings RetrySettings|array

Retry settings to use for this call. Can be a Google\ApiCore\RetrySettings object, or an associative array of retry settings parameters. See the documentation on Google\ApiCore\RetrySettings for example usage.

Returns
TypeDescription
Google\Analytics\Admin\V1beta\CustomDimension
Example
use Google\Analytics\Admin\V1beta\AnalyticsAdminServiceClient;
use Google\Analytics\Admin\V1beta\CustomDimension;
use Google\ApiCore\ApiException;
use Google\Protobuf\FieldMask;

/**
 * This sample has been automatically generated and should be regarded as a code
 * template only. It will require modifications to work:
 *  - It may require correct/in-range values for request initialization.
 *  - It may require specifying regional endpoints when creating the service client,
 *    please see the apiEndpoint client configuration option for more details.
 */
function update_custom_dimension_sample(): void
{
    // Create a client.
    $analyticsAdminServiceClient = new AnalyticsAdminServiceClient();

    // Prepare any non-scalar elements to be passed along with the request.
    $updateMask = new FieldMask();

    // Call the API and handle any network failures.
    try {
        /** @var CustomDimension $response */
        $response = $analyticsAdminServiceClient->updateCustomDimension($updateMask);
        printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString());
    } catch (ApiException $ex) {
        printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage());
    }
}

updateCustomMetric

Updates a CustomMetric on a property.

Parameters
NameDescription
updateMask Google\Protobuf\FieldMask

Required. The list of fields to be updated. Omitted fields will not be updated. To replace the entire entity, use one path with the string "*" to match all fields.

optionalArgs array

Optional.

↳ customMetric CustomMetric

The CustomMetric to update

↳ retrySettings RetrySettings|array

Retry settings to use for this call. Can be a Google\ApiCore\RetrySettings object, or an associative array of retry settings parameters. See the documentation on Google\ApiCore\RetrySettings for example usage.

Returns
TypeDescription
Google\Analytics\Admin\V1beta\CustomMetric
Example
use Google\Analytics\Admin\V1beta\AnalyticsAdminServiceClient;
use Google\Analytics\Admin\V1beta\CustomMetric;
use Google\ApiCore\ApiException;
use Google\Protobuf\FieldMask;

/**
 * This sample has been automatically generated and should be regarded as a code
 * template only. It will require modifications to work:
 *  - It may require correct/in-range values for request initialization.
 *  - It may require specifying regional endpoints when creating the service client,
 *    please see the apiEndpoint client configuration option for more details.
 */
function update_custom_metric_sample(): void
{
    // Create a client.
    $analyticsAdminServiceClient = new AnalyticsAdminServiceClient();

    // Prepare any non-scalar elements to be passed along with the request.
    $updateMask = new FieldMask();

    // Call the API and handle any network failures.
    try {
        /** @var CustomMetric $response */
        $response = $analyticsAdminServiceClient->updateCustomMetric($updateMask);
        printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString());
    } catch (ApiException $ex) {
        printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage());
    }
}

updateDataRetentionSettings

Updates the singleton data retention settings for this property.

Parameters
NameDescription
dataRetentionSettings Google\Analytics\Admin\V1beta\DataRetentionSettings

Required. The settings to update. The name field is used to identify the settings to be updated.

updateMask Google\Protobuf\FieldMask

Required. The list of fields to be updated. Field names must be in snake case (e.g., "field_to_update"). Omitted fields will not be updated. To replace the entire entity, use one path with the string "*" to match all fields.

optionalArgs array

Optional.

↳ retrySettings RetrySettings|array

Retry settings to use for this call. Can be a Google\ApiCore\RetrySettings object, or an associative array of retry settings parameters. See the documentation on Google\ApiCore\RetrySettings for example usage.

Returns
TypeDescription
Google\Analytics\Admin\V1beta\DataRetentionSettings
Example
use Google\Analytics\Admin\V1beta\AnalyticsAdminServiceClient;
use Google\Analytics\Admin\V1beta\DataRetentionSettings;
use Google\ApiCore\ApiException;
use Google\Protobuf\FieldMask;

/**
 * This sample has been automatically generated and should be regarded as a code
 * template only. It will require modifications to work:
 *  - It may require correct/in-range values for request initialization.
 *  - It may require specifying regional endpoints when creating the service client,
 *    please see the apiEndpoint client configuration option for more details.
 */
function update_data_retention_settings_sample(): void
{
    // Create a client.
    $analyticsAdminServiceClient = new AnalyticsAdminServiceClient();

    // Prepare any non-scalar elements to be passed along with the request.
    $dataRetentionSettings = new DataRetentionSettings();
    $updateMask = new FieldMask();

    // Call the API and handle any network failures.
    try {
        /** @var DataRetentionSettings $response */
        $response = $analyticsAdminServiceClient->updateDataRetentionSettings(
            $dataRetentionSettings,
            $updateMask
        );
        printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString());
    } catch (ApiException $ex) {
        printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage());
    }
}

updateDataStream

Updates a DataStream on a property.

Parameters
NameDescription
updateMask Google\Protobuf\FieldMask

Required. The list of fields to be updated. Omitted fields will not be updated. To replace the entire entity, use one path with the string "*" to match all fields.

optionalArgs array

Optional.

↳ dataStream DataStream

The DataStream to update

↳ retrySettings RetrySettings|array

Retry settings to use for this call. Can be a Google\ApiCore\RetrySettings object, or an associative array of retry settings parameters. See the documentation on Google\ApiCore\RetrySettings for example usage.

Returns
TypeDescription
Google\Analytics\Admin\V1beta\DataStream
Example
use Google\Analytics\Admin\V1beta\AnalyticsAdminServiceClient;
use Google\Analytics\Admin\V1beta\DataStream;
use Google\ApiCore\ApiException;
use Google\Protobuf\FieldMask;

/**
 * This sample has been automatically generated and should be regarded as a code
 * template only. It will require modifications to work:
 *  - It may require correct/in-range values for request initialization.
 *  - It may require specifying regional endpoints when creating the service client,
 *    please see the apiEndpoint client configuration option for more details.
 */
function update_data_stream_sample(): void
{
    // Create a client.
    $analyticsAdminServiceClient = new AnalyticsAdminServiceClient();

    // Prepare any non-scalar elements to be passed along with the request.
    $updateMask = new FieldMask();

    // Call the API and handle any network failures.
    try {
        /** @var DataStream $response */
        $response = $analyticsAdminServiceClient->updateDataStream($updateMask);
        printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString());
    } catch (ApiException $ex) {
        printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage());
    }
}

Updates a GoogleAdsLink on a property

Parameters
NameDescription
updateMask Google\Protobuf\FieldMask

Required. The list of fields to be updated. Field names must be in snake case (e.g., "field_to_update"). Omitted fields will not be updated. To replace the entire entity, use one path with the string "*" to match all fields.

optionalArgs array

Optional.

↳ googleAdsLink GoogleAdsLink

The GoogleAdsLink to update

↳ retrySettings RetrySettings|array

Retry settings to use for this call. Can be a Google\ApiCore\RetrySettings object, or an associative array of retry settings parameters. See the documentation on Google\ApiCore\RetrySettings for example usage.

Returns
TypeDescription
Google\Analytics\Admin\V1beta\GoogleAdsLink
Example
use Google\Analytics\Admin\V1beta\AnalyticsAdminServiceClient;
use Google\Analytics\Admin\V1beta\GoogleAdsLink;
use Google\ApiCore\ApiException;
use Google\Protobuf\FieldMask;

/**
 * This sample has been automatically generated and should be regarded as a code
 * template only. It will require modifications to work:
 *  - It may require correct/in-range values for request initialization.
 *  - It may require specifying regional endpoints when creating the service client,
 *    please see the apiEndpoint client configuration option for more details.
 */
function update_google_ads_link_sample(): void
{
    // Create a client.
    $analyticsAdminServiceClient = new AnalyticsAdminServiceClient();

    // Prepare any non-scalar elements to be passed along with the request.
    $updateMask = new FieldMask();

    // Call the API and handle any network failures.
    try {
        /** @var GoogleAdsLink $response */
        $response = $analyticsAdminServiceClient->updateGoogleAdsLink($updateMask);
        printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString());
    } catch (ApiException $ex) {
        printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage());
    }
}

updateMeasurementProtocolSecret

Updates a measurement protocol secret.

Parameters
NameDescription
measurementProtocolSecret Google\Analytics\Admin\V1beta\MeasurementProtocolSecret

Required. The measurement protocol secret to update.

optionalArgs array

Optional.

↳ updateMask FieldMask

The list of fields to be updated. Omitted fields will not be updated.

↳ retrySettings RetrySettings|array

Retry settings to use for this call. Can be a Google\ApiCore\RetrySettings object, or an associative array of retry settings parameters. See the documentation on Google\ApiCore\RetrySettings for example usage.

Returns
TypeDescription
Google\Analytics\Admin\V1beta\MeasurementProtocolSecret
Example
use Google\Analytics\Admin\V1beta\AnalyticsAdminServiceClient;
use Google\Analytics\Admin\V1beta\MeasurementProtocolSecret;
use Google\ApiCore\ApiException;

/**
 * @param string $measurementProtocolSecretDisplayName Human-readable display name for this secret.
 */
function update_measurement_protocol_secret_sample(
    string $measurementProtocolSecretDisplayName
): void {
    // Create a client.
    $analyticsAdminServiceClient = new AnalyticsAdminServiceClient();

    // Prepare any non-scalar elements to be passed along with the request.
    $measurementProtocolSecret = (new MeasurementProtocolSecret())
        ->setDisplayName($measurementProtocolSecretDisplayName);

    // Call the API and handle any network failures.
    try {
        /** @var MeasurementProtocolSecret $response */
        $response = $analyticsAdminServiceClient->updateMeasurementProtocolSecret(
            $measurementProtocolSecret
        );
        printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString());
    } catch (ApiException $ex) {
        printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage());
    }
}

/**
 * This sample has been automatically generated and should be regarded as a code
 * template only. It will require modifications to work:
 *  - It may require correct/in-range values for request initialization.
 *  - It may require specifying regional endpoints when creating the service client,
 *    please see the apiEndpoint client configuration option for more details.
 */
function callSample(): void
{
    $measurementProtocolSecretDisplayName = '[DISPLAY_NAME]';

    update_measurement_protocol_secret_sample($measurementProtocolSecretDisplayName);
}

updateProperty

Updates a property.

Parameters
NameDescription
property Google\Analytics\Admin\V1beta\Property

Required. The property to update. The property's name field is used to identify the property to be updated.

updateMask Google\Protobuf\FieldMask

Required. The list of fields to be updated. Field names must be in snake case (e.g., "field_to_update"). Omitted fields will not be updated. To replace the entire entity, use one path with the string "*" to match all fields.

optionalArgs array

Optional.

↳ retrySettings RetrySettings|array

Retry settings to use for this call. Can be a Google\ApiCore\RetrySettings object, or an associative array of retry settings parameters. See the documentation on Google\ApiCore\RetrySettings for example usage.

Returns
TypeDescription
Google\Analytics\Admin\V1beta\Property
Example
use Google\Analytics\Admin\V1beta\AnalyticsAdminServiceClient;
use Google\Analytics\Admin\V1beta\Property;
use Google\ApiCore\ApiException;
use Google\Protobuf\FieldMask;

/**
 * @param string $propertyDisplayName Human-readable display name for this property.
 *
 *                                    The max allowed display name length is 100 UTF-16 code units.
 * @param string $propertyTimeZone    Reporting Time Zone, used as the day boundary for reports, regardless of
 *                                    where the data originates. If the time zone honors DST, Analytics will
 *                                    automatically adjust for the changes.
 *
 *                                    NOTE: Changing the time zone only affects data going forward, and is not
 *                                    applied retroactively.
 *
 *                                    Format: https://www.iana.org/time-zones
 *                                    Example: "America/Los_Angeles"
 */
function update_property_sample(string $propertyDisplayName, string $propertyTimeZone): void
{
    // Create a client.
    $analyticsAdminServiceClient = new AnalyticsAdminServiceClient();

    // Prepare any non-scalar elements to be passed along with the request.
    $property = (new Property())
        ->setDisplayName($propertyDisplayName)
        ->setTimeZone($propertyTimeZone);
    $updateMask = new FieldMask();

    // Call the API and handle any network failures.
    try {
        /** @var Property $response */
        $response = $analyticsAdminServiceClient->updateProperty($property, $updateMask);
        printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString());
    } catch (ApiException $ex) {
        printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage());
    }
}

/**
 * This sample has been automatically generated and should be regarded as a code
 * template only. It will require modifications to work:
 *  - It may require correct/in-range values for request initialization.
 *  - It may require specifying regional endpoints when creating the service client,
 *    please see the apiEndpoint client configuration option for more details.
 */
function callSample(): void
{
    $propertyDisplayName = '[DISPLAY_NAME]';
    $propertyTimeZone = '[TIME_ZONE]';

    update_property_sample($propertyDisplayName, $propertyTimeZone);
}

Constants

SERVICE_NAME

Value: 'google.analytics.admin.v1beta.AnalyticsAdminService'

The name of the service.

SERVICE_ADDRESS

Value: 'analyticsadmin.googleapis.com'

The default address of the service.

DEFAULT_SERVICE_PORT

Value: 443

The default port of the service.

CODEGEN_NAME

Value: 'gapic'

The name of the code generator, to be included in the agent header.