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

Fix bug where AnalyticsServices fires same event multiple times #1210

Merged
merged 11 commits into from
Mar 11, 2024

Conversation

scannillo
Copy link
Contributor

@scannillo scannillo commented Mar 7, 2024

Summary

  • This PR came out of this conversation in a previous PR
  • We found a bug where every analytic event was being sent multiple times
    • The reason why was because our sessionsQueue was never being wiped after events were already sent out in an API request
  • This PR takes a path-of-least-resistance approach to fixing this duplicate events bug
    • It uses the existing batch POST formatting, but only sends a single event per API request
    • Previously we were still sending an API request every time sendAnalyticsEvent() was called, but with this change, the payload won't contain duplicate events
    • Our batching logic needs a dedicated revamp (handling app backgrounding, memory wipe, etc) - JIRA DTBTSDK-3629 created

Changes

  • Remove unused flushThreshold & flush logic (this was never called within the SDK)
  • Remove improperly managed DispatchQueue for holding events. This was never getting cleared, thus sending every event multiple times. We can re-add this when we have more time to properly implement the queue's maintenance and clearance.
  • Move to async-await style for BTAnalyticsService.sendAnalyticsEvent() method

Checklist

  • Added a changelog entry

Authors

@scannillo @jaxdesmarais

apiClient.fetchOrReturnRemoteConfiguration { configuration, error in
guard let configuration, error == nil else {
if let error {
completion(error)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This completion was always ignored, so we removed it entirely

Copy link
Contributor

Choose a reason for hiding this comment

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

Curious why this is happening, thoughts?

Copy link
Contributor

Choose a reason for hiding this comment

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

BTAPIClient was always no-oping the result of this completion. I don't think we would ever want to return an error to the merchant and stop the flow if there is an issue with analytics since that's just for us, so this is safe for us to remove since we just discarded the result.

@scannillo scannillo marked this pull request as ready for review March 7, 2024 21:11
@scannillo scannillo requested a review from a team as a code owner March 7, 2024 21:11
Copy link
Contributor

@jaxdesmarais jaxdesmarais left a comment

Choose a reason for hiding this comment

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

Love how this bug also got rid of our recently problematic tests. 😂

Sources/BraintreeCore/Analytics/BTAnalyticsService.swift Outdated Show resolved Hide resolved
scannillo and others added 2 commits March 8, 2024 13:00
# Conflicts:
#	CHANGELOG.md
#	Sources/BraintreeCore/Analytics/BTAnalyticsService.swift
#	Sources/BraintreeCore/BTAPIClient.swift
#	UnitTests/BraintreeCoreTests/Analytics/FakeAnalyticsService.swift
Copy link
Contributor

@agedd agedd left a comment

Choose a reason for hiding this comment

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

looks great and super clean! 🚀

@jaxdesmarais jaxdesmarais merged commit e48237a into main Mar 11, 2024
7 checks passed
@jaxdesmarais jaxdesmarais deleted the fix-duplicate-analytic-send branch March 11, 2024 18:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants