Skip to content

Commit

Permalink
🐛 Source Amazon Ads: Add missing reporting metrics to the source conn…
Browse files Browse the repository at this point in the history
…ector (#25412)

* Add missing reporting metrics to source connector for Amazon Ads

* update changelog

* correct version
  • Loading branch information
Shishir-rmv committed May 25, 2023
1 parent 87f277f commit 26c5cc0
Show file tree
Hide file tree
Showing 6 changed files with 171 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,5 @@ ENTRYPOINT ["python", "/airbyte/integration_code/main.py"]



LABEL io.airbyte.version=1.0.6
LABEL io.airbyte.version=1.1.0
LABEL io.airbyte.name=airbyte/source-amazon-ads
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,7 @@
"keywordText",
"keywordBid",
"keywordStatus",
"targetId",
"searchTermImpressionRank",
"targetingExpression",
"targetingText",
"targetingType",
"matchType",
"impressions",
"clicks",
Expand All @@ -42,6 +38,9 @@
"attributedUnitsOrderedNewToBrandPercentage14d",
"unitsSold14d",
"dpv14d",
"attributedBrandedSearches14d",
"keywordId",
"searchTermImpressionShare",
],
"adGroups": [
"campaignName",
Expand All @@ -68,6 +67,7 @@
"attributedUnitsOrderedNewToBrandPercentage14d",
"unitsSold14d",
"dpv14d",
"attributedBrandedSearches14d",
],
"campaigns": [
"campaignName",
Expand Down Expand Up @@ -95,6 +95,7 @@
"attributedUnitsOrderedNewToBrandPercentage14d",
"unitsSold14d",
"dpv14d",
"attributedBrandedSearches14d",
],
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,11 @@
"campaignStatus",
"campaignBudget",
"campaignBudgetType",
"campaignRuleBasedBudget",
"applicableBudgetRuleId",
"applicableBudgetRuleName",
"adGroupName",
"adGroupId",
"keywordText",
"keywordBid",
"keywordStatus",
"targetId",
"targetingExpression",
"targetingText",
"targetingType",
"matchType",
"impressions",
"clicks",
Expand All @@ -31,6 +24,27 @@
"attributedSales14dSameSKU",
"attributedConversions14d",
"attributedConversions14dSameSKU",
"attributedBrandedSearches14d",
"attributedDetailPageViewsClicks14d",
"attributedOrderRateNewToBrand14d",
"attributedOrdersNewToBrand14d",
"attributedOrdersNewToBrandPercentage14d",
"attributedSalesNewToBrand14d",
"attributedSalesNewToBrandPercentage14d",
"attributedUnitsOrderedNewToBrand14d",
"attributedUnitsOrderedNewToBrandPercentage14d",
"dpv14d",
"keywordId",
"vctr",
"video5SecondViewRate",
"video5SecondViews",
"videoCompleteViews",
"videoFirstQuartileViews",
"videoMidpointViews",
"videoThirdQuartileViews",
"videoUnmutes",
"viewableImpressions",
"vtr",
],
"adGroups": [
"campaignName",
Expand All @@ -47,23 +61,60 @@
"attributedSales14dSameSKU",
"attributedConversions14d",
"attributedConversions14dSameSKU",
"vctr",
"video5SecondViewRate",
"video5SecondViews",
"videoCompleteViews",
"videoFirstQuartileViews",
"videoMidpointViews",
"videoThirdQuartileViews",
"videoUnmutes",
"viewableImpressions",
"vtr",
"dpv14d",
"attributedDetailPageViewsClicks14d",
"attributedOrderRateNewToBrand14d",
"attributedOrdersNewToBrand14d",
"attributedOrdersNewToBrandPercentage14d",
"attributedSalesNewToBrand14d",
"attributedSalesNewToBrandPercentage14d",
"attributedUnitsOrderedNewToBrand14d",
"attributedUnitsOrderedNewToBrandPercentage14d",
"attributedBrandedSearches14d",
],
"campaigns": [
"campaignName",
"campaignId",
"campaignStatus",
"campaignBudget",
"campaignBudgetType",
"campaignRuleBasedBudget",
"applicableBudgetRuleId",
"applicableBudgetRuleName",
"impressions",
"clicks",
"cost",
"attributedSales14d",
"attributedSales14dSameSKU",
"attributedConversions14d",
"attributedConversions14dSameSKU",
"attributedSalesNewToBrand14d",
"attributedSalesNewToBrandPercentage14d",
"attributedUnitsOrderedNewToBrand14d",
"attributedUnitsOrderedNewToBrandPercentage14d",
"attributedBrandedSearches14d",
"attributedDetailPageViewsClicks14d",
"attributedOrderRateNewToBrand14d",
"attributedOrdersNewToBrand14d",
"attributedOrdersNewToBrandPercentage14d",
"dpv14d",
"vctr",
"video5SecondViewRate",
"video5SecondViews",
"videoCompleteViews",
"videoFirstQuartileViews",
"videoMidpointViews",
"videoThirdQuartileViews",
"videoUnmutes",
"viewableImpressions",
"vtr",
],
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,20 @@
"attributedOrdersNewToBrand14d",
"attributedSalesNewToBrand14d",
"attributedUnitsOrderedNewToBrand14d",
"costType",
"campaignBudget",
"campaignStatus",
"attributedBrandedSearches14d",
"attributedDetailPageView14d",
"viewAttributedBrandedSearches14d",
"viewAttributedConversions14d",
"viewAttributedDetailPageView14d",
"viewAttributedOrdersNewToBrand14d",
"viewAttributedSales14d",
"viewAttributedSalesNewToBrand14d",
"viewAttributedUnitsOrdered14d",
"viewAttributedUnitsOrderedNewToBrand14d",
"viewImpressions",
],
"adGroups": [
"campaignName",
Expand Down Expand Up @@ -68,16 +82,27 @@
"attributedSales14dSameSKU",
"attributedSales30dSameSKU",
"attributedOrdersNewToBrand14d",
"attributedSalesNewToBrand14d",
"attributedUnitsOrderedNewToBrand14d",
"attributedBrandedSearches14d",
"attributedDetailPageView14d",
"bidOptimization",
"viewAttributedBrandedSearches14d",
"viewAttributedConversions14d",
"viewAttributedDetailPageView14d",
"viewAttributedOrdersNewToBrand14d",
"viewAttributedSales14d",
"viewAttributedSalesNewToBrand14d",
"viewAttributedUnitsOrdered14d",
"viewAttributedUnitsOrderedNewToBrand14d",
"viewImpressions",
],
"productAds": [
"campaignName",
"campaignId",
"adGroupName",
"adGroupId",
"asin",
"sku",
"sku", # Available for seller accounts only.
"adId",
"impressions",
"clicks",
Expand Down Expand Up @@ -106,6 +131,17 @@
"attributedOrdersNewToBrand14d",
"attributedSalesNewToBrand14d",
"attributedUnitsOrderedNewToBrand14d",
"attributedBrandedSearches14d",
"attributedDetailPageView14d",
"viewAttributedBrandedSearches14d",
"viewAttributedConversions14d",
"viewAttributedDetailPageView14d",
"viewAttributedOrdersNewToBrand14d",
"viewAttributedSales14d",
"viewAttributedSalesNewToBrand14d",
"viewAttributedUnitsOrdered14d",
"viewAttributedUnitsOrderedNewToBrand14d",
"viewImpressions",
],
"targets": [
"campaignName",
Expand Down Expand Up @@ -143,6 +179,17 @@
"attributedOrdersNewToBrand14d",
"attributedSalesNewToBrand14d",
"attributedUnitsOrderedNewToBrand14d",
"attributedBrandedSearches14d",
"attributedDetailPageView14d",
"viewAttributedBrandedSearches14d",
"viewAttributedConversions14d",
"viewAttributedDetailPageView14d",
"viewAttributedOrdersNewToBrand14d",
"viewAttributedSales14d",
"viewAttributedSalesNewToBrand14d",
"viewAttributedUnitsOrdered14d",
"viewAttributedUnitsOrderedNewToBrand14d",
"viewImpressions",
],
"asins": [
"campaignName",
Expand All @@ -151,7 +198,7 @@
"adGroupId",
"asin",
"otherAsin",
"sku",
"sku", # Available for seller accounts only.
"currency",
"attributedUnitsOrdered1dOtherSKU",
"attributedUnitsOrdered7dOtherSKU",
Expand Down Expand Up @@ -187,11 +234,15 @@ def report_init_endpoint(self, record_type: str) -> str:
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]
if record_type == RecordType.ASINS and profile.accountInfo.type == "vendor":
return None
elif record_type == RecordType.PRODUCTADS and profile.accountInfo.type != "seller":
# Remove SKU from metrics since it is only available for seller accounts in Product Ad report
metrics_list = [m for m in metrics_list if m != "sku"]
return {
"reportDate": report_date,
# Only for most common T00020 tactic for now
"tactic": Tactics.T00020,
"metrics": ",".join(self.metrics_map[record_type]),
"metrics": ",".join(metrics_list),
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
# Copyright (c) 2023 Airbyte, Inc., all rights reserved.
#

import json
import re
from base64 import b64decode
from datetime import timedelta
Expand All @@ -27,7 +28,12 @@
SponsoredProductCampaigns,
SponsoredProductsReportStream,
)
from source_amazon_ads.streams.report_streams.report_streams import ReportGenerationFailure, ReportGenerationInProgress, TooManyRequests
from source_amazon_ads.streams.report_streams.report_streams import (
RecordType,
ReportGenerationFailure,
ReportGenerationInProgress,
TooManyRequests,
)

