【问题标题】:Google Analytics API get Profile ID instead or with DomainsGoogle Analytics API 获取配置文件 ID 代替或使用域
【发布时间】:2014-08-22 21:43:19
【问题描述】:

这就是我从任何 Google Analytics(分析)帐户打印域的方式。如何代替(或使用域)打印配置文件 ID?

global $_params, $output_title, $output_body;
$output_title = 'Adwords';
$output_nav = '<li><a href="'.$scriptUri.'?logout">Logout</a></li>'."\n";
$output_body = '<h1>Google Adwords Access demo</h1>
                <p>The following domains are in your Google Adwords account</p><ul>';
$props = $service->management_webproperties->listManagementWebproperties("~all");
foreach($props['items'] as $item) {
    $output_body .= sprintf('<li>%1$s</li>', $item['name']);
}
$output_body .= '</ul>';

这一行是获取域的函数:

$props = $service->management_webproperties->listManagementWebproperties("~all");

我现在需要一些东西来获取多个域的配置文件 ID。

提前致谢。

【问题讨论】:

    标签: api google-analytics google-analytics-api


    【解决方案1】:

    下面的示例应该可以帮助您打印特定帐户 XXXX 和属性 UA-XXXX-Y 的所有配置文件 ID。

     /**
     * This example requests a list of views (profiles) for the authorized user.
     */
    $profiles = $analytics->management_profiles->listManagementProfiles('XXXX', 'UA-XXXX-Y');
    
    foreach ($profiles->getItems() as $profile) {
        print("view (profile) id: $profile->getId()");
    }
    

    您可以查看 API documentation for view (profiles) 以获得更详细的示例。

    您可能还会发现使用account summaries api 很有用。它提供了一种简单的方法来遍历所有级别的 Google Analytics(分析)帐户 -> 属性 -> 视图(配置文件)

    $accounts = $analytics->management_accountSummaries
          ->listManagementAccountSummaries();
    
    foreach ($accounts->getItems() as $account) {
      $html = <<<HTML
    <pre>
    Account id   = {$account->getId()}
    Account kind = {$account->getKind()}
    Account name = {$account->getName()}
    HTML;
    
      // Iterate through each Property.
      foreach ($account->getWebProperties() as $property) {
      $html .= <<<HTML
    Property id          = {$property->getId()}
    Property kind        = {$property->getKind()}
    Property name        = {$property->getName()}
    Internal property id = {$property->getInternalWebPropertyId()}
    Property level       = {$property->getLevel()}
    Property URL         = {$property->getWebsiteUrl()}
    HTML;
    
        // Iterate through each view (profile).
        foreach ($property->getProfiles() as $profile) {
          $html .= <<<HTML
    Profile id   = {$profile->getId()}
    Profile kind = {$profile->getKind()}
    Profile name = {$profile->getName()}
    Profile type = {$profile->getType()}
    HTML;
        }
      }
      $html .= '</pre>';
      print $html;
    }
    

    【讨论】:

      猜你喜欢
      • 2015-08-20
      • 1970-01-01
      • 2013-03-08
      • 1970-01-01
      • 1970-01-01
      • 2019-04-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多