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(llm): 🗒️ log content card impression when 50% of the card is shown #8526

Merged
merged 17 commits into from
Dec 3, 2024

Conversation

thesan
Copy link
Contributor

@thesan thesan commented Nov 28, 2024

✅ Checklist

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

📝 Description

Depending on the type of content card, use a mix of:

  • React Native: FlatList.onViewableItemsChanged
  • and a custom hook (which compare the element position to the screen position).

Demo:

  1. Analytics log:
Screen.Recording.2024-11-29.at.18.02.02.mov
  1. Make things clearer with a console log and the category id and the cards id sliced from the 6 to the 12 char:
Screen.Recording.2024-11-29.at.17.55.46.mov

❓ Context


🧐 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)

Copy link

vercel bot commented Nov 28, 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 3, 2024 9:56am
native-ui-storybook ⬜️ Ignored (Inspect) Visit Preview Dec 3, 2024 9:56am
react-ui-storybook ⬜️ Ignored (Inspect) Visit Preview Dec 3, 2024 9:56am
web-tools ⬜️ Ignored (Inspect) Visit Preview Dec 3, 2024 9:56am

@live-github-bot live-github-bot bot added the mobile Has changes in LLM label Nov 28, 2024
@thesan thesan force-pushed the feat/llm-enhanced-ccard-impression-tracking branch 2 times, most recently from 33c644d to 1747c22 Compare November 29, 2024 08:20
@thesan thesan marked this pull request as ready for review November 29, 2024 08:58
@thesan thesan requested a review from a team as a code owner November 29, 2024 08:58
const { logImpressionCard } = useDynamicContent();

