Hello, I am developing a panel to simplify the visualization. I need to
recover the following data:
Applied value;
amount spent or amount remaining
I am using the following code:
<?php
require __DIR__ . '/googleapi/autoload.php';
use Google\AdsApi\AdWords\AdWordsServices;
use Google\AdsApi\AdWords\AdWordsSessionBuilder;
use Google\AdsApi\AdWords\ReportSettingsBuilder;
use Google\AdsApi\AdWords\v201809\cm\CampaignService;
use Google\AdsApi\AdWords\v201702\cm\ReportDefinitionReportType;
use Google\AdsApi\AdWords\v201702\cm\ReportDefinitionService;
use Google\AdsApi\AdWords\Reporting\v201809\ReportDownloader;
use Google\AdsApi\AdWords\v201809\cm\OrderBy;
use Google\AdsApi\AdWords\v201809\cm\Paging;
use Google\AdsApi\AdWords\v201809\cm\Selector;
use Google\AdsApi\Common\OAuth2TokenBuilder;
class Adwords
{
public static function getData(){
$oAuth2Credential = (new OAuth2TokenBuilder())
->fromFile()
->build();
$session = (new AdWordsSessionBuilder())
->fromFile()
->withOAuth2Credential($oAuth2Credential)
->withClientCustomerId('495-142-3572')
->build(); //708-050-6564
$reportQuery = 'SELECT AbsoluteTopImpressionPercentage,
ActiveViewCpm,
ActiveViewCtr,
ActiveViewImpressions,
ActiveViewMeasurability,
ActiveViewMeasurableCost,
ActiveViewMeasurableImpressions,
ActiveViewViewability,
AllConversionRate,
AllConversions,
AllConversionValue,
AverageCost,
AverageCpc,
AverageCpe,
AverageCpm,
AverageCpv,
AveragePosition,
Clicks,
ContentBudgetLostImpressionShare,
ContentImpressionShare,
ContentRankLostImpressionShare,
ConversionRate,
Conversions,
ConversionValue,
Cost,
CostPerAllConversion,
CostPerConversion,
CrossDeviceConversions,
Ctr,
EngagementRate,
Engagements,
Impressions,
InteractionRate,
Interactions,
InteractionTypes,
InvalidClickRate,
InvalidClicks,
SearchBudgetLostImpressionShare,
SearchExactMatchImpressionShare,
SearchImpressionShare,
SearchRankLostImpressionShare,
TopImpressionPercentage,
ValuePerAllConversion,
ValuePerConversion,
VideoViewRate,
VideoViews,
ViewThroughConversions FROM ACCOUNT_PERFORMANCE_REPORT DURING
20210301,20210331';
$reportFormat = 'XML';
$reportDownloader = new ReportDownloader($session);
$reportDownloadResult = $reportDownloader->downloadReportWithAwql(
$reportQuery, $reportFormat);
$datatest = $reportDownloadResult->getAsString();
$xml = simplexml_load_string($datatest);
$json = json_encode($xml);
$json = json_decode($json, true);
echo "<pre>";
print_r($json);
echo "</pre>";
$custo = $json['table']['row']['@attributes']['cost'];
$cpc = $json['table']['row']['@attributes']['avgCPC'];
$leadmes = $json['table']['row']['@attributes']['allConv'];
$costAllConv = $json['table']['row']['@attributes']['costAllConv'];
$costConv = $json['table']['row']['@attributes']['costConv'];
echo "Impressões: "
.$json['table']['row']['@attributes']['impressions']."<br>";
echo "Clicks: "
.$json['table']['row']['@attributes']['clicks']."<br>";
echo "Custo: ". number_format($custo / 1000000, 2, ',', '.')."<br>";
echo "CPC Médio: ". number_format($cpc / 1000000, 2, ',',
'.')."<br>";
echo "Lead do mês: ". number_format($leadmes, 2, ',', '.')."<br>";
echo "<hr>";
echo "costAllConv: ". number_format($costAllConv / 1000000, 2, ',',
'.')."<br>";
echo "costConv: ". number_format($costConv / 1000000, 2, ',',
'.')."<br>";
}
}
AdWords::getData();
[image: google_api.jpg]
--
--
=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~
Also find us on our blog:
https://googleadsdeveloper.blogspot.com/
=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~
You received this message because you are subscribed to the Google
Groups "AdWords API and Google Ads API Forum" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/adwords-api?hl=en
---
You received this message because you are subscribed to the Google Groups
"AdWords API and Google Ads API Forum" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/adwords-api/2d9cc84c-2a7a-4de4-ac62-52e507ea0acan%40googlegroups.com.