如何获取 Google Analytics GA4 帐户的所有属性

问题描述

如何通过 PHP 列出使用 Google Analytics GA4 的所有帐户的所有媒体资源?对于通用分析,我使用以下内容:

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();
        [...]
    }
}

但是,此方法只允许我检索通用分析属性,而不是新的 GA4 属性。官方文档根本没有帮助。

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)