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: add offline support for anonymous targeted user via braze notifications #8603

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from

Conversation

themooneer
Copy link
Contributor

@themooneer themooneer commented Dec 4, 2024

✅ Checklist

  • npx changeset was attached.
  • Covered by automatic tests.
  • Impact of the changes:
    • ...

📝 Description

Even when the user opt-out from analytics, it can happen that braze campaign target anonymous user via (anonymous_user_id), in this case notification impression/seen process won't be made by calling the tracking/impression request (as it's an opt-out mode). As a reinforcement layer for this scenario, LLD should support the fact that this notification is read via an store/offline indexation process.
Content card's view state will be conditioned by braze metadata and their existence or not in the anonymousUserNotifications store.

Test proof 📹

notif_OK_p1.mov

❓ Context

  • JIRA or GitHub link:

https://ledgerhq.atlassian.net/browse/LIVE-15007


🧐 Checklist for the PR Reviewers

  • The code aligns with the requirements described in the linked JIRA or GitHub issue.
  • The PR description clearly documents the changes made and explains any technical trade-offs or design decisions.
  • There are no undocumented trade-offs, technical debt, or maintainability issues.
  • The PR has been tested thoroughly, and any potential edge cases have been considered and handled.
  • Any new dependencies have been justified and documented.
  • Performance considerations have been taken into account. (changes have been profiled or benchmarked if necessary)

@themooneer themooneer requested a review from a team as a code owner December 4, 2024 16:45
Copy link

vercel bot commented Dec 4, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

4 Skipped Deployments
Name Status Preview Comments Updated (UTC)
ledger-live-github-bot ⬜️ Ignored (Inspect) Visit Preview Dec 6, 2024 1:43pm
native-ui-storybook ⬜️ Ignored (Inspect) Visit Preview Dec 6, 2024 1:43pm
react-ui-storybook ⬜️ Ignored (Inspect) Visit Preview Dec 6, 2024 1:43pm
web-tools ⬜️ Ignored (Inspect) Visit Preview Dec 6, 2024 1:43pm

@live-github-bot live-github-bot bot added the desktop Has changes in LLD label Dec 4, 2024
@themooneer themooneer force-pushed the fix/LIVE-15007 branch 5 times, most recently from 36575be to 8ddefc1 Compare December 4, 2024 17:15
currentCard?.expiresAt?.getTime()
) {
// support new campaign or resumed campaign with the same id + different expiration date targeting anonymous users
setTimeout(() => {
Copy link
Member

Choose a reason for hiding this comment

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

Why do we need to use a timeout, please?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

so , this timeout is used to wait a little bit before a ui change to mark the content card read (as if it's an api request) , Lucas told me that before the work on this feature it was 3 seconds. It's a time laps to avoid immediate disappear of the dot. Initially i just put 500 ms (like in the video) so it's can disappear in a reasonable time. But i should confirm with Anthony.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

simply it will take 3 seconds so that the seen status will be considered for the offline notifications.

Copy link
Contributor

Choose a reason for hiding this comment

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

Actually it was 2 seconds my bad here is the code used before :

const { notificationsCards, logNotificationImpression, groupNotifications, onClickNotif } =
    useNotifications();

  const timeoutByUUID = useRef<Record<string, NodeJS.Timeout>>({});
  const handleInViewNotif = useCallback(
    (visible: boolean, uuid: keyof typeof timeoutByUUID.current) => {
      const timeouts = timeoutByUUID.current;

      if (notificationsCards.find(n => !n.viewed && n.id === uuid) && visible && !timeouts[uuid]) {
        timeouts[uuid] = setTimeout(() => {
          logNotificationImpression(uuid);
          delete timeouts[uuid];
        }, 2000);
      }
      if (!visible && timeouts[uuid]) {
        clearTimeout(timeouts[uuid]);
        delete timeouts[uuid];
      }
    },
    [logNotificationImpression, notificationsCards],
  );

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ok i'll change it ! so that we keep the same look & feel of a real api call , rather than suddenly/fast delete them

Copy link
Contributor Author

Choose a reason for hiding this comment

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

✅ Done

@themooneer themooneer marked this pull request as draft December 5, 2024 12:27
@themooneer themooneer force-pushed the fix/LIVE-15007 branch 2 times, most recently from 9d1a7eb to 91ee3dd Compare December 5, 2024 13:06
@themooneer themooneer marked this pull request as ready for review December 5, 2024 13:15
@themooneer themooneer requested a review from KVNLS December 5, 2024 13:15
@themooneer themooneer force-pushed the fix/LIVE-15007 branch 2 times, most recently from 98102af to 52f3b74 Compare December 6, 2024 05:00
@themooneer themooneer requested a review from LucasWerey December 6, 2024 05:04
@LucasWerey
Copy link
Contributor

LucasWerey commented Dec 6, 2024

I've tested it but now it seems like with analytics on the notif remains active even if the card has the field viewed sets to true

Screen.Recording.2024-12-06.at.10.30.58.mov

@themooneer themooneer force-pushed the fix/LIVE-15007 branch 2 times, most recently from 21b1ea0 to c1a9ed3 Compare December 6, 2024 10:33
Copy link
Contributor

@LucasWerey LucasWerey left a comment

Choose a reason for hiding this comment

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

LGTM

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
desktop Has changes in LLD
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants