-
Notifications
You must be signed in to change notification settings - Fork 333
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
📈(lld) optimize braze CC analytics (#8361)
- Loading branch information
1 parent
61f8b03
commit 34cf0f9
Showing
14 changed files
with
127 additions
and
144 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"ledger-live-desktop": patch | ||
--- | ||
|
||
Optimize content card log impression based on 50% of the card seen |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
66 changes: 66 additions & 0 deletions
66
apps/ledger-live-desktop/src/newArch/components/DynamicContent/LogContentCardWrapper.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
import React, { useRef, useEffect, useMemo } from "react"; | ||
import * as braze from "@braze/web-sdk"; | ||
import { useSelector } from "react-redux"; | ||
import { trackingEnabledSelector } from "~/renderer/reducers/settings"; | ||
import { track } from "~/renderer/analytics/segment"; | ||
import { Flex } from "@ledgerhq/react-ui"; | ||
|
||
interface LogContentCardWrapperProps { | ||
id: string; | ||
children: React.ReactNode; | ||
additionalProps?: object; | ||
} | ||
|
||
const PERCENTAGE_OF_CARD_VISIBLE = 0.5; | ||
|
||
const LogContentCardWrapper: React.FC<LogContentCardWrapperProps> = ({ | ||
id, | ||
children, | ||
additionalProps, | ||
}) => { | ||
const ref = useRef<HTMLDivElement>(null); | ||
const isTrackedUser = useSelector(trackingEnabledSelector); | ||
|
||
const currentCard = useMemo(() => { | ||
const cards = braze.getCachedContentCards().cards; | ||
return cards.find(card => card.id === id); | ||
}, [id]); | ||
|
||
useEffect(() => { | ||
if (!currentCard || !isTrackedUser) return; | ||
|
||
const intersectionObserver = new IntersectionObserver( | ||
([entry]) => { | ||
if (entry.intersectionRatio > PERCENTAGE_OF_CARD_VISIBLE) { | ||
braze.logContentCardImpressions([currentCard]); | ||
track("contentcard_impression", { | ||
id: currentCard.id, | ||
...currentCard.extras, | ||
...additionalProps, | ||
}); | ||
} | ||
}, | ||
{ threshold: PERCENTAGE_OF_CARD_VISIBLE }, | ||
); | ||
|
||
const currentRef = ref.current; | ||
|
||
if (currentRef) { | ||
intersectionObserver.observe(currentRef); | ||
} | ||
|
||
return () => { | ||
if (currentRef) { | ||
intersectionObserver.unobserve(currentRef); | ||
} | ||
}; | ||
}, [currentCard, isTrackedUser, additionalProps]); | ||
|
||
return ( | ||
<Flex width="100%" ref={ref}> | ||
{children} | ||
</Flex> | ||
); | ||
}; | ||
|
||
export default LogContentCardWrapper; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.