: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, kea, path, reducers, selectors } from 'kea'
import { DEFAULT_CONTENT_ORDER, DEFAULT_STAT_ORDER, LiveContentCardId, LiveStatCardId, mergeOrder } from './liveCards'
const teamId = window.POSTHOG_APP_CONTEXT?.current_team?.id
const persistConfig = { persist: true, prefix: `${teamId}__` }
// Generated by kea-typegen. Update if you're an agent, ignore if you're human.
export interface liveWebAnalyticsLayoutLogicValues {
cardOrder: LiveContentCardId[]
isEditing: boolean
persistedCardOrder: LiveContentCardId[]
persistedStatOrder: LiveStatCardId[]
statOrder: LiveStatCardId[]
}
// Generated by kea-typegen. Update if you're an agent, ignore if you're human.
export interface liveWebAnalyticsLayoutLogicActions {
resetLayout: () => {
value: true
}
setCardOrder: (order: LiveContentCardId[]) => {
order: LiveContentCardId[]
}
setEditing: (editing: boolean) => {
editing: boolean
}
setStatOrder: (order: LiveStatCardId[]) => {
order: LiveStatCardId[]
}
}
// Generated by kea-typegen. Update if you're an agent, ignore if you're human.
export interface liveWebAnalyticsLayoutLogicMeta {
__keaTypeGenInternalSelectorTypes: {
statOrder: (persistedStatOrder: LiveStatCardId[]) => LiveStatCardId[]
cardOrder: (persistedCardOrder: LiveContentCardId[]) => LiveContentCardId[]
}
}
export type liveWebAnalyticsLayoutLogicType = MakeLogicType<
liveWebAnalyticsLayoutLogicValues,
liveWebAnalyticsLayoutLogicActions,
Record<string, any>,
liveWebAnalyticsLayoutLogicMeta
>
export const liveWebAnalyticsLayoutLogic = kea<liveWebAnalyticsLayoutLogicType>([
path(['scenes', 'webAnalytics', 'liveWebAnalyticsLayoutLogic']),
actions({
setStatOrder: (order: LiveStatCardId[]) => ({ order }),
setCardOrder: (order: LiveContentCardId[]) => ({ order }),
setEditing: (editing: boolean) => ({ editing }),
resetLayout: true,
}),
reducers({
persistedStatOrder: [
[...DEFAULT_STAT_ORDER] as LiveStatCardId[],
persistConfig,
{
setStatOrder: (_, { order }) => order,
resetLayout: () => [...DEFAULT_STAT_ORDER],
},
],
persistedCardOrder: [
[...DEFAULT_CONTENT_ORDER] as LiveContentCardId[],
persistConfig,
{
setCardOrder: (_, { order }) => order,
resetLayout: () => [...DEFAULT_CONTENT_ORDER],
},
],
isEditing: [
false,
{
setEditing: (_, { editing }) => editing,
},
],
}),
selectors({
statOrder: [
(s) => [s.persistedStatOrder],
(persisted: LiveStatCardId[]): LiveStatCardId[] => mergeOrder(persisted, DEFAULT_STAT_ORDER),
],
cardOrder: [
(s) => [s.persistedCardOrder],
(persisted: LiveContentCardId[]): LiveContentCardId[] => mergeOrder(persisted, DEFAULT_CONTENT_ORDER),
],
}),
])