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

Function postLogEvent

packages/shared/src/lib/feed.ts:109–156  ·  view source on GitHub ↗
(
  eventName: string,
  post: Post | ReadHistoryPost | PostBootData,
  opts?: PostLogEventFnOptions,
)

Source from the content-addressed store, hash-verified

107const feedPathWithIdMatcher = /^\/feeds\/(?<feedId>[A-z0-9]{9})\/?$/;
108
109export function postLogEvent(
110 eventName: string,
111 post: Post | ReadHistoryPost | PostBootData,
112 opts?: PostLogEventFnOptions,
113): PostItemLogEvent {
114 // Lives in `extra` rather than top-level: unmapped top-level event fields are
115 // dropped at analytics ingest, while the `extra` blob is stored intact.
116 const extra: Record<string, unknown> = {
117 ...opts?.extra,
118 ...(opts?.is_ad && { is_ad: true }),
119 ...(typeof opts?.index === 'number' && { feed_item_index: opts.index }),
120 };
121
122 if (typeof window !== 'undefined') {
123 const currentUrl = new URL(window.location.href);
124
125 const feedPathMatch = currentUrl.pathname.match(feedPathWithIdMatcher);
126
127 if (feedPathMatch?.groups?.feedId) {
128 extra.feed_id = feedPathMatch.groups.feedId;
129 }
130 }
131
132 return {
133 event_name: eventName,
134 feed_grid_columns: opts?.columns,
135 feed_item_grid_column: opts?.column,
136 feed_item_grid_row: opts?.row,
137 feed_item_image: post.image,
138 feed_item_target_url: post.permalink,
139 feed_item_title: post.title,
140 feed_item_meta: (post as Post).feedMeta,
141 post_author_id: post.author?.id,
142 post_scout_id: post.scout?.id,
143 post_created_at: post.createdAt,
144 post_comments_count: post.numComments,
145 post_read_time: post.readTime,
146 post_tags: post.tags,
147 post_source_id: post.source?.id,
148 post_trending_value: post.trending,
149 post_upvotes_count: post.numUpvotes,
150 target_id: post.id,
151 target_type: 'post',
152 post_type: post.type,
153 post_source_type: post.source?.type,
154 extra: Object.keys(extra).length > 0 ? JSON.stringify(extra) : undefined,
155 };
156}
157
158export function adLogEvent(
159 eventName: string,

Callers 15

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

Calls

no outgoing calls

Tested by

no test coverage detected