useInViewContext(ref, ({ isInView }) => {
if (isInView) logImpressionCard(id);
Copy link
Contributor

Choose a reason for hiding this comment

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

We may also need to add normal analytics too here

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!

import { Linking } from "react-native";
import useDynamicContent from "~/dynamicContent/useDynamicContent";
import LogContentCardWrapper from "~/newArch/features/DynamicContent/components/LogContentCardWrapper";
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
import LogContentCardWrapper from "~/newArch/features/DynamicContent/components/LogContentCardWrapper";
import LogContentCardWrapper from "LLM/features/DynamicContent/components/LogContentCardWrapper";

@thesan thesan requested a review from LucasWerey November 29, 2024 17:07
@thesan thesan force-pushed the feat/llm-enhanced-ccard-impression-tracking branch from 1747c22 to 8761dc7 Compare November 29, 2024 17:08
@thesan
Copy link
Contributor Author

thesan commented Dec 2, 2024

Demos for the other content cards

with console.log("[test-impression] logImpressionCard", cardId.slice(6, 12), card?.extras.title) added in logImpressionCard for clarity:

Notifications cards:

Screen.Recording.2024-12-02.at.12.37.31.mov

Wallet cards:

(Nb: When the 3rd card is swipped back the 2de card impression is not retriggered because it did not completely left the screen. However when this card is swipped back the 1st card impression is retriggered)

Screen.Recording.2024-12-02.at.10.36.53.mov

Asset cards:

Screen.Recording.2024-12-02.at.11.20.26.mov

Carousel category cards:

Screen.Recording.2024-12-02.at.14.15.53.mov

Uique category cards:

Screen.Recording.2024-12-02.at.14.17.11.mov

@thesan thesan force-pushed the feat/llm-enhanced-ccard-impression-tracking branch from 8761dc7 to 45f1354 Compare December 2, 2024 13:21
deps: DependencyList = [],
) {
const { addWatchedItem, removeWatchedItem } = useContext(InViewContext);
const onInViewUpdateCb = useCallback(onInViewUpdate, deps); // eslint-disable-line react-hooks/exhaustive-deps
Copy link
Contributor

Choose a reason for hiding this comment

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

is the bypass really necessary ? We should avoid that

Copy link
Contributor Author

@thesan thesan Dec 2, 2024

Choose a reason for hiding this comment

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

I might be missing another posibility but here's how I see it:

The way I see not to bypass the react-hooks/exhaustive-deps would be to go:
From version 1

// Declaration
function useInViewContext(
  target: RefObject<View>,
  onInViewUpdate: (entry: InViewEntry) => void,
  deps: DependencyList = [],
)
...
// Usage
useInViewContext(target, ({ isInView }) => {
  if (isInView) logImpressionCard(id);
}, [id]);

To version 2

// Declaration
function useInViewContext(
  target: RefObject<View>,
  onInViewUpdate: (entry: InViewEntry) => void
)
...
// Usage
useInViewContext(target, useCallback(({ isInView }) => {
  if (isInView) logImpressionCard(id);
}, [id]));

The problem I have with version 2 is that the type signature doesn't make it clear onInViewUpdate is a dependency which means writing this would be problematic:

useInViewContext(target, ({ isInView }) => {
  if (isInView) logImpressionCard(id);
});

(because the internal useEffect will rerender on every re-render).

In react we are used to pass functions to hooks directly (without wrapping them in useCallback). So I think that here forwarding the dependencies to the hook is better to avoid mistakes. However it means that the variable used to forward the dependencies can't be statically analized by react-hooks/exhaustive-deps which makes the bypass necessary.

That said I could add useInViewContext to the config rules."react-hooks/exhaustive-deps".additionalHooks. So I'll have to add logImpressionCard to all the deps.

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: d444580

@thesan thesan force-pushed the feat/llm-enhanced-ccard-impression-tracking branch from 45f1354 to d444580 Compare December 3, 2024 08:49
/>
<LogContentCardWrapper key={cardProps.id + index} id={cardProps.id}>
<CarouselCard
key={cardProps.id + index}
Copy link
Contributor

Choose a reason for hiding this comment

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

I think you can remove this key as it's already used on the parent

@thesan thesan force-pushed the feat/llm-enhanced-ccard-impression-tracking branch from d444580 to 7378513 Compare December 3, 2024 09:55
@thesan thesan merged commit fc50509 into develop Dec 3, 2024
41 checks passed
@thesan thesan deleted the feat/llm-enhanced-ccard-impression-tracking branch December 3, 2024 11:01
thesan added a commit that referenced this pull request Dec 3, 2024
…wn (#8526)

* feat(llm): log category cards impression when 50% of the card is visible

* feat(llm): do not run in view checks when no items is being watched

* feat(llm): log portfolio content cards impression on 50% visibility

* chore: update change log

* feat(llm): log dynamic content card impression when 50% is shown

* feat(llm): log notification impression when 50% is shown

* chore(llm): rename IsInViewContext to InViewContext

* chore(llm): add InViewContextProvider to the AppProviders

* fix(llm): undefined order in null

* feat(lld): log category impression when 50% is shown

* chore(llm): use LLM alias in imports

* feat(llm): trigger segment event on card impression

* fix(llm): rewatch card when `LogContentCardWrapper.id` change

* fix(llm): use mobileCardsSelector to find the card to log the impression

* fix(llm): race condition between interval and inViewStatus

* chore(llm): check "exhaustive-deps" on `useInViewContext`

* chore(llm): remove unnecessary key
thesan added a commit that referenced this pull request Dec 3, 2024
…wn (#8526)

* feat(llm): log category cards impression when 50% of the card is visible

* feat(llm): do not run in view checks when no items is being watched

* feat(llm): log portfolio content cards impression on 50% visibility

* chore: update change log

* feat(llm): log dynamic content card impression when 50% is shown

* feat(llm): log notification impression when 50% is shown

* chore(llm): rename IsInViewContext to InViewContext

* chore(llm): add InViewContextProvider to the AppProviders

* fix(llm): undefined order in null

* feat(lld): log category impression when 50% is shown

* chore(llm): use LLM alias in imports

* feat(llm): trigger segment event on card impression

* fix(llm): rewatch card when `LogContentCardWrapper.id` change

* fix(llm): use mobileCardsSelector to find the card to log the impression

* fix(llm): race condition between interval and inViewStatus

* chore(llm): check "exhaustive-deps" on `useInViewContext`

* chore(llm): remove unnecessary key
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
mobile Has changes in LLM
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants