fix: posthog free limit reporting (#2026)

This commit is contained in:
Matti Nannt
2024-02-06 21:40:00 +01:00
committed by GitHub
parent 3472033c7e
commit e80d71e654
3 changed files with 7 additions and 7 deletions

View File

@@ -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([

View File

@@ -6,19 +6,19 @@ import { getTeamDetails } from "@formbricks/lib/teamDetail/service";
export const sendFreeLimitReachedEventToPosthogBiWeekly = async (
environmentId: string,
plan: "inAppSurvey" | "userTargeting"
) => {
await unstable_cache(
): Promise<string> =>
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
}
)();
};

View File

@@ -58,7 +58,7 @@ export async function GET(
isInAppSurveyLimitReached =
!hasInAppSurveySubscription && currentResponseCount >= PRICING_APPSURVEYS_FREE_RESPONSES;
if (isInAppSurveyLimitReached) {
sendFreeLimitReachedEventToPosthogBiWeekly(environmentId, "inAppSurvey");
await sendFreeLimitReachedEventToPosthogBiWeekly(environmentId, "inAppSurvey");
}
}