mirror of
https://github.com/eliasstepanik/core.git
synced 2026-01-10 23:48:26 +00:00
fix: posthog use reverse proxy and reduce tracking information
This commit is contained in:
parent
4a0a57cb97
commit
386580b0ee
@ -19,7 +19,8 @@ export const usePostHog = (
|
||||
if (postHogInitialized.current === true) return;
|
||||
if (logging) console.log("Initializing PostHog");
|
||||
posthog.init(apiKey, {
|
||||
api_host: "https://us.i.posthog.com",
|
||||
api_host: "/relay-Xm1a",
|
||||
ui_host: "https://us.posthog.com",
|
||||
opt_in_site_apps: true,
|
||||
debug,
|
||||
loaded: function (posthog) {
|
||||
|
||||
38
apps/webapp/app/routes/<ph_proxy_path>.$.tsx
Normal file
38
apps/webapp/app/routes/<ph_proxy_path>.$.tsx
Normal file
@ -0,0 +1,38 @@
|
||||
import type { ActionFunction, LoaderFunction } from "@remix-run/node";
|
||||
|
||||
const API_HOST = "us.i.posthog.com";
|
||||
const ASSET_HOST = "us-assets.i.posthog.com";
|
||||
|
||||
const posthogProxy = async (request: Request) => {
|
||||
const url = new URL(request.url);
|
||||
const hostname = url.pathname.startsWith("/relay-Xm1a/static/")
|
||||
? ASSET_HOST
|
||||
: API_HOST;
|
||||
|
||||
const newUrl = new URL(url);
|
||||
newUrl.protocol = "https";
|
||||
newUrl.hostname = hostname;
|
||||
newUrl.port = "443";
|
||||
newUrl.pathname = newUrl.pathname.replace(/^\/relay-Xm1a/, "");
|
||||
|
||||
const headers = new Headers(request.headers);
|
||||
headers.set("host", hostname);
|
||||
|
||||
const response = await fetch(newUrl, {
|
||||
method: request.method,
|
||||
headers,
|
||||
body: request.body,
|
||||
});
|
||||
|
||||
return new Response(response.body, {
|
||||
status: response.status,
|
||||
statusText: response.statusText,
|
||||
headers: response.headers,
|
||||
});
|
||||
};
|
||||
|
||||
export const loader: LoaderFunction = async ({ request }) =>
|
||||
posthogProxy(request);
|
||||
|
||||
export const action: ActionFunction = async ({ request }) =>
|
||||
posthogProxy(request);
|
||||
Loading…
x
Reference in New Issue
Block a user