-
Notifications
You must be signed in to change notification settings - Fork 3.7k
/
brands_video_report.py
95 lines (86 loc) · 2.39 KB
/
brands_video_report.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
#
# Copyright (c) 2022 Airbyte, Inc., all rights reserved.
#
from .report_streams import ReportStream
METRICS_MAP = {
"keywords": [
"campaignName",
"campaignId",
"campaignStatus",
"campaignBudget",
"campaignBudgetType",
"campaignRuleBasedBudget",
"applicableBudgetRuleId",
"applicableBudgetRuleName",
"adGroupName",
"adGroupId",
"keywordText",
"keywordBid",
"keywordStatus",
"targetId",
"targetingExpression",
"targetingText",
"targetingType",
"matchType",
"impressions",
"clicks",
"cost",
"attributedSales14d",
"attributedSales14dSameSKU",
"attributedConversions14d",
"attributedConversions14dSameSKU",
],
"adGroups": [
"campaignName",
"campaignId",
"campaignStatus",
"campaignBudget",
"campaignBudgetType",
"adGroupName",
"adGroupId",
"impressions",
"clicks",
"cost",
"attributedSales14d",
"attributedSales14dSameSKU",
"attributedConversions14d",
"attributedConversions14dSameSKU",
],
"campaigns": [
"campaignName",
"campaignId",
"campaignStatus",
"campaignBudget",
"campaignBudgetType",
"campaignRuleBasedBudget",
"applicableBudgetRuleId",
"applicableBudgetRuleName",
"impressions",
"clicks",
"cost",
"attributedSales14d",
"attributedSales14dSameSKU",
"attributedConversions14d",
"attributedConversions14dSameSKU",
],
}
METRICS_TYPE_TO_ID_MAP = {
"keywords": "keywordBid",
"adGroups": "adGroupId",
"campaigns": "campaignId",
}
class SponsoredBrandsVideoReportStream(ReportStream):
"""
https://advertising.amazon.com/API/docs/en-us/reference/sponsored-brands/2/reports
"""
def report_init_endpoint(self, record_type: str) -> str:
return f"/v2/hsa/{record_type}/report"
metrics_map = METRICS_MAP
metrics_type_to_id_map = METRICS_TYPE_TO_ID_MAP
def _get_init_report_body(self, report_date: str, record_type: str, profile):
metrics_list = self.metrics_map[record_type]
body = {
"reportDate": report_date,
"creativeType": "video",
}
return {**body, "metrics": ",".join(metrics_list)}