@m13v/seo-components 0.32.2 → 0.34.0

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.32.2",
3
+ "version": "0.34.0",
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",
@@ -69,9 +69,22 @@ export interface InstallEmailGateProps {
69
69
  newsletterPath?: string;
70
70
  /** Render a custom trigger element instead of the default button. Receives an onClick handler. */
71
71
  renderTrigger?: (props: { onClick: () => void; disabled?: boolean }) => React.ReactNode;
72
+ /**
73
+ * Email-only delivery mode. When true, the command is NEVER revealed in the
74
+ * modal; instead, after a successful email submit the user sees a
75
+ * "Check your inbox" success state. The newsletter route is responsible for
76
+ * sending the install command via email. Forces a re-submit on every click
77
+ * (no localStorage skip) so each click drives a fresh send and a clean
78
+ * `newsletter_subscribed` + `get_started_click` signal.
79
+ */
80
+ emailOnly?: boolean;
81
+ /** Stage 2 (sent) heading when emailOnly is true. */
82
+ sentTitle?: string;
83
+ /** Stage 2 (sent) body copy when emailOnly is true. Receives the submitted email. */
84
+ sentDescription?: (email: string) => React.ReactNode;
72
85
  }
73
86
 
74
- type Stage = "closed" | "email" | "command";
87
+ type Stage = "closed" | "email" | "command" | "sent";
75
88
 
