Adwords cost : precision problem

251 views
Skip to first unread message

Chaitanya Phani

unread,
Jan 11, 2018, 3:45:31 PM1/11/18
to AdWords API Forum
Hi, 

I pulled all the campaigns and their metrics by using Python API. I uploaded into database and when I calculated Sum, numbers are matching but precision is not. 

Example :

cost in UI: 567.87
it is retrieving as 56787. 

Please let me know why

The following code I used to pull the data.

def download_Performance_Criteria_Report():
 
for client_customer_id in list(set(account_list)):
    o2client
= GoogleRefreshTokenClient(adc['client_id'],adc['client_secret'],adc['refresh_token'])
    client
=AdWordsClient(adc['developer_token'],o2client,'OBI',client_customer_id=client_customer_id)
    _fpath
=os.path.join('D:/adwords/inbound/Adwords_MMA_'+str(client_customer_id)+'_'+datetime.datetime.now().strftime( "%Y%m%d%H%M") + '.csv')
 
##    client = AdWordsClient.LoadFromStorage('googleads.yaml')
    rep_downloader
= client.GetReportDownloader(version='v201710')
    report
= {
           
'reportName' : 'CAMPAIGN_PERFORMANCE_REPORT',
           
'dateRangeType' :'CUSTOM_DATE',
           
'reportType': 'CAMPAIGN_PERFORMANCE_REPORT',
           
'downloadFormat': 'CSV',
           
'selector': {
               
'fields': ['CampaignId','CampaignName','ExternalCustomerId','CustomerDescriptiveName','Impressions','Clicks','Cost','Date'],
               
'dateRange' : { 'min': '20170101' , 'max' : '20171231'}
               
}
           
}
    _f
=open(_fpath,'wb')
    rep_downloader
.DownloadReport(report,output=_f,skip_report_header=False,skip_column_header=False,skip_report_summary=True)


Vincent Racaza (AdWords API Team)

unread,
Jan 12, 2018, 12:25:38 AM1/12/18
to AdWords API Forum
Hi Chaitanya,

All metrics with Money type like the Cost metric of Campaign Performance Report is returned in the API as micros. If for example in the AdWords UI, its value is 567.87, then in the API, it would be 567870000. Therefore, before you add this one in your database, make sure you have applied the correct formula (divide the API value by 1000000) in transforming this into its UI equivalent value.

Let me know if you can still see a precision issue after doing the suggestion.

Thanks,
Vincent
AdWords API Team

Chaitanya Phani

unread,
Jan 15, 2018, 10:23:15 AM1/15/18
to AdWords API Forum
Hi Vincent, 

Thanks for your reply. If you see the logic I was downloading into a file. Is there any way I can apply the logic before saving into file. 

Thanks,
Chaitanya 

Vincent Racaza (AdWords API Team)

unread,
Jan 16, 2018, 12:49:02 AM1/16/18
to AdWords API Forum
Hi Chaitanya,

Thanks for the clarification.

For reports, you can either download the report data in a file or get the report data as String. So in regards to your concern in applying your code logic (transform fields with micro values into its UI equivalent value) before saving it to a file, then it is possible. You can follow the steps below on how to do this:
  • Get the report data as String and apply the code logic into that object. You can transform that String object into array for better manipulation (this depends on what is easier for you). To download the report data as String, you need to use the DownloadReportAsString() or DownloadReportAsStringWithAwql() methods in Python. You can check this example on how to do this.
  • You can then apply your code logic (divide the values of your fields with Money type by 1000000) to your String or Array object. After that, you can now save the String/array object in a file. However, you need to implement your own code logic that creates/downloads a file from a String/array object. You can search other Python forums on how to do this.
Let me know if you have further clarifications.
Reply all
Reply to author
Forward
0 new messages