Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🎉 Source Facebook Marketing: Allow configuring insights lookback window #3396

Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"sourceDefinitionId": "e7778cfc-e97c-4458-9ecb-b4f2bba8946c",
"name": "Facebook Marketing",
"dockerRepository": "airbyte/source-facebook-marketing",
"dockerImageTag": "0.2.4",
"dockerImageTag": "0.2.5",
"documentationUrl": "https://hub.docker.com/r/airbyte/source-facebook-marketing",
"icon": "facebook.svg"
}
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@
- sourceDefinitionId: e7778cfc-e97c-4458-9ecb-b4f2bba8946c
name: Facebook Marketing
dockerRepository: airbyte/source-facebook-marketing
dockerImageTag: 0.2.4
dockerImageTag: 0.2.5
documentationUrl: https://hub.docker.com/r/airbyte/source-facebook-marketing
icon: facebook.svg
- sourceDefinitionId: 36c891d9-4bd9-43ac-bad2-10e12756272c
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,5 @@ COPY $CODE_PATH ./$CODE_PATH
COPY setup.py ./
RUN pip install .

LABEL io.airbyte.version=0.2.4
LABEL io.airbyte.version=0.2.5
LABEL io.airbyte.name=airbyte/source-facebook-marketing
Original file line number Diff line number Diff line change
Expand Up @@ -330,11 +330,11 @@ class AdsInsightAPI(IncrementalStreamAPI):
level = "ad"
action_attribution_windows = ALL_ACTION_ATTRIBUTION_WINDOWS
time_increment = 1
buffer_days = 28

def __init__(self, api, start_date, breakdowns=None):
def __init__(self, api, start_date, breakdowns=None, buffer_days=28):
super().__init__(api=api)
self.start_date = start_date
self.buffer_days = buffer_days
self._state = start_date
self.breakdowns = breakdowns

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,23 +40,37 @@


class Client(BaseClient):
def __init__(self, account_id: str, access_token: str, start_date: str, include_deleted: bool = False):
def __init__(
self, account_id: str, access_token: str, start_date: str, include_deleted: bool = False, insights_lookback_window: int = 28
):
self._account_id = account_id
self._start_date = pendulum.parse(start_date)
self._insights_lookback_window = insights_lookback_window

self._api = FacebookAdsApi.init(access_token=access_token)
self._apis = {
"campaigns": CampaignAPI(self, include_deleted=include_deleted),
"adsets": AdSetsAPI(self, include_deleted=include_deleted),
"ads": AdsAPI(self, include_deleted=include_deleted),
"adcreatives": AdCreativeAPI(self),
"ads_insights": AdsInsightAPI(self, start_date=self._start_date),
"ads_insights_age_and_gender": AdsInsightAPI(self, start_date=self._start_date, breakdowns=["age", "gender"]),
"ads_insights_country": AdsInsightAPI(self, start_date=self._start_date, breakdowns=["country"]),
"ads_insights_region": AdsInsightAPI(self, start_date=self._start_date, breakdowns=["region"]),
"ads_insights_dma": AdsInsightAPI(self, start_date=self._start_date, breakdowns=["dma"]),
"ads_insights": AdsInsightAPI(self, start_date=self._start_date, buffer_days=self._insights_lookback_window),
"ads_insights_age_and_gender": AdsInsightAPI(
self, start_date=self._start_date, breakdowns=["age", "gender"], buffer_days=self._insights_lookback_window
),
"ads_insights_country": AdsInsightAPI(
self, start_date=self._start_date, breakdowns=["country"], buffer_days=self._insights_lookback_window
),
"ads_insights_region": AdsInsightAPI(
self, start_date=self._start_date, breakdowns=["region"], buffer_days=self._insights_lookback_window
),
"ads_insights_dma": AdsInsightAPI(
self, start_date=self._start_date, breakdowns=["dma"], buffer_days=self._insights_lookback_window
),
"ads_insights_platform_and_device": AdsInsightAPI(
self, start_date=self._start_date, breakdowns=["publisher_platform", "platform_position", "impression_device"]
self,
start_date=self._start_date,
breakdowns=["publisher_platform", "platform_position", "impression_device"],
buffer_days=self._insights_lookback_window,
),
}
super().__init__()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,15 @@
"include_deleted": {
"type": "boolean",
"description": "Include data from deleted campaigns, ads, and adsets.",
"default": false
"default": "false"
},
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is the first step, but this needs to be passed into the connector so it would actually use this value.

Also, could you add a test using a mocked HTTP request to verify this works?

"insights_lookback_window": {
"type": "integer",
"title": "Insights Lookback Window",
"description": "The attribution window for the actions",
"minimum": 0,
"maximum": 28,
"default": 28
}
}
}
Expand Down