Skip to content

Commit

Permalink
feat: improve PostHog tracking with $pageview and graceful shutdown
Browse files Browse the repository at this point in the history
  • Loading branch information
arpitdalal committed Feb 1, 2025
1 parent 8359ee2 commit e325acd
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,9 @@ app.use((req, _, next) => {
if (req.url !== "/healthcheck") {
posthogClient.capture({
distinctId: req.ip,
event: "pageview",
event: "$pageview",
properties: {
$current_url: req.originalUrl,
path: req.path,
url: req.originalUrl,
method: req.method,
Expand Down Expand Up @@ -188,6 +189,12 @@ app.listen(port, () => {
console.log(`Server is running on port ${port}`);
});

process.on("SIGINT", async () => {
console.log("SIGINT signal received.");
await posthogClient.shutdown();
process.exit(0);
});

/**
* @param {string} url
* @param {string} pathToRemove
Expand Down

0 comments on commit e325acd

Please sign in to comment.