简体   繁体   English

如何获取 Google Analytics(分析)GA4 帐户的所有属性

[英]How to get all properties for Google Analytics GA4 accounts

How do I list all properties for all account using Google Analytics GA4 through PHP?如何列出使用 Google Analytics GA4 到 PHP 的所有帐户的所有属性? For universal analyitcs I'm using the following:对于通用分析,我使用以下内容:

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

However, this method only allows me to retrieve Universal analytics properties, not the new GA4 ones.但是,这种方法只允许我检索通用分析属性,而不是新的 GA4 属性。 The official documentation was of no help at all.官方文档根本没有帮助。

Google analytics GA4 is not the same as universal analytics . 谷歌分析 GA4通用分析不同。

You can use the managment api to list all of the properties for Univeral analytics acocunts.您可以使用管理 api列出通用分析帐户的所有属性。

$accounts = $analytics->management_accounts->listManagementAccounts();

You will need to use the Admin api to list the Ga4 accounts.您将需要使用管理员 api列出 Ga4 帐户。

GET https://analyticsadmin.googleapis.com/v1alpha/accountSummaries

  "accountSummaries": [
    {
      object (AccountSummary)
    }
  ],
  "nextPageToken": string
}

At the time of writing they have not released a PHP client library for the Admin api yet.在撰写本文时,他们尚未为管理员 api 发布 PHP 客户端库。 I will update with a link to it when it is released.当它发布时,我会更新它的链接。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何将访问令牌与 Google Admin API 一起用于 GA4 属性? - How to use access tokens with Google Admin API for GA4 properties? 如何在使用 PHP 的 Google Analytics Data API (GA4) 中使用多个过滤器 - How to use multiple filters with Google Analytics Data API (GA4) using PHP PHP Google Analytics 数据 API V1 (Beta) (GA4) 通过服务账户授权 - PHP Google Analytics Data API V1 (Beta) (GA4) Authorization via Service Account 通过 oauth2(同意屏幕)从 Google Analytics Data API (Ga4) 中提取数据 - Extract data from Google Analytics Data API (Ga4) via oauth2 (consent screen) 如何使PHP-GA停止增加Google Analytics(分析)中的实时访问者? - How do I get PHP-GA to stop incrementing real-time visitors in google analytics? PHP-Google Analytics(分析)API-在data_ga-> get中使用变量 - PHP - Google Analytics API - Using variables in data_ga->get Google Analytics 未列出所有 web 属性 - Google Analytics Not listing all web properties Google API获取所有登录帐户 - Google API get all logged in accounts 如何使用“ ga”命令通过Analytics.js向Google Analytics(分析)发送购买请求? - how to send purchase request to google analytics via Analytics.js with “ga” command? 如何在1个请求中从Google Analytics(分析)获取所有页面的唯一身份用户 - How to get unique users from Google Analytics for all pages in 1 request
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM