瀏覽代碼

feat: migrate PostHog client to ph.roocode.com (#9402)

Co-authored-by: Roo Code <[email protected]>
Co-authored-by: Matt Rubens <[email protected]>
roomote[bot] 1 月之前
父節點
當前提交
ee19904b29

+ 0 - 1
apps/web-roo-code/.env.example

@@ -1,7 +1,6 @@
 # PostHog Analytics Configuration
 # Replace these values with your actual PostHog API key and host
 NEXT_PUBLIC_POSTHOG_KEY=your_posthog_api_key_here
-NEXT_PUBLIC_POSTHOG_HOST=https://us.i.posthog.com
 
 # Basin Form Endpoint for Static Form Submissions
 # Replace this with your actual Basin form endpoint (e.g., https://usebasin.com/f/your-form-id)

+ 2 - 9
apps/web-roo-code/src/components/providers/posthog-provider.tsx

@@ -32,7 +32,6 @@ export function PostHogProvider({ children }: { children: React.ReactNode }) {
 		// Initialize PostHog immediately on the client side
 		if (typeof window !== "undefined" && !posthog.__loaded) {
 			const posthogKey = process.env.NEXT_PUBLIC_POSTHOG_KEY
-			const posthogHost = process.env.NEXT_PUBLIC_POSTHOG_HOST
 
 			// Check if environment variables are set
 			if (!posthogKey) {
@@ -43,19 +42,13 @@ export function PostHogProvider({ children }: { children: React.ReactNode }) {
 				return
 			}
 
-			if (!posthogHost) {
-				console.warn(
-					"PostHog host URL is missing. Using default host. " +
-						"Please set NEXT_PUBLIC_POSTHOG_HOST in your .env file.",
-				)
-			}
-
 			// Check if user has already consented to cookies
 			const userHasConsented = hasConsent()
 
 			// Initialize PostHog with appropriate persistence based on consent
 			posthog.init(posthogKey, {
-				api_host: posthogHost || "https://us.i.posthog.com",
+				api_host: "https://ph.roocode.com",
+				ui_host: "https://us.posthog.com",
 				capture_pageview: false, // We handle pageview tracking manually
 				loaded: (posthogInstance) => {
 					if (process.env.NODE_ENV === "development") {

+ 1 - 1
packages/telemetry/src/PostHogTelemetryClient.ts

@@ -25,7 +25,7 @@ export class PostHogTelemetryClient extends BaseTelemetryClient {
 			debug,
 		)
 
-		this.client = new PostHog(process.env.POSTHOG_API_KEY || "", { host: "https://us.i.posthog.com" })
+		this.client = new PostHog(process.env.POSTHOG_API_KEY || "", { host: "https://ph.roocode.com" })
 	}
 
 	/**

+ 1 - 1
src/core/webview/ClineProvider.ts

@@ -1196,7 +1196,7 @@ export class ClineProvider
             <meta charset="utf-8">
             <meta name="viewport" content="width=device-width,initial-scale=1,shrink-to-fit=no">
             <meta name="theme-color" content="#000000">
-            <meta http-equiv="Content-Security-Policy" content="default-src 'none'; font-src ${webview.cspSource} data:; style-src ${webview.cspSource} 'unsafe-inline'; img-src ${webview.cspSource} https://storage.googleapis.com https://img.clerk.com data:; media-src ${webview.cspSource}; script-src ${webview.cspSource} 'wasm-unsafe-eval' 'nonce-${nonce}' https://us-assets.i.posthog.com 'strict-dynamic'; connect-src ${webview.cspSource} ${openRouterDomain} https://api.requesty.ai https://us.i.posthog.com https://us-assets.i.posthog.com;">
+            <meta http-equiv="Content-Security-Policy" content="default-src 'none'; font-src ${webview.cspSource} data:; style-src ${webview.cspSource} 'unsafe-inline'; img-src ${webview.cspSource} https://storage.googleapis.com https://img.clerk.com data:; media-src ${webview.cspSource}; script-src ${webview.cspSource} 'wasm-unsafe-eval' 'nonce-${nonce}' https://ph.roocode.com 'strict-dynamic'; connect-src ${webview.cspSource} ${openRouterDomain} https://api.requesty.ai https://ph.roocode.com;">
             <link rel="stylesheet" type="text/css" href="${stylesUri}">
 			<link href="${codiconsUri}" rel="stylesheet" />
 			<script nonce="${nonce}">

+ 1 - 1
src/core/webview/__tests__/ClineProvider.spec.ts

@@ -486,7 +486,7 @@ describe("ClineProvider", () => {
 
 		// Verify Content Security Policy contains the necessary PostHog domains
 		expect(mockWebviewView.webview.html).toContain(
-			"connect-src vscode-webview://test-csp-source https://openrouter.ai https://api.requesty.ai https://us.i.posthog.com https://us-assets.i.posthog.com",
+			"connect-src vscode-webview://test-csp-source https://openrouter.ai https://api.requesty.ai https://ph.roocode.com",
 		)
 
 		// Extract the script-src directive section and verify required security elements

+ 1 - 1
webview-ui/src/__tests__/TelemetryClient.spec.ts

@@ -55,7 +55,7 @@ describe("TelemetryClient", () => {
 			expect(posthog.init).toHaveBeenCalledWith(
 				API_KEY,
 				expect.objectContaining({
-					api_host: "https://us.i.posthog.com",
+					api_host: "https://ph.roocode.com",
 					persistence: "localStorage",
 					loaded: expect.any(Function),
 				}),

+ 2 - 1
webview-ui/src/utils/TelemetryClient.ts

@@ -13,7 +13,8 @@ class TelemetryClient {
 			TelemetryClient.telemetryEnabled = true
 
 			posthog.init(apiKey, {
-				api_host: "https://us.i.posthog.com",
+				api_host: "https://ph.roocode.com",
+				ui_host: "https://us.posthog.com",
 				persistence: "localStorage",
 				loaded: () => posthog.identify(distinctId),
 				capture_pageview: false,

+ 1 - 1
webview-ui/src/utils/__tests__/TelemetryClient.spec.ts

@@ -60,7 +60,7 @@ describe("TelemetryClient", () => {
 		expect(posthog.init).toHaveBeenCalledWith(
 			API_KEY,
 			expect.objectContaining({
-				api_host: "https://us.i.posthog.com",
+				api_host: "https://ph.roocode.com",
 				persistence: "localStorage",
 				loaded: expect.any(Function),
 			}),