( eventName: string, post: Post | ReadHistoryPost | PostBootData, opts?: PostLogEventFnOptions, )
| 102 | const feedPathWithIdMatcher = /^\/feeds\/(?<feedId>[A-z0-9]{9})\/?$/; |
| 103 | |
| 104 | export function postLogEvent( |
| 105 | eventName: string, |
| 106 | post: Post | ReadHistoryPost | PostBootData, |
| 107 | opts?: PostLogEventFnOptions, |
| 108 | ): PostItemLogEvent { |
| 109 | const extra: Record<string, unknown> = { |
| 110 | ...opts?.extra, |
| 111 | ...(opts?.is_ad && { is_ad: true }), |
| 112 | }; |
| 113 | |
| 114 | if (typeof window !== 'undefined') { |
| 115 | const currentUrl = new URL(window.location.href); |
| 116 | |
| 117 | const feedPathMatch = currentUrl.pathname.match(feedPathWithIdMatcher); |
| 118 | |
| 119 | if (feedPathMatch?.groups?.feedId) { |
| 120 | extra.feed_id = feedPathMatch.groups.feedId; |
| 121 | } |
| 122 | } |
| 123 | |
| 124 | return { |
| 125 | event_name: eventName, |
| 126 | feed_grid_columns: opts?.columns, |
| 127 | feed_item_grid_column: opts?.column, |
| 128 | feed_item_grid_row: opts?.row, |
| 129 | feed_item_image: post.image, |
| 130 | feed_item_target_url: post.permalink, |
| 131 | feed_item_title: post.title, |
| 132 | feed_item_meta: (post as Post).feedMeta, |
| 133 | post_author_id: post.author?.id, |
| 134 | post_scout_id: post.scout?.id, |
| 135 | post_created_at: post.createdAt, |
| 136 | post_comments_count: post.numComments, |
| 137 | post_read_time: post.readTime, |
| 138 | post_tags: post.tags, |
| 139 | post_source_id: post.source?.id, |
| 140 | post_trending_value: post.trending, |
| 141 | post_upvotes_count: post.numUpvotes, |
| 142 | target_id: post.id, |
| 143 | target_type: 'post', |
| 144 | post_type: post.type, |
| 145 | post_source_type: post.source?.type, |
| 146 | extra: Object.keys(extra).length > 0 ? JSON.stringify(extra) : undefined, |
| 147 | }; |
| 148 | } |
| 149 | |
| 150 | export function adLogEvent( |
| 151 | eventName: string, |
no outgoing calls
no test coverage detected