Skip to content

Commit 207d8cd

Browse files
committed
Add option to ignore deleted campaigns. Add breaking changes to changelog
1 parent eb9b0c9 commit 207d8cd

File tree

3 files changed

+51
-16
lines changed

3 files changed

+51
-16
lines changed

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,13 @@
33
## 4.0.0 (2019-07-05)
44

55
- Compatible with specifications: a unique identifier is an Ad ID + Ad Group ID.
6+
- Add option to ignore downloading of data related to removed campaigns
7+
8+
**required changes**
9+
10+
- The file format changed to `v5`. Adapt etl scripts that process the output data.
11+
- Ad ID no longer unique in any files
12+
- Ad performance datasets now include Ad Group Id
613

714
## 3.0.0 (2019-04-13)
815

google_ads_downloader/config.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,3 +62,8 @@ def max_retries() -> int:
6262
def retry_backoff_factor() -> int:
6363
"""How many seconds to wait between retries (is multiplied with retry count)"""
6464
return 5
65+
66+
67+
def ignore_removed_campaigns() -> bool:
68+
"""Whether to ignore campaigns with status 'REMOVED'"""
69+
return False

google_ads_downloader/downloader.py

Lines changed: 39 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -101,22 +101,32 @@ def download_data_sets(api_client: AdWordsApiClient):
101101
api_client: AdWordsApiClient
102102
103103
"""
104+
105+
predicates = [{'field': 'Status',
106+
'operator': 'IN',
107+
'values': ['ENABLED',
108+
'PAUSED',
109+
'DISABLED']
110+
}, {
111+
'field': 'Impressions',
112+
'operator': 'GREATER_THAN',
113+
'values': [0]
114+
}]
115+
116+
if config.ignore_removed_campaigns():
117+
predicates.append({
118+
'field': 'CampaignStatus',
119+
'operator': 'NOT_EQUALS',
120+
'values': 'REMOVED'
121+
})
122+
104123
download_performance(api_client,
105124
PerformanceReportType.AD_PERFORMANCE_REPORT,
106125
fields=['Date', 'Id', 'AdGroupId', 'Device', 'AdNetworkType2',
107126
'ActiveViewImpressions', 'AveragePosition',
108127
'Clicks', 'Conversions', 'ConversionValue',
109128
'Cost', 'Impressions'],
110-
predicates=[{'field': 'Status',
111-
'operator': 'IN',
112-
'values': ['ENABLED',
113-
'PAUSED',
114-
'DISABLED']
115-
}, {
116-
'field': 'Impressions',
117-
'operator': 'GREATER_THAN',
118-
'values': [0]
119-
}]
129+
predicates=predicates
120130
)
121131

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

318328
api_client.SetClientCustomerId(client_customer_id)
329+
330+
predicates = [
331+
{
332+
'field': 'Status',
333+
'operator': 'IN',
334+
'values': ['ENABLED',
335+
'PAUSED',
336+
'DISABLED']
337+
}
338+
]
339+
340+
if config.ignore_removed_campaigns():
341+
predicates.append({
342+
'field': 'CampaignStatus',
343+
'operator': 'NOT_EQUALS',
344+
'values': 'REMOVED'
345+
})
346+
319347
report = _download_adwords_report(api_client,
320348
report_type='AD_PERFORMANCE_REPORT',
321349
fields=['Id', 'AdGroupId', 'AdGroupName',
322350
'CampaignId', 'CampaignName',
323351
'Labels', 'Headline', 'AdType',
324352
'Status'],
325-
predicates={'field': 'Status',
326-
'operator': 'IN',
327-
'values': ['ENABLED',
328-
'PAUSED',
329-
'DISABLED']
330-
})
353+
predicates=predicates)
331354

332355
ad_data = []
333356
for row in report:

0 commit comments

Comments
 (0)