gpt4 book ai didi

api - Google Analytics API 获取配置文件 ID 代替或使用域

转载 作者:行者123 更新时间:2023-12-03 16:05:53 25 4
gpt4 key购买 nike

这就是我从任何 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。

提前致谢。

最佳答案

下面的示例应该可以帮助您打印特定帐户 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 帐户 -> 属性 -> View (配置文件)
$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;
}

关于api - Google Analytics API 获取配置文件 ID 代替或使用域,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25455950/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com