Campaign Location Report - All Targeted locations for each campaign

74 views
Skip to first unread message

Carson W

unread,
May 22, 2020, 3:09:18 PM5/22/20
to AdWords API and Google Ads API Forum
Hello,

I'm attempting to replicate the Targeted Locations view within the UI and am working through the best way to replicate this. Currently, I'm attempting to use the "Campaign Location Target Report" and using an AWQL pull (below).
To get these results for all targeted locations across all campaigns, I'm unsure as to if this is the best call to be making. 

I've made a separate call that pulls every campaign ID and all of the corresponding targeted location ID's and values.
That call was using the "CampaignCriterionService", but I was unable to discern how to pull in metrics associated to the selectors. 

Brand new to AdWords API and would appreciate any help/guidance. The docs are a lot to take in when first starting out.



Both Using Python 3.7

AWQL Report Call:
***Anyone know how to push results to a DataFrame instead of exporting as CSV?***
-- Provides a "Bad Request" error, Invalid Field Name --

def main(client):
    report_downloader = client.GetReportDownloader(version='v201809')

    report_query = (adwords.ReportQueryBuilder()
                  .Select('CampaignId','Id', 'Criteria','Date',
                          'Impressions', 'Clicks','Cost')
                  .From('CAMPAIGN_LOCATION_TARGET_REPORT')
                  .Where('CampaignStatus').In('ENABLED', 'PAUSED')
                  .During('LAST_7_DAYS')
                  .Build())
    
    report_downloader.DownloadReportWithAwql(
      report_query, 'CSV', PATH, skip_report_header=False,
      skip_column_header=False, skip_report_summary=False)


Campaign Criterion Call To Pull All Campaign ID's with targeted locations and sending to DataFrame:
*** was unable to figure out how to add date filtering or associated metrics (spend, cost, clicks etc)  in this type of call ***

def main(client):
    count = 0
    # Specifying which specific call, in this case it's campaign criterion.
    campaign_criterion_service = client.GetService('CampaignCriterionService', version='v201809')

    # Construct selectors and filters.
    offset = 0
    selector = {
    'fields': ['CampaignId', 'Id',
               'CriteriaType',
               #'PlatformName',
                #'LanguageName',
               'LocationName'
               #'KeywordText'
               ],
    'predicates': [{
        'field': 'CriteriaType',
        'operator': 'IN',
        'values': [#'KEYWORD',
                   #'LANGUAGE',
                   'LOCATION'
                   #'PLATFORM'
        ]
        # 'dateRange': 'LAST_MONTH'
        }],
    # 'dateRange': 'THIS_MONTH',
    'paging': {
        'startIndex': str(offset),
        'numberResults': str(PAGE_SIZE)}}


    more_pages = True
    while more_pages:
        page = campaign_criterion_service.get(selector)

    # Printing Results HERE
        if 'entries' in page:
            for campaign_criterion in page['entries']:
                criterion = campaign_criterion['criterion']
                criteria = (criterion['locationName'] if 'locationName' in criterion else None)

                df.loc[count, 'Id'] = campaign_criterion["campaignId"]
                df.loc[count, 'Location'] = criterion["type"]
                df.loc[count, 'Location_Value'] = criteria

                count += 1

                print((campaign_criterion['campaignId'], criterion['type'], criteria))
        else:
            print('No campaign targets were found.')
        offset += PAGE_SIZE
        selector['paging']['startIndex'] = str(offset)
        more_pages = offset < int(page['totalNumEntries'])

# Formatting 5 digit zips w/ leading 0's
    N = 5
    df['Location_Value'] = df['Location_Value'].astype(str)
    df['Location_Value'] = df['Location_Value'].str.zfill(N)

** 

Google Ads API Forum Advisor Prod

unread,
May 26, 2020, 9:43:19 AM5/26/20
to cwhi...@budgetdumpster.com, adwor...@googlegroups.com
Hi Carson,

Thank you for reaching out. In order to pull the metrics for all targeted locations in all campaigns, you should use the Campaign Location Target report. The Id field will return the location ID and the CampaignId field will return the campaign IDs. In the example you shared, you tried to select "Criteria" however this is not a supported attribute in this report and should not be included. If you are interested in mapping the location ID to the location, you can find the mappings here.

Regards,
Mitchell
Google Ads API Team

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