From e80d71e65419e96603825be6fe4cb270d6ae0936 Mon Sep 17 00:00:00 2001 From: Matti Nannt Date: Tue, 6 Feb 2024 21:40:00 +0100 Subject: [PATCH] fix: posthog free limit reporting (#2026) --- .../client/[environmentId]/in-app/sync/[userId]/route.ts | 4 ++-- .../v1/client/[environmentId]/in-app/sync/lib/posthog.ts | 8 ++++---- .../api/v1/client/[environmentId]/in-app/sync/route.ts | 2 +- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/apps/web/app/api/v1/client/[environmentId]/in-app/sync/[userId]/route.ts b/apps/web/app/api/v1/client/[environmentId]/in-app/sync/[userId]/route.ts index 4950b22bef..776bd76949 100644 --- a/apps/web/app/api/v1/client/[environmentId]/in-app/sync/[userId]/route.ts +++ b/apps/web/app/api/v1/client/[environmentId]/in-app/sync/[userId]/route.ts @@ -96,7 +96,7 @@ export async function GET( person = await createPerson(environmentId, userId); } } else { - sendFreeLimitReachedEventToPosthogBiWeekly(environmentId, "userTargeting"); + await sendFreeLimitReachedEventToPosthogBiWeekly(environmentId, "userTargeting"); const errorMessage = `Monthly Active Users limit in the current plan is reached in ${environmentId}`; if (!person) { // if it's a new person and MAU limit is reached, throw an error @@ -110,7 +110,7 @@ export async function GET( } } if (isInAppSurveyLimitReached) { - sendFreeLimitReachedEventToPosthogBiWeekly(environmentId, "inAppSurvey"); + await sendFreeLimitReachedEventToPosthogBiWeekly(environmentId, "inAppSurvey"); } const [surveys, noCodeActionClasses, product] = await Promise.all([ diff --git a/apps/web/app/api/v1/client/[environmentId]/in-app/sync/lib/posthog.ts b/apps/web/app/api/v1/client/[environmentId]/in-app/sync/lib/posthog.ts index 0f770d0161..f7a072a045 100644 --- a/apps/web/app/api/v1/client/[environmentId]/in-app/sync/lib/posthog.ts +++ b/apps/web/app/api/v1/client/[environmentId]/in-app/sync/lib/posthog.ts @@ -6,19 +6,19 @@ import { getTeamDetails } from "@formbricks/lib/teamDetail/service"; export const sendFreeLimitReachedEventToPosthogBiWeekly = async ( environmentId: string, plan: "inAppSurvey" | "userTargeting" -) => { - await unstable_cache( +): Promise => + unstable_cache( async () => { const teamDetails = await getTeamDetails(environmentId); if (teamDetails?.teamOwnerId) { - return await capturePosthogEvent(teamDetails.teamOwnerId, "free limit reached", teamDetails.teamId, { + await capturePosthogEvent(teamDetails.teamOwnerId, "free limit reached", teamDetails.teamId, { plan, }); } + return "success"; }, [`posthog-${plan}-limitReached-${environmentId}`], { revalidate: 60 * 60 * 24 * 15, // 15 days } )(); -}; diff --git a/apps/web/app/api/v1/client/[environmentId]/in-app/sync/route.ts b/apps/web/app/api/v1/client/[environmentId]/in-app/sync/route.ts index 61113d8cd0..a5d211cc98 100644 --- a/apps/web/app/api/v1/client/[environmentId]/in-app/sync/route.ts +++ b/apps/web/app/api/v1/client/[environmentId]/in-app/sync/route.ts @@ -58,7 +58,7 @@ export async function GET( isInAppSurveyLimitReached = !hasInAppSurveySubscription && currentResponseCount >= PRICING_APPSURVEYS_FREE_RESPONSES; if (isInAppSurveyLimitReached) { - sendFreeLimitReachedEventToPosthogBiWeekly(environmentId, "inAppSurvey"); + await sendFreeLimitReachedEventToPosthogBiWeekly(environmentId, "inAppSurvey"); } }