From e325acd5b1a34620b9975d68dfe324b8829c4961 Mon Sep 17 00:00:00 2001 From: Arpit Dalal Date: Sat, 1 Feb 2025 15:07:58 -0500 Subject: [PATCH] feat: improve PostHog tracking with $pageview and graceful shutdown --- index.js | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/index.js b/index.js index bae8581..02dd52b 100644 --- a/index.js +++ b/index.js @@ -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, @@ -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