AdWords report converting to Google Ads API - finding what fields

68 views
Skip to first unread message

Derek Piper

unread,
Feb 8, 2022, 4:36:50 PM2/8/22
to Google Ads API and AdWords API Forum

I am trying to convert reporting that was written for AdWords to this Google Ads API. This was written in PHP.

What I used to have was:

 $reportSettings = (new ReportSettingsBuilder())
                        ->includeZeroImpressions(false)
                        ->skipReportSummary(true)
                        ->build();

                $reportSession = (new AdWordsSessionBuilder())
                        ->withOAuth2Credential($this->_oauth)
                        ->withDeveloperToken($this->_authsource['dev_token'])
                        ->withReportSettings($reportSettings)
                        ->withClientCustomerId($accountId)
                        ->withSoapLogger($this->_adwordsLogger)
                        ->build();

                $reportSelector = new Selector();
                if (empty($fields))
                {
                    $fields = array('Date', 'Clicks', 'Impressions', 'Cost', 'AveragePosition', 'Conversions', 'ConversionValue');
                }
                $reportSelector->setFields($fields);
                if (!empty($dateFrom))
                {
                    $dateRange = new DateRange();
                    $fromDate = new \Score\Time($dateFrom['mon'] . '/' . $dateFrom['mday'] . '/' . $dateFrom['year']);
                    $toDate = new \Score\Time($dateTo['mon'] . '/' . $dateTo['mday'] . '/' . $dateTo['year']);
                    $dateRange->setMin($fromDate->format('Ymd'));
                    $dateRange->setMax($toDate->format('Ymd'));
                    $reportSelector->setDateRange($dateRange);
                }

I am having an issue trying to find the correct way to get aggregate information for the fields:

'Date', 'Clicks', 'Impressions', 'Cost', 'AveragePosition', 'Conversions', 'ConversionValue'


to help me get there and although it appears to return a lot of data, it is hard to determine exactly what it is since it comes back as the GoogleAdsRow object. When trying to 'getSegments()' from this in order to get the Date field, for example, the object returned is null.

Is there any resource for converting adwords reports to the Google Ads API ? Are there methods to get the Google Ads API to simply return a CSV file of the data I'm wanting?

Help would be appreciated, thanks.

Derek

Derek Piper

unread,
Feb 8, 2022, 6:55:46 PM2/8/22
to Google Ads API and AdWords API Forum

To update this, I have made progress and have the Day field now by pulling in segments.date as a query field. Thought I had tried that before but for whatever reason redoing things got that part working.

I realized I needed to update the query I was using to this:

$query =
                    "SELECT "
                    . "segments.date, "
                    . "metrics.impressions, "
                    . "metrics.clicks, "
                    . "metrics.conversions_by_conversion_date, "
                    . "metrics.conversions, "
                    . "metrics.conversions_value, "
                    . "metrics.cost_micros "
                    . "FROM keyword_view ";

and my date range query would be
$query .= "WHERE segments.date >= '" . $fromDate->format('Y-m-d') . "' AND segments.date <= '" . $toDate->format('Y-m-d') . "' ";

Adding this in case it helps anyone else.

Google Ads API Forum Advisor

unread,
Feb 9, 2022, 5:07:20 AM2/9/22
to dcp...@gmail.com, adwor...@googlegroups.com

Hi Derek,

Thanks for reaching out to the Google Ads API Forum.

For your question “Is there any resource for converting adwords reports to the Google Ads API ?”, you may refer to our Query Migration Tool. This tool helps to translate AWQL queries into GAQL. For more information, please refer to this page.

With regards to Keyword view GAQL, you may use the following GAQL:

SELECT metrics.impressions, metrics.clicks, metrics.conversions_by_conversion_date, metrics.conversions, metrics.conversions_value, metrics.cost_micros, segments.date FROM keyword_view WHERE segments.date >= '2022-01-01' AND segments.date <= '2022-02-01'

Also, you make use of our keyword_view_query_builder to construct a query.

Let us know if you have any further questions.

Regards,

Google Logo
Yasar
Google Ads API Team
 

 

 



ref:_00D1U1174p._5004Q2W5Wv9:ref
Reply all
Reply to author
Forward
0 new messages