[英]Get Reports On Ads Using Google Ads Api
我正在嘗試獲取有關廣告系列和廣告效果的報告。 到目前為止,我已經獲得了廣告系列效果報告,但我無法獲得廣告效果報告。
我在客戶端庫中看到了 google ads api 和它們的示例。 但我無法理解如何獲取廣告報告。
我制作了一個功能,可以通過谷歌廣告 API 為我獲取報告。
谷歌廣告 API: https ://developers.google.com/google-ads/api/docs/fields/ad_group_ad#ad_group_adadexpanded_text_addescription2
谷歌廣告 API Github: https ://github.com/googleads/google-ads-php/
public function getAdsPerformance($customerId)
{
// Customer ID which i am using ---> 2942416690
try {
// Creates a query that retrieves all campaigns.
$query = 'SELECT ad_group_ad.ad.expanded_text_ad.description2 FROM ad_group_ad';
// Issues a search request by specifying page size.
$response = $this->googleAdsServiceClient->search($customerId, $query, ['pageSize' => $this->page_size]);
// Iterates over all rows in all pages and prints the requested field values for
// the campaign in each row.
foreach ($response->iterateAllElements() as $googleAdsRow) {
$adGroup = $googleAdsRow->getAdGroupAd();
// $customer = $googleAdsRow->getCustomer();
// $metrics = $googleAdsRow->getMetrics();
/** @var GoogleAdsRow $googleAdsRow */
$result = [
'ad' => $adGroup->getResourceName()->getValue(),
];
print "<pre>";
print_r($result);
print "</pre>";
}
} catch (GoogleAdsException $googleAdsException) {
printf(
"Request with ID '%s' has failed.%sGoogle Ads failure details:%s",
$googleAdsException->getRequestId(),
PHP_EOL,
PHP_EOL
);
foreach ($googleAdsException->getGoogleAdsFailure()->getErrors() as $error) {
$error = [
'code' => $error->getErrorCode()->getErrorCode(),
'status' => $error->getStatus(),
'message' => $error->getMessage()
];
printf(json_encode($error));
}
} catch (ApiException $apiException) {
$error = [
'code' => $apiException->getCode(),
'status' => $apiException->getStatus(),
'message' => $apiException->getBasicMessage()
];
printf(json_encode($error));
}
}
我正在嘗試從數組中的 api 獲取這種類型的簡單值
Array
(
[campaign] => some test campaign
[currency] => PLN
[clicks] => 100
[impressions] => 300
[cost] => 250.08
[avg_position] => 1.07
[avg_cpc] => 0.8
[conversions] => 0
[cost/conv] => 0
[conv_rate] => 0
[ctr] => 0.9
[avg_cpm] => 2.5
[interaction_rate] => 0.1
[interactions] => 52
)
關於如何從 api 獲取廣告報告的任何想法,有人做過嗎? 我似乎無法弄清楚查看文檔和客戶端庫。
好吧,我做了一些研究。 有兩種類型的廣告。
1. 擴展文字廣告
2. 僅調用廣告
我檢查了投放的廣告類型,結果是“擴展文字廣告”。 然后從此處的 api 文檔中選擇字段ad_group_ad.ad.expanded_text_ad.headline_part1 :
這是完整的功能:
public function getAdsPerformance($customerId)
{
try {
$query =
'SELECT ad_group_ad.ad.expanded_text_ad.headline_part1 '
. 'FROM ad_group_ad '
. 'WHERE ad_group_ad.ad.type = EXPANDED_TEXT_AD';
$response = $this->googleAdsServiceClient->search($customerId, $query, ['pageSize' => $this->page_size]);
foreach ($response->iterateAllElements() as $googleAdsRow) {
$ad = $googleAdsRow->getAdGroupAd()->getAd();
$result = [
'headline part 1' => $ad->getExpandedTextAd()->getHeadlinePart1()->getValue(),
];
print "<pre>";
print_r($result);
print "</pre>";
}
} catch (GoogleAdsException $googleAdsException) {
printf(
"Request with ID '%s' has failed.%sGoogle Ads failure details:%s",
$googleAdsException->getRequestId(),
PHP_EOL,
PHP_EOL
);
foreach ($googleAdsException->getGoogleAdsFailure()->getErrors() as $error) {
$error = [
'code' => $error->getErrorCode()->getErrorCode(),
'status' => $error->getStatus(),
'message' => $error->getMessage()
];
// return $error;
printf(json_encode($error));
}
} catch (ApiException $apiException) {
$error = [
'code' => $apiException->getCode(),
'status' => $apiException->getStatus(),
'message' => $apiException->getBasicMessage()
];
printf(json_encode($error));
}
}
我得到了現場結果:
Array
(
[headline part 1] => Small Business System
)
我正在嘗試獲取有關廣告系列和廣告效果的報告。 到目前為止,我已經獲得了廣告系列效果報告,但我無法獲得廣告效果報告。
我在客戶端庫中看到了 google ads api 及其示例。 但我無法理解如何獲取廣告報告。
我制作了一個功能,可以通過 google ads api 為我獲取報告。
Google Ads API: https : //developers.google.com/google-ads/api/docs/fields/ad_group_ad#ad_group_adadexpanded_text_addescription2
Google Ads Api Github: https : //github.com/googleads/google-ads-php/
public function getAdsPerformance($customerId)
{
// Customer ID which i am using ---> 2942416690
try {
// Creates a query that retrieves all campaigns.
$query = 'SELECT ad_group_ad.ad.expanded_text_ad.description2 FROM ad_group_ad';
// Issues a search request by specifying page size.
$response = $this->googleAdsServiceClient->search($customerId, $query, ['pageSize' => $this->page_size]);
// Iterates over all rows in all pages and prints the requested field values for
// the campaign in each row.
foreach ($response->iterateAllElements() as $googleAdsRow) {
$adGroup = $googleAdsRow->getAdGroupAd();
// $customer = $googleAdsRow->getCustomer();
// $metrics = $googleAdsRow->getMetrics();
/** @var GoogleAdsRow $googleAdsRow */
$result = [
'ad' => $adGroup->getResourceName()->getValue(),
];
print "<pre>";
print_r($result);
print "</pre>";
}
} catch (GoogleAdsException $googleAdsException) {
printf(
"Request with ID '%s' has failed.%sGoogle Ads failure details:%s",
$googleAdsException->getRequestId(),
PHP_EOL,
PHP_EOL
);
foreach ($googleAdsException->getGoogleAdsFailure()->getErrors() as $error) {
$error = [
'code' => $error->getErrorCode()->getErrorCode(),
'status' => $error->getStatus(),
'message' => $error->getMessage()
];
printf(json_encode($error));
}
} catch (ApiException $apiException) {
$error = [
'code' => $apiException->getCode(),
'status' => $apiException->getStatus(),
'message' => $apiException->getBasicMessage()
];
printf(json_encode($error));
}
}
我正在嘗試從數組中的 api 獲取這種類型的簡單值
Array
(
[campaign] => some test campaign
[currency] => PLN
[clicks] => 100
[impressions] => 300
[cost] => 250.08
[avg_position] => 1.07
[avg_cpc] => 0.8
[conversions] => 0
[cost/conv] => 0
[conv_rate] => 0
[ctr] => 0.9
[avg_cpm] => 2.5
[interaction_rate] => 0.1
[interactions] => 52
)
關於如何從 api 獲取廣告報告的任何想法,有人做過嗎? 我似乎無法弄清楚查看文檔和客戶端庫。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.