downloadReportWithAwql returning bad numbers in PHP

40 views
Skip to first unread message

Jay Chuck Mailen

unread,
Mar 12, 2018, 1:39:08 AM3/12/18
to AdWords API Forum
Hello All,

I've run into an issue and was hoping someone would point me in the right direction.

I'm using downloadReportWithAwql (client v201802) to run a query with the KEYWORDS_PERFORMANCE_REPORT - it's actually a query we use in an AdWords script and it works fine there.

But in the PHP script I'm writing some of the number columns return correctly, but others are not.

For example; "Search Impr. share" on one of our keywords is returning 44.83, which is correct, but on the same keyword the "Cost" is returning 7250000 but the cost is actually 7.25

The cost field isn't the only one doing this. All of these fields are doing the same thing: "Avg. CPC", "CPC Bid", "Cost", "CPC" & "Conv. rate" (unless their value is 0, in that case it does spit out 0).

All other numeric fields are returning correctly. But these fields return 7 digits. It appears the whole number separator ( . ) is missing and it's cramming all the decimals right into it. (ie x.xx becomes xxxxxxx and xx.xx also becomes xxxxxxx). If it was always one number before the decimal I'd just grab the first digit and drop in a decimal, but sometimes it's a value like 12.54 becoming 1253267. So that won't work.

Here's a slightly modified version of the code:

private function get_data() {
$reportFormat = DownloadFormat::CSV;
$oAuth2Credential = (new OAuth2TokenBuilder())
->fromFile( self::$ini_path )
->build();

$session = (new AdWordsSessionBuilder())
->fromFile( self::$ini_path )
->withOAuth2Credential( $oAuth2Credential )
->withClientCustomerId( self::$client_id )
->build();

$adWordsServices = new AdWordsServices();
$reportQuery = $this->query( 'KEYWORDS_PERFORMANCE_REPORT' );
/* This is an example of the returned value of $reportQuery
SELECT Criteria,CampaignName,AdGroupName,KeywordMatchType,Clicks,Impressions,Ctr,AverageCpc,CpcBid,Cost,AveragePosition,Conversions,CostPerConversion,ConversionRate,SearchImpressionShare,QualityScore
FROM KEYWORDS_PERFORMANCE_REPORT
WHERE 
IsNegative = FALSE
AND Status = ENABLED
AND AdGroupStatus = ENABLED
AND CampaignStatus = ENABLED
DURING 20170911,20180309
*/

$reportDownloader = new ReportDownloader( $session );

$reportSettingsOverride = ( new ReportSettingsBuilder() )
->includeZeroImpressions( false )
->build();

$reportDownloadResult = $reportDownloader->downloadReportWithAwql(
$reportQuery,
$reportFormat,
$reportSettingsOverride
);

return $reportDownloadResult->getAsString();
}


This is an example of what it's kicking out:

"KEYWORDS_PERFORMANCE_REPORT (Sep 11, 2017-Mar 9, 2018)"
Keyword,Campaign,Ad group,Match type,Clicks,Impressions,CTR,Avg. CPC,Max. CPC,Cost,Avg. position,Conversions,Cost / conv.,Conv. rate,Search Impr. share,Quality score
keyword1,campaign1,group1,Broad,2,127,1.57%,15890000,5000000,31780000,2.2,0.00,0,0.00%,59.71%,5
keyword2,campaign2,group2,Broad,2,26,7.69%,2745000,4880000,5490000,2.3,0.00,0,0.00%,89.47%,6

Obviously I switched out the keywords, campaigns and ad group names. But what's going on with the 7 digit numerical values?

If anyone can shed any light on this and steer me in the right direction I would greatly appreciate it. I don't have much hair left and you'd be saving me from pulling what little remains out.

Thanks,
-Jay



Peter Oliquino

unread,
Mar 12, 2018, 2:26:41 AM3/12/18
to AdWords API Forum
Hi Jay,

In the AdWords API, Money fields such as the Cost field are represented in micros. So what you're seeing is not the actual value of the cost and you will still need to divide it by 1,000,000 in order to get its actual value. I hope this helps.

Best regards,
Peter
AdWords API Team
Reply all
Reply to author
Forward
0 new messages