Skip to content

Commit

Permalink
Add option to ignore deleted campaigns. Add breaking changes to chang…
Browse files Browse the repository at this point in the history
…elog
  • Loading branch information
apisarenco committed Jul 9, 2019
1 parent eb9b0c9 commit 207d8cd
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 16 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,13 @@
## 4.0.0 (2019-07-05)

- Compatible with specifications: a unique identifier is an Ad ID + Ad Group ID.
- Add option to ignore downloading of data related to removed campaigns

**required changes**

- The file format changed to `v5`. Adapt etl scripts that process the output data.
- Ad ID no longer unique in any files
- Ad performance datasets now include Ad Group Id

## 3.0.0 (2019-04-13)

Expand Down
5 changes: 5 additions & 0 deletions google_ads_downloader/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,3 +62,8 @@ def max_retries() -> int:
def retry_backoff_factor() -> int:
"""How many seconds to wait between retries (is multiplied with retry count)"""
return 5


def ignore_removed_campaigns() -> bool:
"""Whether to ignore campaigns with status 'REMOVED'"""
return False
55 changes: 39 additions & 16 deletions google_ads_downloader/downloader.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,22 +101,32 @@ def download_data_sets(api_client: AdWordsApiClient):
api_client: AdWordsApiClient
"""

predicates = [{'field': 'Status',
'operator': 'IN',
'values': ['ENABLED',
'PAUSED',
'DISABLED']
}, {
'field': 'Impressions',
'operator': 'GREATER_THAN',
'values': [0]
}]

if config.ignore_removed_campaigns():
predicates.append({
'field': 'CampaignStatus',
'operator': 'NOT_EQUALS',
'values': 'REMOVED'
})

download_performance(api_client,
PerformanceReportType.AD_PERFORMANCE_REPORT,
fields=['Date', 'Id', 'AdGroupId', 'Device', 'AdNetworkType2',
'ActiveViewImpressions', 'AveragePosition',
'Clicks', 'Conversions', 'ConversionValue',
'Cost', 'Impressions'],
predicates=[{'field': 'Status',
'operator': 'IN',
'values': ['ENABLED',
'PAUSED',
'DISABLED']
}, {
'field': 'Impressions',
'operator': 'GREATER_THAN',
'values': [0]
}]
predicates=predicates
)

download_account_structure(api_client)
Expand Down Expand Up @@ -316,18 +326,31 @@ def get_ad_data(api_client: AdWordsApiClient, client_customer_id: int) -> [{}]:
logging.info('get ad data for account {}'.format(client_customer_id))

api_client.SetClientCustomerId(client_customer_id)

predicates = [
{
'field': 'Status',
'operator': 'IN',
'values': ['ENABLED',
'PAUSED',
'DISABLED']
}
]

if config.ignore_removed_campaigns():
predicates.append({
'field': 'CampaignStatus',
'operator': 'NOT_EQUALS',
'values': 'REMOVED'
})

report = _download_adwords_report(api_client,
report_type='AD_PERFORMANCE_REPORT',
fields=['Id', 'AdGroupId', 'AdGroupName',
'CampaignId', 'CampaignName',
'Labels', 'Headline', 'AdType',
'Status'],
predicates={'field': 'Status',
'operator': 'IN',
'values': ['ENABLED',
'PAUSED',
'DISABLED']
})
predicates=predicates)

ad_data = []
for row in report:
Expand Down

0 comments on commit 207d8cd

Please sign in to comment.