from .utils import read_incremental

Expand Down Expand Up @@ -199,6 +205,47 @@ def test_display_report_stream(config):
assert len(metrics) == METRICS_COUNT * (len(stream.metrics_map) - 1)


@pytest.mark.parametrize(
("profiles", "stream_class", "url_pattern", "expected"),
[
(
make_profiles(),
SponsoredDisplayReportStream,
r"https://advertising-api.amazon.com/sd/([a-zA-Z]+)/report",
True,
),
(
make_profiles(profile_type="vendor"),
SponsoredDisplayReportStream,
r"https://advertising-api.amazon.com/sd/([a-zA-Z]+)/report",
False,
),
],
)
@responses.activate
def test_stream_report_body_metrics(config, profiles, stream_class, url_pattern, expected):
setup_responses(
init_response=REPORT_INIT_RESPONSE,
init_response_products=REPORT_INIT_RESPONSE,
status_response=REPORT_STATUS_RESPONSE,
metric_response=METRIC_RESPONSE,
)

stream = stream_class(config, profiles, authenticator=mock.MagicMock())
stream_slice = {"profile": profiles[0], "reportDate": "20210725"}
list(stream.read_records(SyncMode.incremental, stream_slice=stream_slice))
for call in responses.calls:
create_report_pattern = re.compile(url_pattern)
for match in create_report_pattern.finditer(call.request.url):
record_type = match.group(1)
request_body = call.request.body
request_metrics = json.loads(request_body.decode("utf-8"))["metrics"]
if record_type == RecordType.PRODUCTADS or record_type == RecordType.ASINS:
assert ("sku" in request_metrics) == expected
else:
assert "sku" not in request_metrics


@responses.activate
def test_products_report_stream(config):
setup_responses(
Expand Down
1 change: 1 addition & 0 deletions docs/integrations/sources/amazon-ads.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ Information about expected report generation waiting time you may find [here](ht

| Version | Date | Pull Request | Subject |
|:--------|:-----------|:---------------------------------------------------------|:----------------------------------------------------------------------------------------------------------------|
| 1.1.0 | 2023-04-22 | [25412](https://github.com/airbytehq/airbyte/pull/25412) | Add missing reporting metrics |
| 1.0.6 | 2023-05-09 | [25913](https://github.com/airbytehq/airbyte/pull/25913) | Small schema fixes |
| 1.0.5 | 2023-05-08 | [25885](https://github.com/airbytehq/airbyte/pull/25885) | Improve error handling for attribution_report(s) streams |
| 1.0.4 | 2023-05-04 | [25792](https://github.com/airbytehq/airbyte/pull/25792) | Add availability strategy for basic streams (not including report streams) |
Expand Down

0 comments on commit 26c5cc0

Please sign in to comment.