MCPcopy Create free account
hub / github.com/dailydotdev/apps / postLogEvent

Function postLogEvent

packages/shared/src/lib/feed.ts:138–185  ·  view source on GitHub ↗
(
  eventName: string,
  post: PostLogEventPost,
  opts?: PostLogEventFnOptions,
)

Source from the content-addressed store, hash-verified

136 Partial<Pick<Post, 'slug'>>;
137
138export 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
187export function adLogEvent(
188 eventName: string,

Callers 15

onShareFunction · 0.90
logShareEventFunction · 0.90
onShareToSquadFunction · 0.90
onCommentClickFunction · 0.90
FeedItemComponentFunction · 0.90
baseLogEventFunction · 0.90
onShareFunction · 0.90
onReportCommentFunction · 0.90
onReportPostFunction · 0.90
useBookmarkActionsFunction · 0.90
SocialIconButtonFunction · 0.90
onLinkClickFunction · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected