@m13v/seo-components 0.26.0 → 0.28.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 +1 -5
- package/src/lib/book-call-redirect.ts +16 -17
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@m13v/seo-components",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.28.0",
|
|
4
4
|
"scripts": {
|
|
5
5
|
"build:css": "tailwind -i src/_build.css -o dist/styles.css --minify",
|
|
6
6
|
"bump:consumers": "bash scripts/bump-consumers.sh",
|
|
@@ -58,7 +58,6 @@
|
|
|
58
58
|
"lottie-react": ">=2",
|
|
59
59
|
"next": ">=14",
|
|
60
60
|
"posthog-js": ">=1.100",
|
|
61
|
-
"posthog-node": ">=4",
|
|
62
61
|
"react": ">=18",
|
|
63
62
|
"react-dom": ">=18",
|
|
64
63
|
"remotion": ">=4"
|
|
@@ -84,9 +83,6 @@
|
|
|
84
83
|
},
|
|
85
84
|
"posthog-js": {
|
|
86
85
|
"optional": true
|
|
87
|
-
},
|
|
88
|
-
"posthog-node": {
|
|
89
|
-
"optional": true
|
|
90
86
|
}
|
|
91
87
|
},
|
|
92
88
|
"devDependencies": {
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { NextRequest } from "next/server";
|
|
2
|
-
import { PostHog } from "posthog-node";
|
|
3
2
|
|
|
4
3
|
export interface BookCallRedirectConfig {
|
|
5
4
|
/** Site slug. Must match the value the POST handler encoded into the link. */
|
|
@@ -18,7 +17,8 @@ export interface BookCallRedirectConfig {
|
|
|
18
17
|
* The handler:
|
|
19
18
|
* 1. Reads `email` and `site` from the query string (unsigned — the blast
|
|
20
19
|
* radius of forgery is a noisy PostHog event).
|
|
21
|
-
* 2. Fires a
|
|
20
|
+
* 2. Fires a `book_call_email_link_clicked` event to PostHog via the
|
|
21
|
+
* public `/i/v0/e/` HTTP endpoint (no posthog-node dependency), with
|
|
22
22
|
* `distinct_id = email`. Unique-user dedup is handled by PostHog.
|
|
23
23
|
* 3. 302s to Cal.com / Calendly with `?email=` pre-filled and
|
|
24
24
|
* `utm_medium=email_booking_link` so the funnel column separates
|
|
@@ -41,30 +41,29 @@ export function createBookCallRedirectHandler(config: BookCallRedirectConfig) {
|
|
|
41
41
|
const validEmail = !!email && email.includes("@") && email.length <= 254;
|
|
42
42
|
const siteMatches = querySite === site;
|
|
43
43
|
|
|
44
|
-
// If the query is malformed or targeted at a different site, drop to the
|
|
45
|
-
// bare booking URL so the user still reaches Cal/Calendly.
|
|
46
44
|
if (validEmail && siteMatches) {
|
|
47
45
|
const posthogKey = process.env[posthogKeyEnv];
|
|
46
|
+
const posthogHost = process.env[posthogHostEnv] || "https://us.i.posthog.com";
|
|
48
47
|
if (posthogKey) {
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
distinctId: email,
|
|
48
|
+
// Fire via PostHog's public HTTP capture endpoint. Fire-and-forget
|
|
49
|
+
// with .catch so a PostHog hiccup never delays the 302.
|
|
50
|
+
fetch(`${posthogHost.replace(/\/+$/, "")}/i/v0/e/`, {
|
|
51
|
+
method: "POST",
|
|
52
|
+
headers: { "Content-Type": "application/json" },
|
|
53
|
+
body: JSON.stringify({
|
|
54
|
+
api_key: posthogKey,
|
|
57
55
|
event: "book_call_email_link_clicked",
|
|
56
|
+
distinct_id: email,
|
|
57
|
+
timestamp: new Date().toISOString(),
|
|
58
58
|
properties: {
|
|
59
59
|
site,
|
|
60
60
|
email,
|
|
61
61
|
$set: { email },
|
|
62
62
|
},
|
|
63
|
-
})
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
}
|
|
63
|
+
}),
|
|
64
|
+
}).catch((err) => {
|
|
65
|
+
console.error("[book-call/redirect] posthog fetch failed:", err);
|
|
66
|
+
});
|
|
68
67
|
}
|
|
69
68
|
}
|
|
70
69
|
|