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

Function useLogImpression

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

Source from the content-addressed store, hash-verified

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

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