( eventName: string, post: PostLogEventPost, opts?: PostLogEventFnOptions, )
| 136 | Partial<Pick<Post, 'slug'>>; |
| 137 | |
| 138 | export function postLogEvent( |
| 139 | eventName: string, |
| 140 | post: PostLogEventPost, |
| 141 | opts?: PostLogEventFnOptions, |
| 142 | ): PostItemLogEvent { |
| 143 | // Lives in `extra` rather than top-level: unmapped top-level event fields are |
| 144 | // dropped at analytics ingest, while the `extra` blob is stored intact. |
| 145 | const extra: Record<string, unknown> = { |
| 146 | ...opts?.extra, |
| 147 | ...(opts?.is_ad && { is_ad: true }), |
| 148 | ...(typeof opts?.index === 'number' && { feed_item_index: opts.index }), |
| 149 | }; |
| 150 | |
| 151 | if (typeof window !== 'undefined') { |
| 152 | const currentUrl = new URL(window.location.href); |
| 153 | |
| 154 | const feedPathMatch = currentUrl.pathname.match(feedPathWithIdMatcher); |
| 155 | |
| 156 | if (feedPathMatch?.groups?.feedId) { |
| 157 | extra.feed_id = feedPathMatch.groups.feedId; |
| 158 | } |
| 159 | } |
| 160 | |
| 161 | return { |
| 162 | event_name: eventName, |
| 163 | feed_grid_columns: opts?.columns, |
| 164 | feed_item_grid_column: opts?.column, |
| 165 | feed_item_grid_row: opts?.row, |
| 166 | feed_item_image: post.image, |
| 167 | feed_item_target_url: post.permalink, |
| 168 | feed_item_title: post.title, |
| 169 | feed_item_meta: post.feedMeta, |
| 170 | post_author_id: post.author?.id, |
| 171 | post_scout_id: post.scout?.id, |
| 172 | post_created_at: post.createdAt, |
| 173 | post_comments_count: post.numComments, |
| 174 | post_read_time: post.readTime, |
| 175 | post_tags: post.tags, |
| 176 | post_source_id: post.source?.id, |
| 177 | post_trending_value: post.trending, |
| 178 | post_upvotes_count: post.numUpvotes, |
| 179 | target_id: post.id, |
| 180 | target_type: 'post', |
| 181 | post_type: post.type, |
| 182 | post_source_type: post.source?.type, |
| 183 | extra: Object.keys(extra).length > 0 ? JSON.stringify(extra) : undefined, |
| 184 | }; |
| 185 | } |
| 186 | |
| 187 | export function adLogEvent( |
| 188 | eventName: string, |
no outgoing calls
no test coverage detected