:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.
Python ab-testingai-analyticsanalyticscdpdata-warehouseexperimentsfeature-flagsjavascriptproduct-analyticspythonreactsession-replaysurveystypescriptweb-analytics
import { BreakPointFunction } from 'kea'
import { getInsightId } from 'lib/insights/getInsightId'
import { getCurrentTeamId } from 'lib/utils/getAppContext'
import { InsightShortId } from '~/types'
import { subscriptionsList } from 'products/subscriptions/frontend/generated/api'
export async function fetchTeamSubscriptionCount(breakpoint?: BreakPointFunction): Promise<number> {
const response = await subscriptionsList(String(getCurrentTeamId()), { limit: 1 })
breakpoint?.()
return response.count ?? 0
}
export async function fetchHasSubscriptionForDashboard(
dashboardId: number,
breakpoint?: BreakPointFunction
): Promise<boolean> {
const response = await subscriptionsList(String(getCurrentTeamId()), { dashboard: dashboardId, limit: 1 })
breakpoint?.()
return (response.count ?? 0) > 0
}
export async function fetchHasSubscriptionForInsightId(
insightId: number,
breakpoint?: BreakPointFunction
): Promise<boolean> {
const response = await subscriptionsList(String(getCurrentTeamId()), { insight: insightId, limit: 1 })
breakpoint?.()
return (response.count ?? 0) > 0
}
export async function fetchHasSubscriptionForInsight(
insightShortId: InsightShortId,
breakpoint?: BreakPointFunction
): Promise<boolean> {
const insightId = await getInsightId(insightShortId)
breakpoint?.()
return insightId ? await fetchHasSubscriptionForInsightId(insightId, breakpoint) : false
}