( item: FeedItem, index: number, columns: number, column: number, row: number, feedName: string, ranking?: string, highlightColSpan?: number, origin?: Origin, )
| 23 | export const generateHighlightLogEventKey = (id: string): string => `hi-${id}`; |
| 24 | |
| 25 | export 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 | } |
no test coverage detected