From 65babae41a3a60dc5b8aa88aa7fc847b5cb7f84d Mon Sep 17 00:00:00 2001 From: x032205 Date: Tue, 16 Sep 2025 00:54:56 -0400 Subject: [PATCH] feat(notifications): add notification update posthog telemetry to track when notifications are clicked / read. also increased popup z index --- backend/src/server/routes/v1/notification-router.ts | 12 ++++++++++++ backend/src/services/telemetry/telemetry-types.ts | 12 +++++++++++- .../components/NavBar/NotificationDropdown.tsx | 2 +- 3 files changed, 24 insertions(+), 2 deletions(-) diff --git a/backend/src/server/routes/v1/notification-router.ts b/backend/src/server/routes/v1/notification-router.ts index 5f72b88d6..955a1174e 100644 --- a/backend/src/server/routes/v1/notification-router.ts +++ b/backend/src/server/routes/v1/notification-router.ts @@ -3,8 +3,10 @@ import { z } from "zod"; import { UserNotificationsSchema } from "@app/db/schemas/user-notifications"; import { UnauthorizedError } from "@app/lib/errors"; import { readLimit, writeLimit } from "@app/server/config/rateLimiter"; +import { getTelemetryDistinctId } from "@app/server/lib/telemetry"; import { verifyAuth } from "@app/server/plugins/auth/verify-auth"; import { AuthMode } from "@app/services/auth/auth-type"; +import { PostHogEventTypes } from "@app/services/telemetry/telemetry-types"; export const registerNotificationRouter = async (server: FastifyZodProvider) => { server.route({ @@ -97,6 +99,16 @@ export const registerNotificationRouter = async (server: FastifyZodProvider) => ...req.body }); + await server.services.telemetry.sendPostHogEvents({ + event: PostHogEventTypes.NotificationUpdated, + distinctId: getTelemetryDistinctId(req), + organizationId: req.permission.orgId, + properties: { + notificationId: req.params.notificationId, + ...req.body + } + }); + return { notification }; } }); diff --git a/backend/src/services/telemetry/telemetry-types.ts b/backend/src/services/telemetry/telemetry-types.ts index a43a2f746..de466614a 100644 --- a/backend/src/services/telemetry/telemetry-types.ts +++ b/backend/src/services/telemetry/telemetry-types.ts @@ -32,7 +32,8 @@ export enum PostHogEventTypes { IssueSshHostHostCert = "Issue SSH Host Host Certificate", SignCert = "Sign PKI Certificate", IssueCert = "Issue PKI Certificate", - InvalidateCache = "Invalidate Cache" + InvalidateCache = "Invalidate Cache", + NotificationUpdated = "Notification Updated" } export type TSecretModifiedEvent = { @@ -232,6 +233,14 @@ export type TInvalidateCacheEvent = { }; }; +export type TNotificationUpdatedEvent = { + event: PostHogEventTypes.NotificationUpdated; + properties: { + notificationId: string; + isRead?: boolean; + }; +}; + export type TPostHogEvent = { distinctId: string; organizationId?: string } & ( | TSecretModifiedEvent | TAdminInitEvent @@ -251,4 +260,5 @@ export type TPostHogEvent = { distinctId: string; organizationId?: string } & ( | TSignCertificateEvent | TIssueCertificateEvent | TInvalidateCacheEvent + | TNotificationUpdatedEvent ); diff --git a/frontend/src/layouts/OrganizationLayout/components/NavBar/NotificationDropdown.tsx b/frontend/src/layouts/OrganizationLayout/components/NavBar/NotificationDropdown.tsx index a5e9166d9..6b6381ac1 100644 --- a/frontend/src/layouts/OrganizationLayout/components/NavBar/NotificationDropdown.tsx +++ b/frontend/src/layouts/OrganizationLayout/components/NavBar/NotificationDropdown.tsx @@ -46,7 +46,7 @@ export const NotificationDropdown = () => {