MCPcopy Create free account
hub / github.com/dailydotdev/apps / useLogImpression

Function useLogImpression

packages/shared/src/hooks/feed/useLogImpression.ts:25–185  ·  view source on GitHub ↗
(
  item: FeedItem,
  index: number,
  columns: number,
  column: number,
  row: number,
  feedName: string,
  ranking?: string,
  highlightColSpan?: number,
  origin?: Origin,
)

Source from the content-addressed store, hash-verified

23export const generateHighlightLogEventKey = (id: string): string => `hi-${id}`;
24
25export default function useLogImpression(
26 item: FeedItem,
27 index: number,
28 columns: number,
29 column: number,
30 row: number,
31 feedName: string,
32 ranking?: string,
33 highlightColSpan?: number,
34 origin?: Origin,
35): (node?: Element | null) => void {
36 const { logEventStart, logEventEnd } = useLogContext();
37 const postLogEvent = usePostLogEvent();
38 const { ref: inViewRef, inView } = useInView({
39 threshold: 0.5,
40 });
41
42 useEffect(() => {
43 if (item.type === 'post') {
44 const eventKey = generatePostLogEventKey(item.post.id);
45 if (inView && !item.post.impressionStatus) {
46 const significance = item.post.hero?.significance;
47 logEventStart(
48 eventKey,
49 postLogEvent(LogEvent.Impression, item.post, {
50 columns,
51 column,
52 row,
53 extra: {
54 ...feedLogExtra(
55 feedName,
56 ranking,
57 { scroll_y: window.scrollY },
58 origin,
59 ).extra,
60 clickbait_badge: isShareLikePost(item.post)
61 ? item.post.sharedPost?.clickbaitTitleDetected
62 : item.post.clickbaitTitleDetected,
63 feedback: item.post.type === PostType.Article ? true : undefined,
64 ...(!!significance && {
65 highlight_significance: significance,
66 ...(!!highlightColSpan && {
67 highlight_col_span: highlightColSpan,
68 }),
69 }),
70 },
71 }),
72 );
73 // eslint-disable-next-line no-param-reassign
74 item.post.impressionStatus = ImpressionStatus.LOGGING;
75 } else if (
76 !inView &&
77 item.post.impressionStatus === ImpressionStatus.LOGGING
78 ) {
79 logEventEnd(eventKey);
80 // eslint-disable-next-line no-param-reassign
81 item.post.impressionStatus = ImpressionStatus.LOGGED;
82 }

Callers 5

FeedItemComponentFunction · 0.85
HeadlineRowFunction · 0.85
BriefHeadlineRowFunction · 0.85
AdRowFunction · 0.85
PickRowFunction · 0.85

Calls 15

useLogContextFunction · 0.90
usePostLogEventFunction · 0.90
feedLogExtraFunction · 0.90
isShareLikePostFunction · 0.90
adLogEventFunction · 0.90
getHighlightIdsKeyFunction · 0.90
getHighlightIdsFunction · 0.90
feedHighlightsLogEventFunction · 0.90
useInViewFunction · 0.85
generatePostLogEventKeyFunction · 0.85
logEventStartFunction · 0.85
postLogEventFunction · 0.85

Tested by

no test coverage detected