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 duplicate event tracking and incorrect foreground event logging for push notifications #22956

Merged

Conversation

salimbraksa
Copy link
Contributor

@salimbraksa salimbraksa commented Apr 4, 2024

Fixes #22935

Description

This PR fixes an issue where the push_notification_alert_tapped event was being tracked multiple times. It ensures that push_notification_received is consistently logged upon the arrival of any notification, and push_notification_alert_tapped is recorded exclusively when the user taps the notification alert. These changes also shift the responsibility of event tracking to the caller level, thereby improving the precision of our analytics.

Test Instructions

  1. Run the Jetpack app and log in.
  2. Send a push notification to your device. ( e.g. You can setup 2 accounts, and use the 1st account to like a post of the 2nd account. The 2nd account should receive a push notification )
  3. Verify that push_notification_received is tracked, regardless of the app's state ( foreground or background ).
  4. Tap the push notification alert.
  5. Verify that push_notification_alert_tapped is tracked, and is not duplicated.

Regression Notes

  1. Potential unintended areas of impact
    This PR impacts only the analytics tracking when a push notification is received or tapped.

  2. What I did to test those areas of impact (or what existing automated tests I relied on)
    Manual testing.

  3. What automated tests I added (or what prevented me from doing so)
    None.

PR submission checklist:

  • I have completed the Regression Notes.
  • I have considered adding unit tests for my changes.
  • I have considered adding accessibility improvements for my changes.
  • I have considered if this change warrants user-facing release notes and have added them to RELEASE-NOTES.txt if necessary.

… notification is received and when it is tapped
@dangermattic
Copy link
Collaborator

dangermattic commented Apr 4, 2024

1 Warning
⚠️ PR is not assigned to a milestone.

Generated by 🚫 Danger

@@ -186,9 +186,6 @@ final public class PushNotificationsManager: NSObject {
return
}

// Analytics
trackNotification(with: userInfo)

Copy link
Contributor Author

@salimbraksa salimbraksa Apr 4, 2024

Choose a reason for hiding this comment

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

Removing this line from PushNotificationsManager.handleNotification resolved the issue of duplicated push_notification_alert_tapped analytics events. The idea is that handleNotification should only be concerned with handling the notification, irrespective of the context that triggered it (whether the notification was received in the background, or the notification alert was tapped). Analytics tracking has now been moved to the caller level.

@wpmobilebot
Copy link
Contributor

wpmobilebot commented Apr 4, 2024

WordPress Alpha📲 You can test the changes from this Pull Request in WordPress Alpha by scanning the QR code below to install the corresponding build.
App NameWordPress Alpha WordPress Alpha
ConfigurationRelease-Alpha
Build Numberpr22956-4017c7e
Version24.6
Bundle IDorg.wordpress.alpha
Commit4017c7e
App Center BuildWPiOS - One-Offs #9376
Automatticians: You can use our internal self-serve MC tool to give yourself access to App Center if needed.

return response.actionIdentifier == UNNotificationDefaultActionIdentifier ? .pushNotificationAlertPressed : nil
}
return .pushNotificationReceived
}()
Copy link
Contributor Author

@salimbraksa salimbraksa Apr 4, 2024

Choose a reason for hiding this comment

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

This logic fixes the bug where the event push_notification_alert_tapped is tracked when the app is in foreground. So the event was tracked even though the user doesn't tap the alert, which is misleading.

This event is now only tracked when the user taps the notification alert.

@wpmobilebot
Copy link
Contributor

wpmobilebot commented Apr 4, 2024

Jetpack Alpha📲 You can test the changes from this Pull Request in Jetpack Alpha by scanning the QR code below to install the corresponding build.
App NameJetpack Alpha Jetpack Alpha
ConfigurationRelease-Alpha
Build Numberpr22956-4017c7e
Version24.6
Bundle IDcom.jetpack.alpha
Commit4017c7e
App Center Buildjetpack-installable-builds #8420
Automatticians: You can use our internal self-serve MC tool to give yourself access to App Center if needed.

@salimbraksa salimbraksa marked this pull request as ready for review April 4, 2024 04:59
@salimbraksa salimbraksa changed the title Refactor push notifs analytic tracking to differentate between when a notification is received and when it is tapped Fix duplicate event tracking and incorrect foreground event logging for push notifications Apr 4, 2024
@salimbraksa salimbraksa requested a review from antonis April 4, 2024 05:03
Copy link

@antonis antonis left a comment

Choose a reason for hiding this comment

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

Thank you for fixing this @salimbraksa 🙇
I confirm that the behavior introduced with this PR aligns with how the Android push_notification_received and push_notification_alert_tapped events work.

@salimbraksa salimbraksa merged commit 0906842 into release/24.6 Apr 5, 2024
39 checks passed
@salimbraksa salimbraksa deleted the task/22935-fix-duplicated-push-notifs-analytics branch April 5, 2024 03:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants