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

Feat/appsflyer #44

Open
wants to merge 10 commits into
base: main
Choose a base branch
from
Open

Feat/appsflyer #44

wants to merge 10 commits into from

Conversation

sanjushahgupta
Copy link
Collaborator

@sanjushahgupta sanjushahgupta commented Oct 16, 2024

The following changes are made in this PR:

  • date partitioning to fetch all requested data
  • handle end date for cohort metrics
  • use install time as the incremental key

@sanjushahgupta sanjushahgupta added the bug Something isn't working label Oct 16, 2024
@sanjushahgupta sanjushahgupta marked this pull request as ready for review October 17, 2024 11:49
@dlt.resource(write_disposition="merge", merge_key="install_time")
def campaigns() -> Iterable[TDataItem]:
yield from client.fetch_campaigns(start_date, end_date)
@dlt.resource(write_disposition="merge", merge_key="Install Time")
Copy link
Contributor

Choose a reason for hiding this comment

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

the key is supposed to be as the fields in JSON, why did you go with Install Time instead of the previous version?

Copy link
Collaborator Author

@sanjushahgupta sanjushahgupta Oct 20, 2024

Choose a reason for hiding this comment

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

Because "Install Time" is the JSON key not "install_time". My understanding was wrong.

def campaigns(
updated=dlt.sources.incremental('["Install Time"]', start_date_obj.isoformat()),
) -> Iterable[TDataItem]:
current_start_time = datetime.fromisoformat(updated.start_value).date()
Copy link
Contributor

Choose a reason for hiding this comment

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

shouldn't this be updated.last_value?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

While testing, both start_value and last_value were giving the same value, so I used start_value.

yield from client.fetch_campaigns(
start_date=current_start_time.isoformat(), end_date=next_end_date.isoformat()
)
print(current_start_time, next_end_date)
Copy link
Contributor

Choose a reason for hiding this comment

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

we shouldn't print this

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Done

current_start_time = datetime.fromisoformat(updated.start_value).date()
end_date_time = datetime.fromisoformat(end_date).date()

while current_start_time < end_date_time:
Copy link
Contributor

Choose a reason for hiding this comment

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

I'd move this logic into the internal appsflyer client so that we don't have to repeat it

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Done

Comment on lines 95 to 98
max_cohort_duration = 7
max_allowed_end_date = (datetime.now() - timedelta(days=max_cohort_duration)).strftime('%Y-%m-%d')
adjusted_end_date = min(end_date, max_allowed_end_date)
return self._fetch_data(start_date, adjusted_end_date, metrics=metrics)
Copy link
Contributor

Choose a reason for hiding this comment

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

why?

Copy link
Collaborator Author

@sanjushahgupta sanjushahgupta Oct 20, 2024

Choose a reason for hiding this comment

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

We can only fetch cohort metric data up to last seven days. If a user tries to fetch cohort data for today, Appsflyer shows an error "429." To handle this, we limit the end date to 7 days before the current date. For example, if a user is trying to fetch data from 2024-09-10 to 2024-10-20, the data will be fetched from 2024-09-10 to 2024-10-13 instead. Otherwise, it will show an error, and we won't be able to fetch data (this issue occurs only in the campaigns resource).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants