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