({
item,
index,
columns,
column,
row,
feedName,
ranking,
highlightColSpan,
origin,
searchLogExtra,
isExplaining = false,
}: UseLogImpressionProps)
| 39 | } |
| 40 | |
| 41 | export 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 ( |
no test coverage detected