Php 如何获取Google Analytics GA4帐户的所有属性
如何使用Google Analytics GA4通过PHP列出所有帐户的所有属性?对于通用分析,我使用以下方法:Php 如何获取Google Analytics GA4帐户的所有属性,php,google-analytics,google-analytics-api,google-api-php-client,google-analytics-4,Php,Google Analytics,Google Analytics Api,Google Api Php Client,Google Analytics 4,如何使用Google Analytics GA4通过PHP列出所有帐户的所有属性?对于通用分析,我使用以下方法: function initializeAnalyticsV3() { $client = new Google_Client(); $client->setApplicationName("Name"); $client->setAuthConfig($KEY_FILE_LOCATION); $client->se
function initializeAnalyticsV3()
{
$client = new Google_Client();
$client->setApplicationName("Name");
$client->setAuthConfig($KEY_FILE_LOCATION);
$client->setScopes(['https://www.googleapis.com/auth/analytics.readonly']);
$analytics = new Google_Service_Analytics($client);
return $analytics;
}
$analyticsV3 = initializeAnalyticsV3();
try {
$accounts = $analyticsV3->management_accountSummaries
->listManagementAccountSummaries();
} catch (apiServiceException $e) {
print 'There was an Analytics API service error '
. $e->getCode() . ':' . $e->getMessage();
} catch (apiException $e) {
print 'There was a general API error '
. $e->getCode() . ':' . $e->getMessage();
}
foreach ($accounts->getItems() as $account) {
foreach ($account->getWebProperties() as $property) {
$profile = $property->getProfiles();
[...]
}
}
然而,这个方法只允许我检索Universal analytics属性,而不是新的GA4属性。官方文件毫无帮助。与之不同
您可以使用列出Univeral analytics帐户的所有属性
$accounts = $analytics->management_accounts->listManagementAccounts();
您需要使用列出Ga4帐户
GET https://analyticsadmin.googleapis.com/v1alpha/accountSummaries
"accountSummaries": [
{
object (AccountSummary)
}
],
"nextPageToken": string
}
在撰写本文时,他们还没有发布用于管理api的PHP客户端库。发布后,我将更新它的链接。谢谢。这是很有帮助的。在php库上坚持住,幸运的是,几周后就会有一个。