-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
swap vercel analytics for posthog (#1719)
- Loading branch information
1 parent
4cc3fa1
commit 9270067
Showing
7 changed files
with
491 additions
and
214 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -42,7 +42,6 @@ | |
"@fern-ui/fern-docs-utils": "workspace:*", | ||
"@fern-ui/search-utils": "workspace:*", | ||
"@fern-ui/ui": "workspace:*", | ||
"@vercel/analytics": "^1.3.1", | ||
"@vercel/kv": "^2.0.0", | ||
"@workos-inc/node": "^6.1.0", | ||
"algoliasearch": "^5.8.1", | ||
|
@@ -57,6 +56,7 @@ | |
"next": "npm:@fern-api/[email protected]", | ||
"node-fetch": "2.7.0", | ||
"postcss-import": "^16.0.1", | ||
"posthog-node": "^4.2.1", | ||
"react": "^18.2.0", | ||
"react-dom": "^18.2.0", | ||
"sharp": "^0.33.3", | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import { PostHog } from "posthog-node"; | ||
|
||
function getPosthogKey(): string { | ||
const key = process.env.NEXT_PUBLIC_POSTHOG_API_KEY; | ||
if (key == null) { | ||
throw new Error("NEXT_PUBLIC_POSTHOG_API_KEY is not set"); | ||
} | ||
return key.trim(); | ||
} | ||
|
||
function getPosthog(): PostHog { | ||
return new PostHog(getPosthogKey(), { | ||
host: "https://us.i.posthog.com", | ||
}); | ||
} | ||
|
||
export async function track(event: string, properties?: Record<string, unknown>): Promise<void> { | ||
try { | ||
const client = getPosthog(); | ||
|
||
client.capture({ | ||
event, | ||
distinctId: "server-side-event", | ||
properties: { | ||
// anonymize this event because it's server-side https://posthog.com/docs/product-analytics/capture-events?tab=Backend | ||
$process_person_profile: false, | ||
...properties, | ||
}, | ||
}); | ||
|
||
await client.shutdown(); | ||
} catch (error) { | ||
// eslint-disable-next-line no-console | ||
console.error(error); | ||
} | ||
} |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.