Skip to content

Commit

Permalink
fix: fixes client side PostHog events capturing and adds extra data t…
Browse files Browse the repository at this point in the history
…o the metadata (#663)
  • Loading branch information
luis-herasme authored Dec 9, 2024
1 parent 0057df3 commit 79f9151
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 7 deletions.
2 changes: 1 addition & 1 deletion apps/web/src/pages/_app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ if (typeof window !== "undefined" && env.NEXT_PUBLIC_POSTHOG_ID) {
api_host: env.NEXT_PUBLIC_POSTHOG_HOST,
person_profiles: "identified_only",
loaded: (posthog) => {
if (env.NODE_ENV === "development") {
if (window.location.hostname.includes("localhost")) {
posthog.debug();
}
},
Expand Down
22 changes: 16 additions & 6 deletions packages/api/src/context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,10 @@ import type {
import cookie from "cookie";
import jwt from "jsonwebtoken";

import { BlobPropagator, getBlobPropagator } from "@blobscan/blob-propagator";
import {
BlobStorageManager,
getBlobStorageManager,
} from "@blobscan/blob-storage-manager";
import type { BlobPropagator } from "@blobscan/blob-propagator";
import { getBlobPropagator } from "@blobscan/blob-propagator";
import type { BlobStorageManager } from "@blobscan/blob-storage-manager";
import { getBlobStorageManager } from "@blobscan/blob-storage-manager";
import { prisma } from "@blobscan/db";
import { env } from "@blobscan/env";

Expand Down Expand Up @@ -119,14 +118,25 @@ export function createTRPCContext(
);
}

let pathname: string | undefined;
let query: string | undefined;

if (opts.req.url) {
const url = new URL(opts.req.url, env.BLOBSCAN_API_BASE_URL);
pathname = url.pathname;
query = url.searchParams.toString();
}

posthog.capture({
distinctId,
event: "trpc_request",
properties: {
$ip: getIP(opts.req),
scope,
$current_url: opts.req.url,
method: opts.req.method,
network: env.NETWORK_NAME,
pathname,
query,
},
});

Expand Down

0 comments on commit 79f9151

Please sign in to comment.