: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 type { ExtensionContextValue } from '@stripe/ui-extension-sdk/context'
import BrandIcon from './views/logomark.svg'
export const BRAND_COLOR = '#F7A501'
export interface AppConstants {
POSTHOG_US_BASE_URL: string
POSTHOG_EU_BASE_URL: string
POSTHOG_DASHBOARD_URL: string
POSTHOG_NEW_SOURCE_URL: string
}
const FALLBACK_CONSTANTS: AppConstants = {
POSTHOG_US_BASE_URL: 'https://us.posthog.com',
POSTHOG_EU_BASE_URL: 'https://eu.posthog.com',
POSTHOG_DASHBOARD_URL: 'https://app.posthog.com',
POSTHOG_NEW_SOURCE_URL: 'https://app.posthog.com/data-warehouse/new-source?kind=Stripe',
}
// Must match the `constants` block in stripe-app.json.
// `stripe apps upload` (apps plugin <1.15.32) server-canonicalises the manifest
// by adding a `declarations` block that causes the SDK to ignore top-level
// `constants` at runtime, making `environment.constants` undefined. Fall back
// to these hardcoded values when that happens. See PR #56404.
export function getConstants(environment: ExtensionContextValue['environment']): AppConstants {
return (environment?.constants as unknown as AppConstants | undefined) ?? FALLBACK_CONSTANTS
}
export { BrandIcon }
export interface Timeframe {
value: string
label: string
days: number
}
export const TIMEFRAMES: Timeframe[] = [
{ value: '-7d', label: 'Last 7 days', days: 7 },
{ value: '-30d', label: 'Last 30 days', days: 30 },
{ value: '-90d', label: 'Last 90 days', days: 90 },
{ value: '-180d', label: 'Last 180 days', days: 180 },
]
export const DEFAULT_TIMEFRAME: Timeframe = TIMEFRAMES[1]
export function getTimeframe(value: string): Timeframe {
return TIMEFRAMES.find((t) => t.value === value) ?? DEFAULT_TIMEFRAME
}
export const POSTHOG_ICON_SRC =
'data:image/svg+xml,%3Csvg%20width%3D%2250%22%20height%3D%2230%22%20viewBox%3D%220%200%2050%2030%22%20fill%3D%22none%22%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%3E%3Cpath%20d%3D%22M10.8914%2017.2057c-.3685.7371-1.42031.7371-1.78884%200L8.2212%2015.443c-.14077-.2815-.14077-.6129%200-.8944l.88136-1.7627c.36853-.7371%201.42034-.7371%201.78884%200l.8814%201.7627c.1407.2815.1407.6129%200%20.8944l-.8814%201.7627zM10.8914%2027.2028c-.3685.737-1.42031.737-1.78884%200L8.2212%2025.44c-.14077-.2815-.14077-.6129%200-.8944l.88136-1.7627c.36853-.7371%201.42034-.7371%201.78884%200l.8814%201.7627c.1407.2815.1407.6129%200%20.8944l-.8814%201.7628z%22%20fill%3D%22%231D4AFF%22%2F%3E%3Cpath%20d%3D%22M0%2023.4082c0-.8909%201.07714-1.3371%201.70711-.7071l4.58338%204.5834c.62997.63.1838%201.7071-.7071%201.7071H.999999c-.552284%200-.999999-.4477-.999999-1v-4.5834zm0-4.8278c0%20.2652.105357.5196.292893.7071l9.411217%209.4112c.18753.1875.44189.2929.70709.2929h5.1692c.8909%200%201.3371-1.0771.7071-1.7071L1.70711%2012.7041C1.07714%2012.0741%200%2012.5203%200%2013.4112v5.1692zm0-9.99701c0%20.26521.105357.51957.292893.7071L19.7011%2028.6987c.1875.1875.4419.2929.7071.2929h5.1692c.8909%200%201.3371-1.0771.7071-1.7071L1.70711%202.70711C1.07715%202.07715%200%202.52331%200%203.41421v5.16918zm9.997%200c0%20.26521.1054.51957.2929.7071l17.994%2017.99401c.63.63%201.7071.1838%201.7071-.7071v-5.1692c0-.2652-.1054-.5196-.2929-.7071l-17.994-17.994c-.63-.62996-1.7071-.18379-1.7071.70711v5.16918zm11.7041-5.87628c-.63-.62997-1.7071-.1838-1.7071.7071v5.16918c0%20.26521.1054.51957.2929.7071l7.997%207.99701c.63.63%201.7071.1838%201.7071-.7071v-5.1692c0-.2652-.1054-.5196-.2929-.7071l-7.997-7.99699z%22%20fill%3D%22%23F9BD2B%22%2F%3E%3Cpath%20d%3D%22M42.5248%2023.5308l-9.4127-9.4127c-.63-.63-1.7071-.1838-1.7071.7071v13.1664c0%20.5523.4477%201%201%201h14.5806c.5523%200%201-.4477%201-1v-1.199c0-.5523-.4496-.9934-.9973-1.0647-1.6807-.2188-3.2528-.9864-4.4635-2.1971zm-6.3213%202.2618c-.8829%200-1.5995-.7166-1.5995-1.5996%200-.8829.7166-1.5995%201.5995-1.5995.883%200%201.5996.7166%201.5996%201.5995%200%20.883-.7166%201.5996-1.5996%201.5996z%22%20fill%3D%22%23000%22%2F%3E%3Cpath%20d%3D%22M0%2027.9916c0%20.5523.447715%201%201%201h4.58339c.8909%200%201.33707-1.0771.70711-1.7071l-4.58339-4.5834C1.07714%2022.0711%200%2022.5173%200%2023.4082v4.5834zM9.997%2010.997L1.70711%202.70711C1.07714%202.07714%200%202.52331%200%203.41421v5.16918c0%20.26521.105357.51957.292893.7071L9.997%2018.9946V10.997zM1.70711%2012.7041C1.07714%2012.0741%200%2012.5203%200%2013.4112v5.1692c0%20.2652.105357.5196.292893.7071L9.997%2028.9916V20.994l-8.28989-8.2899z%22%20fill%3D%22%231D4AFF%22%2F%3E%3Cpath%20d%3D%22M19.994%2011.4112c0-.2652-.1053-.5196-.2929-.7071l-7.997-7.99699c-.6299-.62997-1.70709-.1838-1.70709.7071v5.16918c0%20.26521.10539.51957.29289.7071l9.7041%209.70411v-7.5834zM9.99701%2028.9916h5.58339c.8909%200%201.3371-1.0771.7071-1.7071L9.99701%2020.994v7.9976zM9.99701%2010.997v7.5834c0%20.2652.10539.5196.29289.7071l9.7041%209.7041v-7.5834c0-.2652-.1053-.5196-.2929-.7071L9.99701%2010.997z%22%20fill%3D%22%23F54E00%22%2F%3E%3C%2Fsvg%3E'