: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 { MakeLogicType, actions, connect, kea, listeners, path, reducers, selectors } from 'kea'
import posthog from 'posthog-js'
import { superpowersLogic } from 'lib/components/Superpowers/superpowersLogic'
import type { UserType } from '~/types'
// Generated by kea-typegen. Update if you're an agent, ignore if you're human.
export interface postHogTeamCohortBannerLogicValues {
excludedFromPostHogTeamCohort: boolean // superpowersLogic
user: UserType | null // superpowersLogic
bannerVisible: boolean
dismissed: boolean
}
// Generated by kea-typegen. Update if you're an agent, ignore if you're human.
export interface postHogTeamCohortBannerLogicActions {
setExcludedFromPostHogTeamCohort: (excluded: boolean) => {
excluded: boolean
} // superpowersLogic
dismissBanner: () => {
value: true
}
rejoinPostHogTeamCohort: (navCollapsed: boolean) => {
navCollapsed: boolean
}
}
// Generated by kea-typegen. Update if you're an agent, ignore if you're human.
export interface postHogTeamCohortBannerLogicMeta {
__keaTypeGenInternalSelectorTypes: {
bannerVisible: (user: UserType | null, excludedFromPostHogTeamCohort: boolean, dismissed: boolean) => boolean
}
}
export type postHogTeamCohortBannerLogicType = MakeLogicType<
postHogTeamCohortBannerLogicValues,
postHogTeamCohortBannerLogicActions,
Record<string, any>,
postHogTeamCohortBannerLogicMeta
>
export const postHogTeamCohortBannerLogic = kea<postHogTeamCohortBannerLogicType>([
path(['layout', 'panel-layout', 'navbar', 'postHogTeamCohortBannerLogic']),
connect(() => ({
values: [superpowersLogic, ['excludedFromPostHogTeamCohort', 'user']],
actions: [superpowersLogic, ['setExcludedFromPostHogTeamCohort']],
})),
actions({
dismissBanner: true,
rejoinPostHogTeamCohort: (navCollapsed: boolean) => ({ navCollapsed }),
}),
reducers({
// Not persisted, so a page refresh shows the banner again while the opt-out is still on.
// Any change to the opt-out clears the dismissal, so leaving the cohort again shows the banner.
dismissed: [
false,
{
dismissBanner: () => true,
setExcludedFromPostHogTeamCohort: () => false,
},
],
}),
selectors({
bannerVisible: [
(s) => [s.user, s.excludedFromPostHogTeamCohort, s.dismissed],
(user: UserType | null, excludedFromPostHogTeamCohort: boolean, dismissed: boolean): boolean =>
!!user?.is_staff && excludedFromPostHogTeamCohort && !dismissed,
],
}),
listeners(({ actions }) => ({
dismissBanner: () => {
// pinned: analytics event name, renaming breaks dashboards
posthog.capture('nav posthog team cohort banner dismissed')
},
rejoinPostHogTeamCohort: ({ navCollapsed }) => {
// pinned: analytics event name, renaming breaks dashboards
posthog.capture('nav posthog team cohort banner rejoin clicked', { nav_collapsed: navCollapsed })
actions.setExcludedFromPostHogTeamCohort(false)
},
})),
])