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

Function useLogImpression

packages/shared/src/hooks/feed/useLogImpression.ts:41–208  ·  view source on GitHub ↗
({
  item,
  index,
  columns,
  column,
  row,
  feedName,
  ranking,
  highlightColSpan,
  origin,
  searchLogExtra,
  isExplaining = false,
}: UseLogImpressionProps)

Source from the content-addressed store, hash-verified

39}
40
41export default function useLogImpression({
42 item,
43 index,
44 columns,
45 column,
46 row,
47 feedName,
48 ranking,
49 highlightColSpan,
50 origin,
51 searchLogExtra,
52 isExplaining = false,
53}: UseLogImpressionProps): (node?: Element | null) => void {
54 const { logEventStart, logEventEnd } = useLogContext();
55 const postLogEvent = usePostLogEvent();
56 const { ref: inViewRef, inView } = useInView({
57 threshold: 0.5,
58 });
59
60 useEffect(() => {
61 if (item.type === 'post') {
62 // Debug covers the card with its explanation, so it is not an
63 // impression of the post.
64 const isCovered = isExplaining && item.post.explain !== undefined;
65 const isSeen = inView && !isCovered;
66 const eventKey = generatePostLogEventKey(item.post.id);
67 if (isSeen && !item.post.impressionStatus) {
68 const significance = item.post.hero?.significance;
69 logEventStart(
70 eventKey,
71 postLogEvent(LogEvent.Impression, item.post, {
72 columns,
73 column,
74 row,
75 index,
76 extra: {
77 ...feedLogExtra(
78 feedName,
79 ranking,
80 { scroll_y: window.scrollY, ...searchLogExtra },
81 origin,
82 ).extra,
83 clickbait_badge: isShareLikePost(item.post)
84 ? item.post.sharedPost?.clickbaitTitleDetected
85 : item.post.clickbaitTitleDetected,
86 feedback: item.post.type === PostType.Article ? true : undefined,
87 ...(!!significance && {
88 highlight_significance: significance,
89 ...(!!highlightColSpan && {
90 highlight_col_span: highlightColSpan,
91 }),
92 }),
93 },
94 }),
95 );
96 // eslint-disable-next-line no-param-reassign
97 item.post.impressionStatus = ImpressionStatus.LOGGING;
98 } else if (

Callers 1

FeedItemComponentFunction · 0.85

Calls 14

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

Tested by

no test coverage detected