forked from CopilotKit/CopilotKit
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsignup-link.tsx
More file actions
46 lines (39 loc) · 1.21 KB
/
Copy pathsignup-link.tsx
File metadata and controls
46 lines (39 loc) · 1.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
"use client";
import posthog from "posthog-js";
import { useCallback } from "react";
const DEFAULT_SIGNUP_URL = "https://dashboard.operations.copilotkit.ai/";
const SIGNUP_URL =
process.env.NEXT_PUBLIC_INTELLIGENCE_SIGNUP_URL || DEFAULT_SIGNUP_URL;
export interface SignupLinkProps {
/** Stable identifier for analytics, e.g. "docs_langgraph_quickstart_step1" */
surface: string;
children: React.ReactNode;
}
function buildHref(surface: string): string {
const url = new URL(SIGNUP_URL);
url.searchParams.set("utm_source", "docs");
url.searchParams.set("utm_medium", "cta");
url.searchParams.set("utm_campaign", "intelligence");
url.searchParams.set("utm_content", surface);
return url.toString();
}
export function SignupLink({ surface, children }: SignupLinkProps) {
const handleClick = useCallback(() => {
try {
posthog.capture("try_for_free_clicked", { location: surface });
} catch {
// PostHog may be blocked by ad blockers — never let analytics block navigation.
}
}, [surface]);
return (
<a
href={buildHref(surface)}
target="_blank"
rel="noreferrer"
onClick={handleClick}
data-cta-surface={surface}
>
{children}
</a>
);
}