: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
feat(growth): play five gold rings during christmas (#122112)
Paul D'Ambra2e352e7177c1
diff --git a/frontend/public/sounds/five-gold-rings.mp3 b/frontend/public/sounds/five-gold-rings.mp3new file mode 100644index 000000000000..cf663e9c9a87Binary files /dev/null and b/frontend/public/sounds/five-gold-rings.mp3 differdiff --git a/frontend/src/lib/constants.tsx b/frontend/src/lib/constants.tsxindex 3a0a63951068..96bd40516008 100644--- a/frontend/src/lib/constants.tsx+++ b/frontend/src/lib/constants.tsx@@ -276,6 +276,7 @@ export const FEATURE_FLAGS = {CDP_NEW_PRICING: 'cdp-new-pricing', // owner: #team-workflowsCDP_PERSON_UPDATES: 'cdp-person-updates', // owner: #team-workflows-cdpCDP_VERCEL_LOG_DRAIN: 'cdp-vercel-log-drain', // owner: #team-workflows-cdp+ CHRISTMAS_GOLD_RINGS: 'christmas-gold-rings', // owner: #team-growthCLEARABLE_NOTIFICATIONS: 'clearable-notifications', // owner: @jordanm-posthog #team-web-analyticsCODE_BADGE_SELF_DRIVING_LABEL: 'code-badge-self-driving-label', // owner: #team-self-driving, experiment: label the Code badge "Self-driving" and compare setup activationsCOHORT_INLINE_CALCULATION: 'inline-cohort-calculation', // owner: #team-analytics-platform, inlines fast dynamic cohort queries instead of using precomputed cohortpeople tablediff --git a/frontend/src/lib/holidayGoldRings.test.ts b/frontend/src/lib/holidayGoldRings.test.tsnew file mode 100644index 000000000000..16f28b0525b3--- /dev/null+++ b/frontend/src/lib/holidayGoldRings.test.ts@@ -0,0 +1,133 @@+import { isGoldRingsMuted, listenForGoldRingsKeys } from './holidayGoldRings'++describe('holiday gold rings keys', () => {+ afterEach(() => {+ sessionStorage.removeItem('christmas-gold-rings-muted')+ jest.restoreAllMocks()+ jest.useRealTimers()+ })++ test.each([+ ['flag on before December', new Date(2026, 9, 22), true, 1],+ ['flag on after Christmas', new Date(2027, 0, 6), true, 1],+ ['flag off during Christmas', new Date(2026, 11, 25), false, 0],+ ] as const)('%s', (_name, date, enabled, expected) => {+ jest.useFakeTimers()+ jest.setSystemTime(date)+ const play = jest.spyOn(HTMLMediaElement.prototype, 'play').mockResolvedValue()+ jest.spyOn(HTMLMediaElement.prototype, 'pause').mockImplementation()+ const stopListening = listenForGoldRingsKeys(() => enabled)++ window.dispatchEvent(new KeyboardEvent('keydown', { key: '5' }))++ expect(play).toHaveBeenCalledTimes(expected)+ stopListening()+ })++ test('plays once for a held key', () => {+ jest.useFakeTimers()+ jest.setSystemTime(new Date(2026, 11, 25))+ const play = jest.spyOn(HTMLMediaElement.prototype, 'play').mockResolvedValue()+ jest.spyOn(HTMLMediaElement.prototype, 'pause').mockImplementation()+ const stopListening = listenForGoldRingsKeys(() => true)++ window.dispatchEvent(new KeyboardEvent('keydown', { key: '5' }))+ window.dispatchEvent(new KeyboardEvent('keydown', { key: '5', repeat: true }))++ expect(play).toHaveBeenCalledTimes(1)+ stopListening()+ })++ test.each(['I hate Xmas', 'ihatexmas', 'I HATE XMAS'])('turns off for %s', (phrase) => {+ jest.useFakeTimers()+ jest.setSystemTime(new Date(2026, 11, 25))+ const play = jest.spyOn(HTMLMediaElement.prototype, 'play').mockResolvedValue()+ jest.spyOn(HTMLMediaElement.prototype, 'pause').mockImplementation()+ const stopListening = listenForGoldRingsKeys(() => true)++ for (const key of phrase) {+ window.dispatchEvent(new KeyboardEvent('keydown', { key }))+ }+ window.dispatchEvent(new KeyboardEvent('keydown', { key: '5' }))++ expect(isGoldRingsMuted()).toBe(true)+ expect(play).not.toHaveBeenCalled()+ stopListening()+ })++ test('resets an incomplete opt-out phrase after a pause', () => {+ jest.useFakeTimers()+ jest.setSystemTime(new Date(2026, 11, 25))+ const stopListening = listenForGoldRingsKeys(() => true)++ for (const key of 'I hate') {+ window.dispatchEvent(new KeyboardEvent('keydown', { key }))+ }+ jest.advanceTimersByTime(2_001)+ for (const key of ' Xmas') {+ window.dispatchEvent(new KeyboardEvent('keydown', { key }))+ }++ expect(isGoldRingsMuted()).toBe(false)+ stopListening()+ })++ test.each([+ ['an input', '<input data-key-target />'],+ ['a textarea', '<textarea data-key-target></textarea>'],+ ['contenteditable text', '<div contenteditable="true"><span data-key-target></span></div>'],+ ['a code editor', '<div class="monaco-editor"><span data-key-target></span></div>'],+ ])('plays without swallowing 5 while typing in %s', (_name, markup) => {+ jest.useFakeTimers()+ jest.setSystemTime(new Date(2026, 11, 25))+ const play = jest.spyOn(HTMLMediaElement.prototype, 'play').mockResolvedValue()+ const container = document.createElement('div')+ container.innerHTML = markup+ document.body.appendChild(container)+ const stopListening = listenForGoldRingsKeys(() => true)++ const event = new KeyboardEvent('keydown', { bubbles: true, cancelable: true, key: '5' })+ container.querySelector('[data-key-target]')?.dispatchEvent(event)++ expect(play).toHaveBeenCalledTimes(1)+ expect(event.defaultPrevented).toBe(false)+ stopListening()+ container.remove()+ })++ test('does not play or track the opt-out phrase in password inputs', () => {+ jest.spyOn(HTMLMediaElement.prototype, 'pause').mockImplementation()+ const play = jest.spyOn(HTMLMediaElement.prototype, 'play').mockResolvedValue()+ const input = document.createElement('input')+ input.type = 'password'+ document.body.appendChild(input)+ const stopListening = listenForGoldRingsKeys(() => true)++ for (const key of 'I hate Xmas') {+ input.dispatchEvent(new KeyboardEvent('keydown', { bubbles: true, key }))+ }+ const event = new KeyboardEvent('keydown', { bubbles: true, cancelable: true, key: '5' })+ input.dispatchEvent(event)++ expect(play).not.toHaveBeenCalled()+ expect(isGoldRingsMuted()).toBe(false)+ expect(event.defaultPrevented).toBe(false)+ stopListening()+ input.remove()+ })++ test('can opt out while typing in an input', () => {+ jest.spyOn(HTMLMediaElement.prototype, 'pause').mockImplementation()+ const input = document.createElement('input')+ document.body.appendChild(input)+ const stopListening = listenForGoldRingsKeys(() => true)++ for (const key of 'I hate Xmas') {+ input.dispatchEvent(new KeyboardEvent('keydown', { bubbles: true, key }))+ }++ expect(isGoldRingsMuted()).toBe(true)+ stopListening()+ input.remove()+ })+})diff --git a/frontend/src/lib/holidayGoldRings.ts b/frontend/src/lib/holidayGoldRings.tsnew file mode 100644index 000000000000..16e79786446e--- /dev/null+++ b/frontend/src/lib/holidayGoldRings.ts@@ -0,0 +1,63 @@+let goldRingsAudio: HTMLAudioElement | null = null+const optOutKey = 'christmas-gold-rings-muted'+const optOutPhrase = 'ihatexmas'+const sequenceTimeoutMs = 2_000++const isPlainKey = (event: KeyboardEvent): boolean =>+ event.key.length === 1 && !event.repeat && !event.altKey && !event.ctrlKey && !event.metaKey++export function isGoldRingsMuted(): boolean {+ return sessionStorage.getItem(optOutKey) === 'true'+}++function playGoldRings(): void {+ goldRingsAudio ??= new Audio('/static/sounds/five-gold-rings.mp3')+ goldRingsAudio.pause()+ goldRingsAudio.currentTime = 0+ goldRingsAudio.volume = 0.5+ void goldRingsAudio.play().catch(() => undefined)+}++export function listenForGoldRingsKeys(isEnabled: () => boolean): () => void {+ let progress = 0+ let lastKeyAt = 0++ const trackOptOutKey = (key: string): boolean => {+ if (key === ' ') {+ return false+ }++ const now = Date.now()+ progress = now - lastKeyAt > sequenceTimeoutMs ? 0 : progress+ lastKeyAt = now+ const normalizedKey = key.toLowerCase()+ progress = normalizedKey === optOutPhrase[progress] ? progress + 1 : normalizedKey === optOutPhrase[0] ? 1 : 0++ if (progress === optOutPhrase.length) {+ sessionStorage.setItem(optOutKey, 'true')+ goldRingsAudio?.pause()+ progress = 0+ return true+ }+ return false+ }++ const onKeyDown = (event: KeyboardEvent): void => {+ if (!isEnabled() || isGoldRingsMuted() || !isPlainKey(event)) {+ return+ }+ if (event.target instanceof HTMLInputElement && event.target.type === 'password') {+ return+ }+ if (trackOptOutKey(event.key)) {+ return+ }++ if (event.key === '5') {+ playGoldRings()+ }+ }++ window.addEventListener('keydown', onKeyDown)+ return () => window.removeEventListener('keydown', onKeyDown)+}diff --git a/frontend/src/scenes/sceneLogic.test.tsx b/frontend/src/scenes/sceneLogic.test.tsxindex 55d22e6623e7..4e92aa6f3550 100644--- a/frontend/src/scenes/sceneLogic.test.tsx+++ b/frontend/src/scenes/sceneLogic.test.tsx@@ -117,6 +117,32 @@ describe('sceneLogic', () => {})})+ it('plays when 5 is pressed after the holiday flag arrives', () => {+ jest.useFakeTimers()+ jest.setSystemTime(new Date(2026, 9, 22))+ const play = jest.spyOn(HTMLMediaElement.prototype, 'play').mockResolvedValue()+ const pause = jest.spyOn(HTMLMediaElement.prototype, 'pause').mockImplementation()+ let playsBeforeFlag = 0+ let playsAfterFlag = 0++ try {+ window.dispatchEvent(new KeyboardEvent('keydown', { key: '5' }))+ playsBeforeFlag = play.mock.calls.length++ featureFlagLogic.actions.setFeatureFlags([FEATURE_FLAGS.CHRISTMAS_GOLD_RINGS], {+ [FEATURE_FLAGS.CHRISTMAS_GOLD_RINGS]: true,+ })+ window.dispatchEvent(new KeyboardEvent('keydown', { key: '5' }))+ playsAfterFlag = play.mock.calls.length+ } finally {+ play.mockRestore()+ pause.mockRestore()+ jest.useRealTimers()+ }+ expect(playsBeforeFlag).toBe(0)+ expect(playsAfterFlag).toBe(1)+ })+// A scene that never mounts must not leave the address bar on it with the previous scene still// rendered, and must leave something error tracking can count.describe('a scene that fails to load', () => {diff --git a/frontend/src/scenes/sceneLogic.tsx b/frontend/src/scenes/sceneLogic.tsxindex 03a16d2df349..05f5f071400e 100644--- a/frontend/src/scenes/sceneLogic.tsx+++ b/frontend/src/scenes/sceneLogic.tsx@@ -19,6 +19,7 @@ import { useEffect, useState } from 'react'import api from 'lib/api'import type { SupportTicketExceptionEvent } from 'lib/components/Support/supportLogic'import { FEATURE_FLAGS, TeamMembershipLevel } from 'lib/constants'+import { listenForGoldRingsKeys } from 'lib/holidayGoldRings'import { trackFileSystemLogView } from 'lib/hooks/useFileSystemLogView'import { lemonToast } from 'lib/lemon-ui/LemonToast/LemonToast'import { Spinner } from 'lib/lemon-ui/Spinner'@@ -456,6 +457,11 @@ export const sceneLogic = kea<sceneLogicType>([cache.lastTrackedScene = null as { sceneId?: string; sceneKey?: string } | nullcache.homepageSave = Promise.resolve()cache.homepageRequest = 0+ cache.disposables.add(() =>+ listenForGoldRingsKeys(+ () => featureFlagLogic.values.featureFlags[FEATURE_FLAGS.CHRISTMAS_GOLD_RINGS] === true+ )+ )}),actions({/* 1. Prepares to open the scene, as the listener may override and do something