76
89
  export function InstallEmailGate({
77
90
  command,
@@ -92,10 +105,14 @@ export function InstallEmailGate({
92
105
  storageKey = DEFAULT_STORAGE_KEY,
93
106
  newsletterPath = "/api/newsletter",
94
107
  renderTrigger,
108
+ emailOnly = false,
109
+ sentTitle = "Check your inbox",
110
+ sentDescription,
95
111
  }: InstallEmailGateProps) {
96
112
  const capture = useCapture();
97
113
  const [stage, setStage] = useState<Stage>("closed");
98
114
  const [email, setEmail] = useState("");
115
+ const [submittedEmail, setSubmittedEmail] = useState("");
99
116
  const [submitting, setSubmitting] = useState(false);
100
117
  const [error, setError] = useState("");
101
118
  const [copied, setCopied] = useState<"command" | "config" | null>(null);
@@ -119,7 +136,10 @@ export function InstallEmailGate({
119
136
  }, [stage]);
120
137
 
121
138
  const onOpen = () => {
122
- const skip = remember && hasCapturedInstallEmail(storageKey);
139
+ // emailOnly mode: never skip via localStorage, never reveal the command.
140
+ // Every click goes through the email form so the user gets a fresh email
141
+ // and the funnel records a fresh signal.
142
+ const skip = !emailOnly && remember && hasCapturedInstallEmail(storageKey);
123
143
  if (skip) {
124
144
  // Gate already passed previously: fire the canonical funnel event for
125
145
  // the gated-passed click. No event when the gate is fresh and we're
@@ -168,20 +188,23 @@ export function InstallEmailGate({
168
188
  site,
169
189
  section,
170
190
  source: "install_gate",
191
+ delivery: emailOnly ? "email_only" : "page_reveal",
171
192
  });
172
193
  trackGetStartedClick({
173
- destination: "modal:command",
194
+ destination: emailOnly ? "email:install" : "modal:command",
174
195
  site,
175
196
  section,
176
197
  text: "email-submitted",
177
198
  component: "InstallEmailGate",
178
- extra: { email: trimmed },
199
+ extra: { email: trimmed, delivery: emailOnly ? "email_only" : "page_reveal" },
179
200
  });
180
- setStage("command");
201
+ setSubmittedEmail(trimmed);
202
+ setStage(emailOnly ? "sent" : "command");
181
203
  } catch (err) {
182
204
  console.warn("[InstallEmailGate] newsletter POST network error", err);
183
205
  if (remember) markInstallEmailCaptured(trimmed, storageKey);
184
- setStage("command");
206
+ setSubmittedEmail(trimmed);
207
+ setStage(emailOnly ? "sent" : "command");
185
208
  } finally {
186
209
  setSubmitting(false);
187
210
  }
@@ -291,11 +314,72 @@ export function InstallEmailGate({
291
314
  </button>
292
315
  </form>
293
316
  <p className="mt-4 text-xs text-zinc-500">
294
- Already subscribed? Submit anyway, the command unlocks either way.
317
+ {emailOnly
318
+ ? "Already subscribed? Submit anyway, we'll resend the install link."
319
+ : "Already subscribed? Submit anyway, the command unlocks either way."}
295
320
  </p>
296
321
  </div>
297
322
  )}
298
323
 
324
+ {stage === "sent" && (
325
+ <div className="p-7">
326
+ <div className="mb-5 flex items-start justify-between gap-4">
327
+ <div>
328
+ <div className="mb-3 inline-flex h-10 w-10 items-center justify-center rounded-full bg-teal-50 text-teal-600">
329
+ <svg
330
+ className="h-5 w-5"
331
+ fill="none"
332
+ viewBox="0 0 24 24"
333
+ stroke="currentColor"
334
+ strokeWidth={2}
335
+ aria-hidden="true"
336
+ >
337
+ <path strokeLinecap="round" strokeLinejoin="round" d="M3 8l7.5 5.25a3 3 0 003 0L21 8M5 19h14a2 2 0 002-2V7a2 2 0 00-2-2H5a2 2 0 00-2 2v10a2 2 0 002 2z" />
338
+ </svg>
339
+ </div>
340
+ <h2 className="text-xl font-semibold tracking-tight text-zinc-900">
341
+ {sentTitle}
342
+ </h2>
343
+ <p className="mt-1 text-sm leading-relaxed text-zinc-600">
344
+ {sentDescription
345
+ ? sentDescription(submittedEmail)
346
+ : (
347
+ <>
348
+ Sent the install command to{" "}
349
+ <span className="font-medium text-zinc-900">{submittedEmail}</span>.
350
+ It usually arrives in under a minute. If you don&apos;t see it, check
351
+ spam or promotions.
352
+ </>
353
+ )}
354
+ </p>
355
+ </div>
356
+ <CloseButton onClick={() => setStage("closed")} />
357
+ </div>
358
+
359
+ <div className="mt-5 flex items-center justify-between gap-3">
360
+ {githubUrl ? (
361
+ <a
362
+ href={githubUrl}
363
+ target="_blank"
364
+ rel="noopener noreferrer"
365
+ className="text-sm font-medium text-teal-700 hover:text-teal-800"
366
+ >
367
+ View on GitHub →
368
+ </a>
369
+ ) : (
370
+ <span />
371
+ )}
372
+ <button
373
+ type="button"
374
+ onClick={() => setStage("closed")}
375
+ className="rounded-md border border-zinc-300 bg-white px-4 py-2 text-sm font-medium text-zinc-900 hover:bg-zinc-50"
376
+ >
377
+ Done
378
+ </button>
379
+ </div>
380
+ </div>
381
+ )}
382
+
299
383
  {stage === "command" && (
300
384
  <div className="p-7">
301
385
  <div className="mb-5 flex items-start justify-between gap-4">
@@ -19,18 +19,27 @@ export interface DmShortLinkRedirectConfig {
19
19
  /**
20
20
  * Factory for `GET /r/[code]`.
21
21
  *
22
- * Each per-DM short link maps to a Cal.com / Calendly URL with full UTM and
23
- * `metadata[utm_*]` so cal_bookings closes the loop on which DM produced the
24
- * booking. The cached `target_url` is frozen at mint time on the dms row, so
25
- * the resolver is a single DB read with no config.json dependency.
22
+ * Each short link maps to a destination URL. Two rails are supported:
23
+ *
24
+ * DM rail: code is minted from dm_links. Target is a Cal.com / Calendly URL
25
+ * with full UTM and metadata[utm_*] so cal_bookings closes the loop on which
26
+ * DM produced the booking. Fires `dm_short_link_clicked` in PostHog.
27
+ *
28
+ * Post rail: code is minted from post_links (public posts/comments). Target
29
+ * is typically the product homepage or a landing page. UTM params are injected
30
+ * at redirect time (utm_source, utm_medium, utm_campaign, utm_content) so
31
+ * PostHog can stitch the full funnel: post click -> get_started_click ->
32
+ * schedule_click -> checkout_success. Fires `post_short_link_clicked` in
33
+ * PostHog.
26
34
  *
27
35
  * Behavior:
28
36
  * 1. Read `code` from the route param. Reject non-alphanumeric / wrong-length.
29
- * 2. Hit `<resolverBase>/api/short-links/<code>`. The resolver increments
30
- * dms.short_link_clicks and stamps first/last click timestamps.
31
- * 3. Fire a PostHog `dm_short_link_clicked` event with dm_id, project,
32
- * platform, code, site.
33
- * 4. 302 to the resolved target_url. On miss/error, 302 to "/".
37
+ * 2. Hit `<resolverBase>/api/short-links/<code>`. The resolver increments the
38
+ * click counter and stamps first/last click timestamps.
39
+ * 3. For post rail links: inject UTM params into the target URL.
40
+ * 4. Fire the appropriate PostHog event (dm_short_link_clicked or
41
+ * post_short_link_clicked) fire-and-forget, non-blocking.
42
+ * 5. 302 to the resolved target_url. On miss/error, 302 to "/".
34
43
  */
35
44
  export function createDmShortLinkRedirectHandler(config: DmShortLinkRedirectConfig) {
36
45
  const {
@@ -55,6 +64,8 @@ export function createDmShortLinkRedirectHandler(config: DmShortLinkRedirectConf
55
64
 
56
65
  let target: string | null = null;
57
66
  let dmId: number | null = null;
67
+ let postId: number | null = null;
68
+ let replyId: number | null = null;
58
69
  let project: string | null = null;
59
70
  let platform: string | null = null;
60
71
 
@@ -67,12 +78,16 @@ export function createDmShortLinkRedirectHandler(config: DmShortLinkRedirectConf
67
78
  const body = (await resp.json()) as {
68
79
  target_url?: string;
69
80
  dm_id?: number;
81
+ post_id?: number;
82
+ reply_id?: number;
70
83
  project?: string;
71
84
  platform?: string;
72
85
  };
73
86
  if (body.target_url) {
74
87
  target = body.target_url;
75
88
  dmId = body.dm_id ?? null;
89
+ postId = body.post_id ?? null;
90
+ replyId = body.reply_id ?? null;
76
91
  project = body.project ?? null;
77
92
  platform = body.platform ?? null;
78
93
  }
@@ -81,8 +96,29 @@ export function createDmShortLinkRedirectHandler(config: DmShortLinkRedirectConf
81
96
  console.error("[dm-short-link/redirect] resolver fetch failed:", err);
82
97
  }
83
98
 
99
+ // For post rail links (public posts/comments), inject UTM params so
100
+ // PostHog can stitch click -> conversion events. DM rail links already
101
+ // have Cal.com metadata[utm_*] attribution embedded at mint time, so we
102
+ // leave those URLs untouched.
103
+ if (target && (postId != null || replyId != null)) {
104
+ try {
105
+ const targetUrl = new URL(target);
106
+ if (!targetUrl.searchParams.has("utm_source")) {
107
+ if (platform) targetUrl.searchParams.set("utm_source", platform);
108
+ targetUrl.searchParams.set("utm_medium", "social");
109
+ if (project) targetUrl.searchParams.set("utm_campaign", project);
110
+ targetUrl.searchParams.set("utm_content", code);
111
+ target = targetUrl.toString();
112
+ }
113
+ } catch {
114
+ // Keep original target if URL parsing fails (e.g. non-HTTP scheme).
115
+ }
116
+ }
117
+
84
118
  const posthogKey = process.env[posthogKeyEnv];
85
119
  const posthogHost = (process.env[posthogHostEnv] || "https://us.i.posthog.com").replace(/\/+$/, "");
120
+
121
+ // DM rail event
86
122
  if (target && posthogKey && dmId != null) {
87
123
  fetch(`${posthogHost}/i/v0/e/`, {
88
124
  method: "POST",
@@ -99,6 +135,30 @@ export function createDmShortLinkRedirectHandler(config: DmShortLinkRedirectConf
99
135
  );
100
136
  }
101
137
 
138
+ // Post rail event
139
+ if (target && posthogKey && (postId != null || replyId != null)) {
140
+ fetch(`${posthogHost}/i/v0/e/`, {
141
+ method: "POST",
142
+ headers: { "Content-Type": "application/json" },
143
+ body: JSON.stringify({
144
+ api_key: posthogKey,
145
+ event: "post_short_link_clicked",
146
+ distinct_id: `post_${postId ?? replyId}`,
147
+ timestamp: new Date().toISOString(),
148
+ properties: {
149
+ post_id: postId,
150
+ reply_id: replyId,
151
+ project,
152
+ platform,
153
+ code,
154
+ site,
155
+ },
156
+ }),
157
+ }).catch((err) =>
158
+ console.error("[dm-short-link/redirect] posthog fetch failed:", err)
159
+ );
160
+ }
161
+
102
162
  return Response.redirect(target || homeUrl, 302);
103
163
  };
104
164
  }
@@ -124,6 +124,7 @@ export interface NewsletterConfig {
124
124
  onSignup?: (email: string, resendEmailId: string | null) => Promise<void>;
125
125
  }
126
126
 
127
+
127
128
  /* ------------------------------------------------------------------ */
128
129
  /* Factory */
129
130
  /* ------------------------------------------------------------------ */