Reference documentation and code samples for the Google Analytics Data V1alpha Client class AlphaAnalyticsDataClient.
Service Description: Google Analytics reporting data service.
This class provides the ability to make remote calls to the backing service through method calls that map to API methods. Sample code to get started:
$alphaAnalyticsDataClient = new AlphaAnalyticsDataClient();
try {
$formattedParent = $alphaAnalyticsDataClient->propertyName('[PROPERTY]');
$audienceList = new AudienceList();
$operationResponse = $alphaAnalyticsDataClient->createAudienceList($formattedParent, $audienceList);
$operationResponse->pollUntilComplete();
if ($operationResponse->operationSucceeded()) {
$result = $operationResponse->getResult();
// doSomethingWith($result)
} else {
$error = $operationResponse->getError();
// handleError($error)
}
// Alternatively:
// start the operation, keep the operation name, and resume later
$operationResponse = $alphaAnalyticsDataClient->createAudienceList($formattedParent, $audienceList);
$operationName = $operationResponse->getName();
// ... do other work
$newOperationResponse = $alphaAnalyticsDataClient->resumeOperation($operationName, 'createAudienceList');
while (!$newOperationResponse->isDone()) {
// ... do other work
$newOperationResponse->reload();
}
if ($newOperationResponse->operationSucceeded()) {
$result = $newOperationResponse->getResult();
// doSomethingWith($result)
} else {
$error = $newOperationResponse->getError();
// handleError($error)
}
} finally {
$alphaAnalyticsDataClient->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.
Namespace
Google \ Analytics \ Data \ V1alphaMethods
__construct
Constructor.
Parameters | |
---|---|
Name | Description |
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 |
↳ 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 |
↳ 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. |
createAudienceList
Creates an audience list for later retrieval. This method quickly returns
the audience list's resource name and initiates a long running asynchronous
request to form an audience list. To list the users in an audience list,
first create the audience list through this method and then send the
audience resource name to the QueryAudienceList
method.
See Creating an Audience List for an introduction to Audience Lists with examples.
An audience list is a snapshot of the users currently in the audience at the time of audience list creation. Creating audience lists for one audience on different days will return different results as users enter and exit the audience.
Audiences in Google Analytics 4 allow you to segment your users in the ways that are important to your business. To learn more, see https://support.google.com/analytics/answer/9267572. Audience lists contain the users in each audience.
This method is available at beta stability at audienceExports.create. To give your feedback on this API, complete the Google Analytics Audience Export API Feedback form.
Parameters | |
---|---|
Name | Description |
parent |
string
Required. The parent resource where this audience list will be created.
Format: |
audienceList |
Google\Analytics\Data\V1alpha\AudienceList
Required. The audience list 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 | |
---|---|
Type | Description |
Google\ApiCore\OperationResponse |
use Google\Analytics\Data\V1alpha\AudienceDimension;
use Google\Analytics\Data\V1alpha\AudienceList;
use Google\Analytics\Data\V1alpha\Client\AlphaAnalyticsDataClient;
use Google\Analytics\Data\V1alpha\CreateAudienceListRequest;
use Google\ApiCore\ApiException;
use Google\ApiCore\OperationResponse;
use Google\Rpc\Status;
/**
* @param string $formattedParent The parent resource where this audience list will be created.
* Format: `properties/{property}`
* Please see {@see AlphaAnalyticsDataClient::propertyName()} for help formatting this field.
* @param string $audienceListAudience The audience resource name. This resource name identifies the
* audience being listed and is shared between the Analytics Data & Admin
* APIs.
*
* Format: `properties/{property}/audiences/{audience}`
*/
function create_audience_list_sample(string $formattedParent, string $audienceListAudience): void
{
// Create a client.
$alphaAnalyticsDataClient = new AlphaAnalyticsDataClient();
// Prepare the request message.
$audienceListDimensions = [new AudienceDimension()];
$audienceList = (new AudienceList())
->setAudience($audienceListAudience)
->setDimensions($audienceListDimensions);
$request = (new CreateAudienceListRequest())
->setParent($formattedParent)
->setAudienceList($audienceList);
// Call the API and handle any network failures.
try {
/** @var OperationResponse $response */
$response = $alphaAnalyticsDataClient->createAudienceList($request);
$response->pollUntilComplete();
if ($response->operationSucceeded()) {
/** @var AudienceList $result */
$result = $response->getResult();
printf('Operation successful with response data: %s' . PHP_EOL, $result->serializeToJsonString());
} else {
/** @var Status $error */
$error = $response->getError();
printf('Operation failed with error data: %s' . PHP_EOL, $error->serializeToJsonString());
}
} catch (ApiException $ex) {
printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage());
}
}
/**
* Helper to execute the sample.
*
* 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 = AlphaAnalyticsDataClient::propertyName('[PROPERTY]');
$audienceListAudience = '[AUDIENCE]';
create_audience_list_sample($formattedParent, $audienceListAudience);
}
createRecurringAudienceList
Creates a recurring audience list. Recurring audience lists produces new audience lists each day. Audience lists are users in an audience at the time of the list's creation.
A recurring audience list ensures that you have audience list based on the most recent data available for use each day. If you manually create audience list, you don't know when an audience list based on an additional day's data is available. This recurring audience list automates the creation of an audience list when an additional day's data is available. You will consume fewer quota tokens by using recurring audience list versus manually creating audience list at various times of day trying to guess when an additional day's data is ready.
This method is introduced at alpha stability with the intention of gathering feedback on syntax and capabilities before entering beta. To give your feedback on this API, complete the Google Analytics Audience Export API Feedback form.
Parameters | |
---|---|
Name | Description |
parent |
string
Required. The parent resource where this recurring audience list will be
created. Format: |
recurringAudienceList |
Google\Analytics\Data\V1alpha\RecurringAudienceList
Required. The recurring audience list 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 | |
---|---|
Type | Description |
Google\Analytics\Data\V1alpha\RecurringAudienceList |
use Google\Analytics\Data\V1alpha\AudienceDimension;
use Google\Analytics\Data\V1alpha\Client\AlphaAnalyticsDataClient;
use Google\Analytics\Data\V1alpha\CreateRecurringAudienceListRequest;
use Google\Analytics\Data\V1alpha\RecurringAudienceList;
use Google\ApiCore\ApiException;
/**
* @param string $formattedParent The parent resource where this recurring audience list will be
* created. Format: `properties/{property}`
* Please see {@see AlphaAnalyticsDataClient::propertyName()} for help formatting this field.
* @param string $recurringAudienceListAudience The audience resource name. This resource name identifies the
* audience being listed and is shared between the Analytics Data & Admin
* APIs.
*
* Format: `properties/{property}/audiences/{audience}`
*/
function create_recurring_audience_list_sample(
string $formattedParent,
string $recurringAudienceListAudience
): void {
// Create a client.
$alphaAnalyticsDataClient = new AlphaAnalyticsDataClient();
// Prepare the request message.
$recurringAudienceListDimensions = [new AudienceDimension()];
$recurringAudienceList = (new RecurringAudienceList())
->setAudience($recurringAudienceListAudience)
->setDimensions($recurringAudienceListDimensions);
$request = (new CreateRecurringAudienceListRequest())
->setParent($formattedParent)
->setRecurringAudienceList($recurringAudienceList);
// Call the API and handle any network failures.
try {
/** @var RecurringAudienceList $response */
$response = $alphaAnalyticsDataClient->createRecurringAudienceList($request);
printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString());
} catch (ApiException $ex) {
printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage());
}
}
/**
* Helper to execute the sample.
*
* 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 = AlphaAnalyticsDataClient::propertyName('[PROPERTY]');
$recurringAudienceListAudience = '[AUDIENCE]';
create_recurring_audience_list_sample($formattedParent, $recurringAudienceListAudience);
}
createReportTask
Initiates the creation of a report task. This method quickly returns a report task and initiates a long running asynchronous request to form a customized report of your Google Analytics event data.
A report task will be retained and available for querying for 72 hours after it has been created.
A report task created by one user can be listed and queried by all users who have access to the property.
Parameters | |
---|---|
Name | Description |
parent |
string
Required. The parent resource where this report task will be created.
Format: |
reportTask |
Google\Analytics\Data\V1alpha\ReportTask
Required. The report task configuration 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 | |
---|---|
Type | Description |
Google\ApiCore\OperationResponse |
use Google\Analytics\Data\V1alpha\Client\AlphaAnalyticsDataClient;
use Google\Analytics\Data\V1alpha\CreateReportTaskRequest;
use Google\Analytics\Data\V1alpha\ReportTask;
use Google\ApiCore\ApiException;
use Google\ApiCore\OperationResponse;
use Google\Rpc\Status;
/**
* @param string $formattedParent The parent resource where this report task will be created.
* Format: `properties/{propertyId}`
* Please see {@see AlphaAnalyticsDataClient::propertyName()} for help formatting this field.
*/
function create_report_task_sample(string $formattedParent): void
{
// Create a client.
$alphaAnalyticsDataClient = new AlphaAnalyticsDataClient();
// Prepare the request message.
$reportTask = new ReportTask();
$request = (new CreateReportTaskRequest())
->setParent($formattedParent)
->setReportTask($reportTask);
// Call the API and handle any network failures.
try {
/** @var OperationResponse $response */
$response = $alphaAnalyticsDataClient->createReportTask($request);
$response->pollUntilComplete();
if ($response->operationSucceeded()) {
/** @var ReportTask $result */
$result = $response->getResult();
printf('Operation successful with response data: %s' . PHP_EOL, $result->serializeToJsonString());
} else {
/** @var Status $error */
$error = $response->getError();
printf('Operation failed with error data: %s' . PHP_EOL, $error->serializeToJsonString());
}
} catch (ApiException $ex) {
printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage());
}
}
/**
* Helper to execute the sample.
*
* 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 = AlphaAnalyticsDataClient::propertyName('[PROPERTY]');
create_report_task_sample($formattedParent);
}
getAudienceList
Gets configuration metadata about a specific audience list. This method can be used to understand an audience list after it has been created.
See Creating an Audience List for an introduction to Audience Lists with examples.
This method is available at beta stability at audienceExports.get. To give your feedback on this API, complete the Google Analytics Audience Export API Feedback form.
Parameters | |
---|---|
Name | Description |
name |
string
Required. The audience list resource name.
Format: |
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 | |
---|---|
Type | Description |
Google\Analytics\Data\V1alpha\AudienceList |
use Google\Analytics\Data\V1alpha\AudienceList;
use Google\Analytics\Data\V1alpha\Client\AlphaAnalyticsDataClient;
use Google\Analytics\Data\V1alpha\GetAudienceListRequest;
use Google\ApiCore\ApiException;
/**
* @param string $formattedName The audience list resource name.
* Format: `properties/{property}/audienceLists/{audience_list}`
* Please see {@see AlphaAnalyticsDataClient::audienceListName()} for help formatting this field.
*/
function get_audience_list_sample(string $formattedName): void
{
// Create a client.
$alphaAnalyticsDataClient = new AlphaAnalyticsDataClient();
// Prepare the request message.
$request = (new GetAudienceListRequest())
->setName($formattedName);
// Call the API and handle any network failures.
try {
/** @var AudienceList $response */
$response = $alphaAnalyticsDataClient->getAudienceList($request);
printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString());
} catch (ApiException $ex) {
printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage());
}
}
/**
* Helper to execute the sample.
*
* 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 = AlphaAnalyticsDataClient::audienceListName('[PROPERTY]', '[AUDIENCE_LIST]');
get_audience_list_sample($formattedName);
}
getPropertyQuotasSnapshot
Get all property quotas organized by quota category for a given property.
This will charge 1 property quota from the category with the most quota.
Parameters | |
---|---|
Name | Description |
name |
string
Required. Quotas from this property will be listed in the response.
Format: |
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 | |
---|---|
Type | Description |
Google\Analytics\Data\V1alpha\PropertyQuotasSnapshot |
use Google\Analytics\Data\V1alpha\Client\AlphaAnalyticsDataClient;
use Google\Analytics\Data\V1alpha\GetPropertyQuotasSnapshotRequest;
use Google\Analytics\Data\V1alpha\PropertyQuotasSnapshot;
use Google\ApiCore\ApiException;
/**
* @param string $formattedName Quotas from this property will be listed in the response.
* Format: `properties/{property}/propertyQuotasSnapshot`
* Please see {@see AlphaAnalyticsDataClient::propertyQuotasSnapshotName()} for help formatting this field.
*/
function get_property_quotas_snapshot_sample(string $formattedName): void
{
// Create a client.
$alphaAnalyticsDataClient = new AlphaAnalyticsDataClient();
// Prepare the request message.
$request = (new GetPropertyQuotasSnapshotRequest())
->setName($formattedName);
// Call the API and handle any network failures.
try {
/** @var PropertyQuotasSnapshot $response */
$response = $alphaAnalyticsDataClient->getPropertyQuotasSnapshot($request);
printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString());
} catch (ApiException $ex) {
printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage());
}
}
/**
* Helper to execute the sample.
*
* 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 = AlphaAnalyticsDataClient::propertyQuotasSnapshotName('[PROPERTY]');
get_property_quotas_snapshot_sample($formattedName);
}
getRecurringAudienceList
Gets configuration metadata about a specific recurring audience list. This method can be used to understand a recurring audience list's state after it has been created. For example, a recurring audience list resource will generate audience list instances for each day, and this method can be used to get the resource name of the most recent audience list instance.
This method is introduced at alpha stability with the intention of gathering feedback on syntax and capabilities before entering beta. To give your feedback on this API, complete the Google Analytics Audience Export API Feedback form.
Parameters | |
---|---|
Name | Description |
name |
string
Required. The recurring audience list resource name.
Format:
|
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 | |
---|---|
Type | Description |
Google\Analytics\Data\V1alpha\RecurringAudienceList |
use Google\Analytics\Data\V1alpha\Client\AlphaAnalyticsDataClient;
use Google\Analytics\Data\V1alpha\GetRecurringAudienceListRequest;
use Google\Analytics\Data\V1alpha\RecurringAudienceList;
use Google\ApiCore\ApiException;
/**
* @param string $formattedName The recurring audience list resource name.
* Format:
* `properties/{property}/recurringAudienceLists/{recurring_audience_list}`
* Please see {@see AlphaAnalyticsDataClient::recurringAudienceListName()} for help formatting this field.
*/
function get_recurring_audience_list_sample(string $formattedName): void
{
// Create a client.
$alphaAnalyticsDataClient = new AlphaAnalyticsDataClient();
// Prepare the request message.
$request = (new GetRecurringAudienceListRequest())
->setName($formattedName);
// Call the API and handle any network failures.
try {
/** @var RecurringAudienceList $response */
$response = $alphaAnalyticsDataClient->getRecurringAudienceList($request);
printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString());
} catch (ApiException $ex) {
printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage());
}
}
/**
* Helper to execute the sample.
*
* 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 = AlphaAnalyticsDataClient::recurringAudienceListName(
'[PROPERTY]',
'[RECURRING_AUDIENCE_LIST]'
);
get_recurring_audience_list_sample($formattedName);
}
getReportTask
Gets report metadata about a specific report task. After creating a report task, use this method to check its processing state or inspect its report definition.
Parameters | |
---|---|
Name | Description |
name |
string
Required. The report task resource name.
Format: |
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 | |
---|---|
Type | Description |
Google\Analytics\Data\V1alpha\ReportTask |
use Google\Analytics\Data\V1alpha\Client\AlphaAnalyticsDataClient;
use Google\Analytics\Data\V1alpha\GetReportTaskRequest;
use Google\Analytics\Data\V1alpha\ReportTask;
use Google\ApiCore\ApiException;
/**
* @param string $formattedName The report task resource name.
* Format: `properties/{property}/reportTasks/{report_task}`
* Please see {@see AlphaAnalyticsDataClient::reportTaskName()} for help formatting this field.
*/
function get_report_task_sample(string $formattedName): void
{
// Create a client.
$alphaAnalyticsDataClient = new AlphaAnalyticsDataClient();
// Prepare the request message.
$request = (new GetReportTaskRequest())
->setName($formattedName);
// Call the API and handle any network failures.
try {
/** @var ReportTask $response */
$response = $alphaAnalyticsDataClient->getReportTask($request);
printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString());
} catch (ApiException $ex) {
printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage());
}
}
/**
* Helper to execute the sample.
*
* 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 = AlphaAnalyticsDataClient::reportTaskName('[PROPERTY]', '[REPORT_TASK]');
get_report_task_sample($formattedName);
}
listAudienceLists
Lists all audience lists for a property. This method can be used for you to find and reuse existing audience lists rather than creating unnecessary new audience lists. The same audience can have multiple audience lists that represent the list of users that were in an audience on different days.
See Creating an Audience List for an introduction to Audience Lists with examples.
This method is available at beta stability at audienceExports.list. To give your feedback on this API, complete the Google Analytics Audience Export API Feedback form.
Parameters | |
---|---|
Name | Description |
parent |
string
Required. All audience lists for this property will be listed in the
response. Format: |
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 | |
---|---|
Type | Description |
Google\ApiCore\PagedListResponse |
use Google\Analytics\Data\V1alpha\AudienceList;
use Google\Analytics\Data\V1alpha\Client\AlphaAnalyticsDataClient;
use Google\Analytics\Data\V1alpha\ListAudienceListsRequest;
use Google\ApiCore\ApiException;
use Google\ApiCore\PagedListResponse;
/**
* @param string $formattedParent All audience lists for this property will be listed in the
* response. Format: `properties/{property}`
* Please see {@see AlphaAnalyticsDataClient::propertyName()} for help formatting this field.
*/
function list_audience_lists_sample(string $formattedParent): void
{
// Create a client.
$alphaAnalyticsDataClient = new AlphaAnalyticsDataClient();
// Prepare the request message.
$request = (new ListAudienceListsRequest())
->setParent($formattedParent);
// Call the API and handle any network failures.
try {
/** @var PagedListResponse $response */
$response = $alphaAnalyticsDataClient->listAudienceLists($request);
/** @var AudienceList $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());
}
}
/**
* Helper to execute the sample.
*
* 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 = AlphaAnalyticsDataClient::propertyName('[PROPERTY]');
list_audience_lists_sample($formattedParent);
}
listRecurringAudienceLists
Lists all recurring audience lists for a property. This method can be used
for you to find and reuse existing recurring audience lists rather than
creating unnecessary new recurring audience lists. The same audience can
have multiple recurring audience lists that represent different dimension
combinations; for example, just the dimension deviceId
or both the
dimensions deviceId
and userId
.
This method is introduced at alpha stability with the intention of gathering feedback on syntax and capabilities before entering beta. To give your feedback on this API, complete the Google Analytics Audience Export API Feedback form.
Parameters | |
---|---|
Name | Description |
parent |
string
Required. All recurring audience lists for this property will be listed in
the response. Format: |
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 | |
---|---|
Type | Description |
Google\ApiCore\PagedListResponse |
use Google\Analytics\Data\V1alpha\Client\AlphaAnalyticsDataClient;
use Google\Analytics\Data\V1alpha\ListRecurringAudienceListsRequest;
use Google\Analytics\Data\V1alpha\RecurringAudienceList;
use Google\ApiCore\ApiException;
use Google\ApiCore\PagedListResponse;
/**
* @param string $formattedParent All recurring audience lists for this property will be listed in
* the response. Format: `properties/{property}`
* Please see {@see AlphaAnalyticsDataClient::propertyName()} for help formatting this field.
*/
function list_recurring_audience_lists_sample(string $formattedParent): void
{
// Create a client.
$alphaAnalyticsDataClient = new AlphaAnalyticsDataClient();
// Prepare the request message.
$request = (new ListRecurringAudienceListsRequest())
->setParent($formattedParent);
// Call the API and handle any network failures.
try {
/** @var PagedListResponse $response */
$response = $alphaAnalyticsDataClient->listRecurringAudienceLists($request);
/** @var RecurringAudienceList $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());
}
}
/**
* Helper to execute the sample.
*
* 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 = AlphaAnalyticsDataClient::propertyName('[PROPERTY]');
list_recurring_audience_lists_sample($formattedParent);
}
listReportTasks
Lists all report tasks for a property.
Parameters | |
---|---|
Name | Description |
parent |
string
Required. All report tasks for this property will be listed in the
response. Format: |
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 | |
---|---|
Type | Description |
Google\ApiCore\PagedListResponse |
use Google\Analytics\Data\V1alpha\Client\AlphaAnalyticsDataClient;
use Google\Analytics\Data\V1alpha\ListReportTasksRequest;
use Google\Analytics\Data\V1alpha\ReportTask;
use Google\ApiCore\ApiException;
use Google\ApiCore\PagedListResponse;
/**
* @param string $formattedParent All report tasks for this property will be listed in the
* response. Format: `properties/{property}`
* Please see {@see AlphaAnalyticsDataClient::propertyName()} for help formatting this field.
*/
function list_report_tasks_sample(string $formattedParent): void
{
// Create a client.
$alphaAnalyticsDataClient = new AlphaAnalyticsDataClient();
// Prepare the request message.
$request = (new ListReportTasksRequest())
->setParent($formattedParent);
// Call the API and handle any network failures.
try {
/** @var PagedListResponse $response */
$response = $alphaAnalyticsDataClient->listReportTasks($request);
/** @var ReportTask $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());
}
}
/**
* Helper to execute the sample.
*
* 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 = AlphaAnalyticsDataClient::propertyName('[PROPERTY]');
list_report_tasks_sample($formattedParent);
}
queryAudienceList
Retrieves an audience list of users. After creating an audience, the users
are not immediately available for listing. First, a request to
CreateAudienceList
is necessary to create an audience list of users, and
then second, this method is used to retrieve the users in the audience
list.
See Creating an Audience List for an introduction to Audience Lists with examples.
Audiences in Google Analytics 4 allow you to segment your users in the ways that are important to your business. To learn more, see https://support.google.com/analytics/answer/9267572.
This method is available at beta stability at audienceExports.query. To give your feedback on this API, complete the Google Analytics Audience Export API Feedback form.
Parameters | |
---|---|
Name | Description |
name |
string
Required. The name of the audience list to retrieve users from.
Format: |
optionalArgs |
array
Optional. |
↳ offset |
int
Optional. The row count of the start row. The first row is counted as row 0. When paging, the first request does not specify offset; or equivalently, sets offset to 0; the first request returns the first |
↳ limit |
int
Optional. The number of rows to return. If unspecified, 10,000 rows are returned. The API returns a maximum of 250,000 rows per request, no matter how many you ask for. |
↳ 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 | |
---|---|
Type | Description |
Google\Analytics\Data\V1alpha\QueryAudienceListResponse |
use Google\Analytics\Data\V1alpha\Client\AlphaAnalyticsDataClient;
use Google\Analytics\Data\V1alpha\QueryAudienceListRequest;
use Google\Analytics\Data\V1alpha\QueryAudienceListResponse;
use Google\ApiCore\ApiException;
/**
* @param string $name The name of the audience list to retrieve users from.
* Format: `properties/{property}/audienceLists/{audience_list}`
*/
function query_audience_list_sample(string $name): void
{
// Create a client.
$alphaAnalyticsDataClient = new AlphaAnalyticsDataClient();
// Prepare the request message.
$request = (new QueryAudienceListRequest())
->setName($name);
// Call the API and handle any network failures.
try {
/** @var QueryAudienceListResponse $response */
$response = $alphaAnalyticsDataClient->queryAudienceList($request);
printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString());
} catch (ApiException $ex) {
printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage());
}
}
/**
* Helper to execute the sample.
*
* 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
{
$name = '[NAME]';
query_audience_list_sample($name);
}
queryReportTask
Retrieves a report task's content. After requesting the CreateReportTask
,
you are able to retrieve the report content once the report is
ACTIVE. This method will return an error if the report task's state is not
ACTIVE
. A query response will return the tabular row & column values of
the report.
Parameters | |
---|---|
Name | Description |
name |
string
Required. The report source name.
Format: |
optionalArgs |
array
Optional. |
↳ offset |
int
Optional. The row count of the start row in the report. The first row is counted as row 0. When paging, the first request does not specify offset; or equivalently, sets offset to 0; the first request returns the first |
↳ limit |
int
Optional. The number of rows to return from the report. If unspecified, 10,000 rows are returned. The API returns a maximum of 250,000 rows per request, no matter how many you ask for. |
↳ 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 | |
---|---|
Type | Description |
Google\Analytics\Data\V1alpha\QueryReportTaskResponse |
use Google\Analytics\Data\V1alpha\Client\AlphaAnalyticsDataClient;
use Google\Analytics\Data\V1alpha\QueryReportTaskRequest;
use Google\Analytics\Data\V1alpha\QueryReportTaskResponse;
use Google\ApiCore\ApiException;
/**
* @param string $name The report source name.
* Format: `properties/{property}/reportTasks/{report}`
*/
function query_report_task_sample(string $name): void
{
// Create a client.
$alphaAnalyticsDataClient = new AlphaAnalyticsDataClient();
// Prepare the request message.
$request = (new QueryReportTaskRequest())
->setName($name);
// Call the API and handle any network failures.
try {
/** @var QueryReportTaskResponse $response */
$response = $alphaAnalyticsDataClient->queryReportTask($request);
printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString());
} catch (ApiException $ex) {
printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage());
}
}
/**
* Helper to execute the sample.
*
* 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
{
$name = '[NAME]';
query_report_task_sample($name);
}
runFunnelReport
Returns a customized funnel report of your Google Analytics event data. The data returned from the API is as a table with columns for the requested dimensions and metrics.
Funnel exploration lets you visualize the steps your users take to complete a task and quickly see how well they are succeeding or failing at each step. For example, how do prospects become shoppers and then become buyers? How do one time buyers become repeat buyers? With this information, you can improve inefficient or abandoned customer journeys. To learn more, see GA4 Funnel Explorations.
This method is introduced at alpha stability with the intention of gathering feedback on syntax and capabilities before entering beta. To give your feedback on this API, complete the Google Analytics Data API Funnel Reporting Feedback.
Parameters | |
---|---|
Name | Description |
optionalArgs |
array
Optional. |
↳ property |
string
Optional. A Google Analytics property identifier whose events are tracked. Specified in the URL path and not the body. To learn more, see where to find your Property ID. Within a batch request, this property should either be unspecified or consistent with the batch-level property. Example: properties/1234 |
↳ dateRanges |
DateRange[]
Optional. Date ranges of data to read. If multiple date ranges are requested, each response row will contain a zero based date range index. If two date ranges overlap, the event data for the overlapping days is included in the response rows for both date ranges. |
↳ funnel |
Funnel
Optional. The configuration of this request's funnel. This funnel configuration is required. |
↳ funnelBreakdown |
FunnelBreakdown
Optional. If specified, this breakdown adds a dimension to the funnel table sub report response. This breakdown dimension expands each funnel step to the unique values of the breakdown dimension. For example, a breakdown by the |
↳ funnelNextAction |
FunnelNextAction
Optional. If specified, next action adds a dimension to the funnel visualization sub report response. This next action dimension expands each funnel step to the unique values of the next action. For example a next action of the |
↳ funnelVisualizationType |
int
Optional. The funnel visualization type controls the dimensions present in the funnel visualization sub report response. If not specified, |
↳ segments |
Segment[]
Optional. The configurations of segments. Segments are subsets of a property's data. In a funnel report with segments, the funnel is evaluated in each segment. Each segment specified in this request produces a separate row in the response; in the response, each segment identified by its name. The segments parameter is optional. Requests are limited to 4 segments. |
↳ limit |
int
Optional. The number of rows to return. If unspecified, 10,000 rows are returned. The API returns a maximum of 250,000 rows per request, no matter how many you ask for. |
↳ dimensionFilter |
FilterExpression
Optional. Dimension filters allow you to ask for only specific dimension values in the report. To learn more, see Creating a Report: Dimension Filters for examples. Metrics cannot be used in this filter. |
↳ returnPropertyQuota |
bool
Optional. Toggles whether to return the current state of this Analytics Property's quota. Quota is returned in PropertyQuota. |
↳ 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 | |
---|---|
Type | Description |
Google\Analytics\Data\V1alpha\RunFunnelReportResponse |
use Google\Analytics\Data\V1alpha\Client\AlphaAnalyticsDataClient;
use Google\Analytics\Data\V1alpha\RunFunnelReportRequest;
use Google\Analytics\Data\V1alpha\RunFunnelReportResponse;
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 run_funnel_report_sample(): void
{
// Create a client.
$alphaAnalyticsDataClient = new AlphaAnalyticsDataClient();
// Prepare the request message.
$request = new RunFunnelReportRequest();
// Call the API and handle any network failures.
try {
/** @var RunFunnelReportResponse $response */
$response = $alphaAnalyticsDataClient->runFunnelReport($request);
printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString());
} catch (ApiException $ex) {
printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage());
}
}
sheetExportAudienceList
Exports an audience list of users to a Google Sheet. After creating an
audience, the users are not immediately available for listing. First, a
request to CreateAudienceList
is necessary to create an audience list of
users, and then second, this method is used to export those users in the
audience list to a Google Sheet.
See Creating an Audience List for an introduction to Audience Lists with examples.
Audiences in Google Analytics 4 allow you to segment your users in the ways that are important to your business. To learn more, see https://support.google.com/analytics/answer/9267572.
This method is introduced at alpha stability with the intention of gathering feedback on syntax and capabilities before entering beta. To give your feedback on this API, complete the Google Analytics Audience Export API Feedback form.
Parameters | |
---|---|
Name | Description |
name |
string
Required. The name of the audience list to retrieve users from.
Format: |
optionalArgs |
array
Optional. |
↳ offset |
int
Optional. The row count of the start row. The first row is counted as row 0. When paging, the first request does not specify offset; or equivalently, sets offset to 0; the first request returns the first |
↳ limit |
int
Optional. The number of rows to return. If unspecified, 10,000 rows are returned. The API returns a maximum of 250,000 rows per request, no matter how many you ask for. |
↳ 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 | |
---|---|
Type | Description |
Google\Analytics\Data\V1alpha\SheetExportAudienceListResponse |
use Google\Analytics\Data\V1alpha\Client\AlphaAnalyticsDataClient;
use Google\Analytics\Data\V1alpha\SheetExportAudienceListRequest;
use Google\Analytics\Data\V1alpha\SheetExportAudienceListResponse;
use Google\ApiCore\ApiException;
/**
* @param string $formattedName The name of the audience list to retrieve users from.
* Format: `properties/{property}/audienceLists/{audience_list}`
* Please see {@see AlphaAnalyticsDataClient::audienceListName()} for help formatting this field.
*/
function sheet_export_audience_list_sample(string $formattedName): void
{
// Create a client.
$alphaAnalyticsDataClient = new AlphaAnalyticsDataClient();
// Prepare the request message.
$request = (new SheetExportAudienceListRequest())
->setName($formattedName);
// Call the API and handle any network failures.
try {
/** @var SheetExportAudienceListResponse $response */
$response = $alphaAnalyticsDataClient->sheetExportAudienceList($request);
printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString());
} catch (ApiException $ex) {
printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage());
}
}
/**
* Helper to execute the sample.
*
* 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 = AlphaAnalyticsDataClient::audienceListName('[PROPERTY]', '[AUDIENCE_LIST]');
sheet_export_audience_list_sample($formattedName);
}
getOperationsClient
Return an OperationsClient object with the same endpoint as $this.
Returns | |
---|---|
Type | Description |
Google\ApiCore\LongRunning\OperationsClient |
resumeOperation
Resume an existing long running operation that was previously started by a long running API method. If $methodName is not provided, or does not match a long running API method, then the operation can still be resumed, but the OperationResponse object will not deserialize the final response.
Parameters | |
---|---|
Name | Description |
operationName |
string
The name of the long running operation |
methodName |
string
The name of the method used to start the operation |
Returns | |
---|---|
Type | Description |
Google\ApiCore\OperationResponse |
static::audienceListName
Formats a string containing the fully-qualified path to represent a audience_list resource.
Parameters | |
---|---|
Name | Description |
property |
string
|
audienceList |
string
|
Returns | |
---|---|
Type | Description |
string |
The formatted audience_list resource. |
static::propertyName
Formats a string containing the fully-qualified path to represent a property resource.
Parameter | |
---|---|
Name | Description |
property |
string
|
Returns | |
---|---|
Type | Description |
string |
The formatted property resource. |
static::propertyQuotasSnapshotName
Formats a string containing the fully-qualified path to represent a property_quotas_snapshot resource.
Parameter | |
---|---|
Name | Description |
property |
string
|
Returns | |
---|---|
Type | Description |
string |
The formatted property_quotas_snapshot resource. |
static::recurringAudienceListName
Formats a string containing the fully-qualified path to represent a recurring_audience_list resource.
Parameters | |
---|---|
Name | Description |
property |
string
|
recurringAudienceList |
string
|
Returns | |
---|---|
Type | Description |
string |
The formatted recurring_audience_list resource. |
static::reportTaskName
Formats a string containing the fully-qualified path to represent a report_task resource.
Parameters | |
---|---|
Name | Description |
property |
string
|
reportTask |
string
|
Returns | |
---|---|
Type | Description |
string |
The formatted report_task resource. |
static::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
- audienceList: properties/{property}/audienceLists/{audience_list}
- property: properties/{property}
- propertyQuotasSnapshot: properties/{property}/propertyQuotasSnapshot
- recurringAudienceList: properties/{property}/recurringAudienceLists/{recurring_audience_list}
- reportTask: properties/{property}/reportTasks/{report_task}
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 | |
---|---|
Name | Description |
formattedName |
string
The formatted name string |
template |
string
Optional name of template to match |
Returns | |
---|---|
Type | Description |
array |
An associative array from name component IDs to component values. |
Constants
SERVICE_NAME
Value: 'google.analytics.data.v1alpha.AlphaAnalyticsData'
The name of the service.
SERVICE_ADDRESS
Value: 'analyticsdata.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.