Just get error,
Uncaught Error: Call to a member function getValue()
Why getAverageCpv() is not working.
My campaign has averge cpv, not null.
public static function runExample(GoogleAdsClient $googleAdsClient, $customerId)
{
$googleAdsServiceClient = $googleAdsClient->getGoogleAdsServiceClient();
// Creates a query that retrieves all keyword statistics.
$query =
metrics.clicks, metrics.ctr, metrics.average_cpv, metrics.average_cpc, metrics.cost_micros
FROM campaign
WHERE segments.date DURING YESTERDAY";
// Issues a search request by specifying page size.
$response =
$googleAdsServiceClient->search($customerId, $query, ['pageSize' => self::PAGE_SIZE]);
// Iterates over all rows in all pages and prints the requested field values for
// the keyword in each row.
foreach ($response->iterateAllElements() as $googleAdsRow) {
/** @var GoogleAdsRow $googleAdsRow */
$campaign = $googleAdsRow->getCampaign();
$metrics = $googleAdsRow->getMetrics();
printf(
"campaign name '%s' "
. "ID %d "
. "cpv %s "
. "cost %s "
. "%s",
$campaign->getName()->getValue(),
$campaign->getId()->getValue(),
$metrics->getAverageCpv()->getValue(),
$metrics->getCostMicros()->getValue(),
PHP_EOL
);
}
}