@m13v/seo-components 0.41.1 → 0.41.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@m13v/seo-components",
3
- "version": "0.41.1",
3
+ "version": "0.41.3",
4
4
  "scripts": {
5
5
  "build:css": "tailwind -i src/_build.css -o dist/styles.css --minify",
6
6
  "lint:mobile-spans": "node scripts/lint-mobile-spans.mjs",
@@ -100,35 +100,53 @@ function nanoid(prefix: string, n = 16): string {
100
100
  return out;
101
101
  }
102
102
 
103
+ // localStorage can throw (quota exceeded, disabled in private mode, blocked by
104
+ // privacy settings). Never let storage access crash the host page: every read
105
+ // and write is wrapped so the chat panel degrades gracefully instead of taking
106
+ // down the entire site through its mount in the root layout.
107
+ function safeGet(key: string): string | null {
108
+ if (typeof window === "undefined") return null;
109
+ try {
110
+ return window.localStorage.getItem(key);
111
+ } catch {
112
+ return null;
113
+ }
114
+ }
115
+
116
+ function safeSet(key: string, value: string): void {
117
+ if (typeof window === "undefined") return;
118
+ try {
119
+ window.localStorage.setItem(key, value);
120
+ } catch {
121
+ /* quota exceeded / storage disabled — ignore */
122
+ }
123
+ }
124
+
103
125
  function getOrCreateVisitorId(): string {
104
126
  if (typeof window === "undefined") return "";
105
127
  const key = "fcp_visitor_id";
106
- let v = window.localStorage.getItem(key);
128
+ let v = safeGet(key);
107
129
  if (!v) {
108
130
  v = nanoid("web_", 16);
109
- window.localStorage.setItem(key, v);
131
+ safeSet(key, v);
110
132
  }
111
133
  return v;
112
134
  }
113
135
 
114
136
  function getStoredThreadId(project: string): string | null {
115
- if (typeof window === "undefined") return null;
116
- return window.localStorage.getItem(`fcp_thread_${project}`);
137
+ return safeGet(`fcp_thread_${project}`);
117
138
  }
118
139
 
119
140
  function setStoredThreadId(project: string, threadId: string): void {
120
- if (typeof window === "undefined") return;
121
- window.localStorage.setItem(`fcp_thread_${project}`, threadId);
141
+ safeSet(`fcp_thread_${project}`, threadId);
122
142
  }
123
143
 
124
144
  function getStoredEmail(): string | null {
125
- if (typeof window === "undefined") return null;
126
- return window.localStorage.getItem("fcp_email");
145
+ return safeGet("fcp_email");
127
146
  }
128
147
 
129
148
  function setStoredEmail(email: string): void {
130
- if (typeof window === "undefined") return;
131
- window.localStorage.setItem("fcp_email", email);
149
+ safeSet("fcp_email", email);
132
150
  }
133
151
 
134
152
  export function FounderChatPanel({
@@ -143,6 +143,13 @@ export function createDmShortLinkRedirectHandler(config: DmShortLinkRedirectConf
143
143
  let replyId: number | null = null;
144
144
  let project: string | null = null;
145
145
  let platform: string | null = null;
146
+ // Newsletter rail attribution: the resolver returns broadcast_id +
147
+ // broadcast_product + recipient_email_hash when the code resolves to
148
+ // newsletter_links. We fire `newsletter_short_link_clicked` so PostHog
149
+ // can stitch the click back to the originating broadcast + recipient.
150
+ let broadcastId: number | null = null;
151
+ let broadcastProduct: string | null = null;
152
+ let recipientEmailHash: string | null = null;
146
153
 
147
154
  try {
148
155
  const params = new URLSearchParams();
@@ -169,6 +176,9 @@ export function createDmShortLinkRedirectHandler(config: DmShortLinkRedirectConf
169
176
  reply_id?: number;
170
177
  project?: string;
171
178
  platform?: string;
179
+ broadcast_id?: number;
180
+ broadcast_product?: string;
181
+ recipient_email_hash?: string;
172
182
  };
173
183
  if (body.target_url) {
174
184
  target = body.target_url;
@@ -177,6 +187,9 @@ export function createDmShortLinkRedirectHandler(config: DmShortLinkRedirectConf
177
187
  replyId = body.reply_id ?? null;
178
188
  project = body.project ?? null;
179
189
  platform = body.platform ?? null;
190
+ broadcastId = body.broadcast_id ?? null;
191
+ broadcastProduct = body.broadcast_product ?? null;
192
+ recipientEmailHash = body.recipient_email_hash ?? null;
180
193
  }
181
194
  }
182
195
  } catch (err) {
@@ -248,6 +261,34 @@ export function createDmShortLinkRedirectHandler(config: DmShortLinkRedirectConf
248
261
  );
249
262
  }
250
263
 
264
+ // Newsletter rail event. distinct_id is the recipient_email_hash so
265
+ // every click from the same recipient stitches under one identity in
266
+ // PostHog. Properties carry broadcast_id + product so HogQL queries
267
+ // can attribute clicks (and downstream signup events on the same
268
+ // session) back to a specific broadcast x recipient pair.
269
+ if (!isBot && target && posthogKey && broadcastId != null) {
270
+ fetch(`${posthogHost}/i/v0/e/`, {
271
+ method: "POST",
272
+ headers: { "Content-Type": "application/json" },
273
+ body: JSON.stringify({
274
+ api_key: posthogKey,
275
+ event: "newsletter_short_link_clicked",
276
+ distinct_id: recipientEmailHash || `newsletter_${broadcastId}`,
277
+ timestamp: new Date().toISOString(),
278
+ properties: {
279
+ broadcast_id: broadcastId,
280
+ broadcast_product: broadcastProduct,
281
+ recipient_email_hash: recipientEmailHash,
282
+ project,
283
+ code,
284
+ site,
285
+ },
286
+ }),
287
+ }).catch((err) =>
288
+ console.error("[dm-short-link/redirect] posthog fetch failed:", err)
289
+ );
290
+ }
291
+
251
292
  return Response.redirect(target || homeUrl, 302);
252
293
  };
253
294
  }
@@ -15,7 +15,7 @@ import { discoverGuides } from "./discover-guides";
15
15
  import { logAiUsage } from "./ai-usage";
16
16
 
17
17
  const MODEL_ID = "gemini-flash-latest";
18
- const MAX_TOOL_ROUNDS = 3;
18
+ const MAX_TOOL_ROUNDS = 50;
19
19
  const RATE_LIMIT_MAX = 20;
20
20
  const RATE_LIMIT_WINDOW_MS = 60 * 60 * 1000;
21
21