Skip to content

Commit

Permalink
feat: Add UI to control human friendly comparison periods
Browse files Browse the repository at this point in the history
You can now toggle that in the UI on `settings/environment-product-analytics#human-friendly-comparison-periods`
  • Loading branch information
rafaeelaudibert committed Dec 27, 2024
1 parent 5a2ab1c commit a298ea9
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 0 deletions.
6 changes: 6 additions & 0 deletions frontend/src/scenes/settings/SettingsMap.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import { CorrelationConfig } from './environment/CorrelationConfig'
import { DataAttributes } from './environment/DataAttributes'
import { GroupAnalyticsConfig } from './environment/GroupAnalyticsConfig'
import { HeatmapsSettings } from './environment/HeatmapsSettings'
import { HumanFriendlyComparisonPeriodsSetting } from './environment/HumanFriendlyComparisonPeriodsSetting'
import { IPAllowListInfo } from './environment/IPAllowListInfo'
import { IPCapture } from './environment/IPCapture'
import { ManagedReverseProxy } from './environment/ManagedReverseProxy'
Expand Down Expand Up @@ -183,6 +184,11 @@ export const SETTINGS_MAP: SettingSection[] = [
title: 'IP data capture configuration',
component: <IPCapture />,
},
{
id: 'human-friendly-comparison-periods',
title: 'Human friendly comparison periods',
component: <HumanFriendlyComparisonPeriodsSetting />,
},
{
id: 'group-analytics',
title: 'Group analytics',
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import { LemonSwitch } from '@posthog/lemon-ui'
import { useActions, useValues } from 'kea'
import { teamLogic } from 'scenes/teamLogic'

export function HumanFriendlyComparisonPeriodsSetting(): JSX.Element {
const { updateCurrentTeam } = useActions(teamLogic)
const { currentTeam, currentTeamLoading } = useValues(teamLogic)

return (
<>
<p>
When comparing against a previous month or year, PostHog will use the same start and end dates as the
current period by default. It might be desirable, however, to compare against the same day of the week
instead of the same day to account for weekend seasonality. If that's the case for your analysis, you
can enable this setting.
</p>
<p>
In practice, this means that an year comparison becomes a 52 week comparison, and a month comparison
becomes a 4 week comparison.
</p>
<LemonSwitch
onChange={(checked) => {
updateCurrentTeam({ human_friendly_comparison_periods: checked })
}}
checked={!!currentTeam?.human_friendly_comparison_periods}
disabled={currentTeamLoading}
label="Use human friendly comparison periods"
bordered
/>
</>
)
}
1 change: 1 addition & 0 deletions frontend/src/scenes/settings/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ export type SettingId =
| 'person-display-name'
| 'path-cleaning'
| 'datacapture'
| 'human-friendly-comparison-periods'
| 'group-analytics'
| 'persons-on-events'
| 'replay'
Expand Down
1 change: 1 addition & 0 deletions frontend/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -544,6 +544,7 @@ export interface TeamType extends TeamBasicType {
live_events_columns: string[] | null // Custom columns shown on the Live Events page
live_events_token: string
cookieless_server_hash_mode?: CookielessServerHashMode
human_friendly_comparison_periods: boolean

/** Effective access level of the user in this specific team. Null if user has no access. */
effective_membership_level: OrganizationMembershipLevel | null
Expand Down
1 change: 1 addition & 0 deletions posthog/api/team.py
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,7 @@ class Meta:
"live_events_columns",
"recording_domains",
"cookieless_server_hash_mode",
"human_friendly_comparison_periods",
"person_on_events_querying_enabled",
"inject_web_apps",
"extra_settings",
Expand Down

0 comments on commit a298ea9

Please sign in to comment.