File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ import { withUtm } from "@/lib/utm" ;
2+
13export const APP_NAME = "NEAR AI Private Chat" ;
24// TODO: remove DEPRECATED_API_BASE_URL from the project as there's no dependency on the legacy Private Chat any more
35export const DEPRECATED_API_BASE_URL = ( import . meta. env . VITE_DEPRECATED_API_URL || "https://private-chat-legacy.near.ai" ) . replace (
@@ -40,5 +42,6 @@ export const NEAR_RPC_URL = import.meta.env.VITE_NEAR_RPC_URL || "https://free.r
4042export const NEAR_AI_CLOUD_MODELS_URL = "https://cloud.near.ai/models" ;
4143
4244export const AGENT_HOST = "agent.near.ai" ;
43- export const AGENT_URL = `https://${ AGENT_HOST } ` ;
44- export const AGENT_BILLING_URL = `https://${ AGENT_HOST } /billing` ;
45+
46+ export const AGENT_URL = withUtm ( `https://${ AGENT_HOST } ` ) ;
47+ export const AGENT_BILLING_URL = withUtm ( `https://${ AGENT_HOST } /billing` ) ;
Original file line number Diff line number Diff line change 1+ import { withUtm } from "@/lib/utm" ;
2+
13export const LOCAL_STORAGE_KEYS = {
24 TOKEN : "sessionToken" ,
35 SESSION : "sessionId" ,
@@ -58,4 +60,4 @@ export const SUPPORTED_TEXT_EXTENSIONS = [
5860export const ACCEPTED_FILE_TYPES = SUPPORTED_TEXT_EXTENSIONS . join ( "," ) ;
5961// export const ACCEPTED_FILE_TYPES = [".pdf", ...SUPPORTED_TEXT_EXTENSIONS].join(",");
6062
61- export const IRONCLAW_URL = "https://www.ironclaw.com" ;
63+ export const IRONCLAW_URL = withUtm ( "https://www.ironclaw.com/" ) ;
Original file line number Diff line number Diff line change 1+ export const UTM_SOURCE = "private_chat" ;
2+ export const UTM_MEDIUM = "web" ;
3+
4+ /**
5+ * Adds default UTM parameters to a URL string.
6+ *
7+ * - Sets `utm_source` and `utm_medium` only when the corresponding query
8+ * parameters are missing (e.g. `?utm_source=` is considered "present" and
9+ * will not be overwritten).
10+ * - If the value cannot be parsed as a URL, the original `url` string is
11+ * returned unchanged.
12+ *
13+ * @param url - A URL (absolute or relative) to augment.
14+ * @param base - Optional base used to resolve `url` when it's relative.
15+ * @returns The augmented URL as a string, or the original input on parse failure.
16+ */
17+ export function withUtm ( url : string , base ?: string ) {
18+ let u : URL ;
19+ try {
20+ u = base ? new URL ( url , base ) : new URL ( url ) ;
21+ } catch ( error ) {
22+ console . error (
23+ `[withUtm] Failed to construct URL from value: "${ url } ". Returning original string.` ,
24+ error
25+ ) ;
26+ return url ;
27+ }
28+ if ( ! u . searchParams . has ( "utm_source" ) ) u . searchParams . set ( "utm_source" , UTM_SOURCE ) ;
29+ if ( ! u . searchParams . has ( "utm_medium" ) ) u . searchParams . set ( "utm_medium" , UTM_MEDIUM ) ;
30+ return u . toString ( ) ;
31+ }
You can’t perform that action at this time.
0 commit comments