From e5a33c108c88126dabfbd3465827d22815518a3a Mon Sep 17 00:00:00 2001 From: posthog-bot Date: Mon, 26 Aug 2024 15:11:49 +0000 Subject: [PATCH 01/19] chore(deps): Update posthog-js to 1.158.1 --- package.json | 2 +- pnpm-lock.yaml | 14 +++++++------- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/package.json b/package.json index 0619355e0d131..7982e7c075666 100644 --- a/package.json +++ b/package.json @@ -148,7 +148,7 @@ "pmtiles": "^2.11.0", "postcss": "^8.4.31", "postcss-preset-env": "^9.3.0", - "posthog-js": "1.157.1", + "posthog-js": "1.158.1", "posthog-js-lite": "3.0.0", "prettier": "^2.8.8", "prop-types": "^15.7.2", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 91662790d6810..346b44e94bb11 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -266,8 +266,8 @@ dependencies: specifier: ^9.3.0 version: 9.3.0(postcss@8.4.31) posthog-js: - specifier: 1.157.1 - version: 1.157.1 + specifier: 1.158.1 + version: 1.158.1 posthog-js-lite: specifier: 3.0.0 version: 3.0.0 @@ -15393,7 +15393,7 @@ packages: image-size: 0.5.5 make-dir: 2.1.0 mime: 1.6.0 - native-request: 1.1.0 + native-request: 1.1.2 source-map: 0.6.1 dev: true @@ -16124,8 +16124,8 @@ packages: engines: {node: ^10 || ^12 || ^13.7 || ^14 || >=15.0.1} hasBin: true - /native-request@1.1.0: - resolution: {integrity: sha512-uZ5rQaeRn15XmpgE0xoPL8YWqcX90VtCFglYwAgkvKM5e8fog+vePLAhHxuuv/gRkrQxIeh5U3q9sMNUrENqWw==} + /native-request@1.1.2: + resolution: {integrity: sha512-/etjwrK0J4Ebbcnt35VMWnfiUX/B04uwGJxyJInagxDqf2z5drSt/lsOvEMWGYunz1kaLZAFrV4NDAbOoDKvAQ==} requiresBuild: true dev: true optional: true @@ -17668,8 +17668,8 @@ packages: resolution: {integrity: sha512-dyajjnfzZD1tht4N7p7iwf7nBnR1MjVaVu+MKr+7gBgA39bn28wizCIJZztZPtHy4PY0YwtSGgwfBCuG/hnHgA==} dev: false - /posthog-js@1.157.1: - resolution: {integrity: sha512-K9TWFrz9PI2e1AMhgfwp1/0eMHdP2DwcHhOsTawlSsj03keUvtybWWiOW36xmrhJzE1HcvlYpfYvpTnbr6MQqA==} + /posthog-js@1.158.1: + resolution: {integrity: sha512-BRCZUpkZTsNPTTclpqv6tB9aGD9OH1Lh+3SZdqo/JMbPesKRQ2XSis6WhxWmujrTZDfdJtVa7tnQG1aT2Ag4Yg==} dependencies: fflate: 0.4.8 preact: 10.23.2 From 1017808d350c9b0e77c00a3f2a28e599db5e7ad9 Mon Sep 17 00:00:00 2001 From: Raquel Smith Date: Mon, 26 Aug 2024 16:40:15 -0700 Subject: [PATCH 02/19] add some logging, force the function --- cypress/e2e/billing.cy.ts | 1 + cypress/support/e2e.ts | 1 + frontend/src/loadPostHogJS.tsx | 5 ++--- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/cypress/e2e/billing.cy.ts b/cypress/e2e/billing.cy.ts index a21188c0f42d0..8f81ca07a63eb 100644 --- a/cypress/e2e/billing.cy.ts +++ b/cypress/e2e/billing.cy.ts @@ -20,6 +20,7 @@ describe('Billing', () => { cy.contains('.LemonModal .LemonButton', 'Unsubscribe').click() cy.window().then((win) => { + win.console.warn('_CYPRESS_POSTHOG_CAPTURES', (win as any)._cypress_posthog_captures) const events = (win as any)._cypress_posthog_captures const matchingEvents = events.filter((event) => event.event === 'survey sent') expect(matchingEvents.length).to.equal(1) diff --git a/cypress/support/e2e.ts b/cypress/support/e2e.ts index f2fad98287005..a01a69b3d23e0 100644 --- a/cypress/support/e2e.ts +++ b/cypress/support/e2e.ts @@ -20,6 +20,7 @@ Cypress.on('window:before:load', (win) => { cy.spy(win.console, 'error') cy.spy(win.console, 'warn') + win.console.warn('SETTING _CYPRESS_POSTHOG_CAPTURES') win._cypress_posthog_captures = [] }) diff --git a/frontend/src/loadPostHogJS.tsx b/frontend/src/loadPostHogJS.tsx index e0307ab977635..233bb79b99fa2 100644 --- a/frontend/src/loadPostHogJS.tsx +++ b/frontend/src/loadPostHogJS.tsx @@ -17,6 +17,7 @@ const configWithSentry = (config: Partial): Partial (window as any)._cypress_posthog_captures.push(event) - : undefined, + _onCapture: (_, event) => (window as any)._cypress_posthog_captures.push(event), }) ) From 6cd8655c09240c83674966381444f8260cf0ac20 Mon Sep 17 00:00:00 2001 From: Raquel Smith Date: Mon, 26 Aug 2024 18:25:30 -0700 Subject: [PATCH 03/19] moar debug --- cypress/e2e/billing.cy.ts | 23 ++++++++++++----------- frontend/src/loadPostHogJS.tsx | 1 + 2 files changed, 13 insertions(+), 11 deletions(-) diff --git a/cypress/e2e/billing.cy.ts b/cypress/e2e/billing.cy.ts index 8f81ca07a63eb..23c09ae06905d 100644 --- a/cypress/e2e/billing.cy.ts +++ b/cypress/e2e/billing.cy.ts @@ -8,18 +8,19 @@ describe('Billing', () => { }) it('Show and submit unsubscribe survey', () => { - cy.intercept('/api/billing/deactivate?products=product_analytics', { - fixture: 'api/billing/billing-unsubscribed-product-analytics.json', - }).as('unsubscribeProductAnalytics') - - cy.get('[data-attr=more-button]').first().click() - cy.contains('.LemonButton', 'Unsubscribe').click() - cy.get('.LemonModal h3').should('contain', 'Unsubscribe from Product analytics') - cy.get('[data-attr=unsubscribe-reason-too-expensive]').click() - cy.get('[data-attr=unsubscribe-reason-survey-textarea]').type('Product analytics') - cy.contains('.LemonModal .LemonButton', 'Unsubscribe').click() - cy.window().then((win) => { + cy.intercept('/api/billing/deactivate?products=product_analytics', { + fixture: 'api/billing/billing-unsubscribed-product-analytics.json', + }).as('unsubscribeProductAnalytics') + cy.visit('/organization/billing') + + cy.get('[data-attr=more-button]').first().click() + cy.contains('.LemonButton', 'Unsubscribe').click() + cy.get('.LemonModal h3').should('contain', 'Unsubscribe from Product analytics') + cy.get('[data-attr=unsubscribe-reason-too-expensive]').click() + cy.get('[data-attr=unsubscribe-reason-survey-textarea]').type('Product analytics') + cy.contains('.LemonModal .LemonButton', 'Unsubscribe').click() + win.console.warn('_CYPRESS_POSTHOG_CAPTURES', (win as any)._cypress_posthog_captures) const events = (win as any)._cypress_posthog_captures const matchingEvents = events.filter((event) => event.event === 'survey sent') diff --git a/frontend/src/loadPostHogJS.tsx b/frontend/src/loadPostHogJS.tsx index 233bb79b99fa2..7227587694c6d 100644 --- a/frontend/src/loadPostHogJS.tsx +++ b/frontend/src/loadPostHogJS.tsx @@ -17,6 +17,7 @@ const configWithSentry = (config: Partial): Partial Date: Mon, 26 Aug 2024 18:57:44 -0700 Subject: [PATCH 04/19] try --- frontend/src/loadPostHogJS.tsx | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/frontend/src/loadPostHogJS.tsx b/frontend/src/loadPostHogJS.tsx index 7227587694c6d..c866d779448c1 100644 --- a/frontend/src/loadPostHogJS.tsx +++ b/frontend/src/loadPostHogJS.tsx @@ -17,8 +17,6 @@ const configWithSentry = (config: Partial): Partial (window as any)._cypress_posthog_captures.push(event), + _onCapture: (_, event) => { + ;(window as any).console.warn( + '_CYPRESS_POSTHOG_CAPTURES', + (window as any)._cypress_posthog_captures + ) + ;(window as any).console.warn('_CYPRESS_POSTHOG_CAPTURES EVENT', event) + + // if not exist, initialize as empty array + ;(window as any)._cypress_posthog_captures = (window as any)._cypress_posthog_captures || [] + ;(window as any)._cypress_posthog_captures.push(event) + }, }) ) From 1c2a7553428d55de9a8e7ca76ef06a55b368346f Mon Sep 17 00:00:00 2001 From: Raquel Smith Date: Mon, 26 Aug 2024 19:23:31 -0700 Subject: [PATCH 05/19] more logging... --- cypress/e2e/billing.cy.ts | 25 +++++++++++++------------ cypress/support/e2e.ts | 2 +- frontend/src/loadPostHogJS.tsx | 7 +++++++ 3 files changed, 21 insertions(+), 13 deletions(-) diff --git a/cypress/e2e/billing.cy.ts b/cypress/e2e/billing.cy.ts index 23c09ae06905d..456d85be4504f 100644 --- a/cypress/e2e/billing.cy.ts +++ b/cypress/e2e/billing.cy.ts @@ -8,19 +8,20 @@ describe('Billing', () => { }) it('Show and submit unsubscribe survey', () => { - cy.window().then((win) => { - cy.intercept('/api/billing/deactivate?products=product_analytics', { - fixture: 'api/billing/billing-unsubscribed-product-analytics.json', - }).as('unsubscribeProductAnalytics') - cy.visit('/organization/billing') - - cy.get('[data-attr=more-button]').first().click() - cy.contains('.LemonButton', 'Unsubscribe').click() - cy.get('.LemonModal h3').should('contain', 'Unsubscribe from Product analytics') - cy.get('[data-attr=unsubscribe-reason-too-expensive]').click() - cy.get('[data-attr=unsubscribe-reason-survey-textarea]').type('Product analytics') - cy.contains('.LemonModal .LemonButton', 'Unsubscribe').click() + cy.intercept('/api/billing/deactivate?products=product_analytics', { + fixture: 'api/billing/billing-unsubscribed-product-analytics.json', + }).as('unsubscribeProductAnalytics') + cy.visit('/organization/billing') + + cy.get('[data-attr=more-button]').first().click() + cy.contains('.LemonButton', 'Unsubscribe').click() + cy.get('.LemonModal h3').should('contain', 'Unsubscribe from Product analytics') + cy.get('[data-attr=unsubscribe-reason-too-expensive]').click() + cy.get('[data-attr=unsubscribe-reason-survey-textarea]').type('Product analytics') + cy.contains('.LemonModal .LemonButton', 'Unsubscribe').click() + cy.wait(5000) // Wait 5 seconds + cy.window().then((win) => { win.console.warn('_CYPRESS_POSTHOG_CAPTURES', (win as any)._cypress_posthog_captures) const events = (win as any)._cypress_posthog_captures const matchingEvents = events.filter((event) => event.event === 'survey sent') diff --git a/cypress/support/e2e.ts b/cypress/support/e2e.ts index a01a69b3d23e0..4ef30e61c6ad4 100644 --- a/cypress/support/e2e.ts +++ b/cypress/support/e2e.ts @@ -20,7 +20,7 @@ Cypress.on('window:before:load', (win) => { cy.spy(win.console, 'error') cy.spy(win.console, 'warn') - win.console.warn('SETTING _CYPRESS_POSTHOG_CAPTURES') + win.console.warn('SETTING _CYPRESS_POSTHOG_CAPTURES BEFORE LOAD') win._cypress_posthog_captures = [] }) diff --git a/frontend/src/loadPostHogJS.tsx b/frontend/src/loadPostHogJS.tsx index c866d779448c1..b83ac0fb884a7 100644 --- a/frontend/src/loadPostHogJS.tsx +++ b/frontend/src/loadPostHogJS.tsx @@ -17,7 +17,9 @@ const configWithSentry = (config: Partial): Partial Date: Tue, 27 Aug 2024 12:24:24 -0500 Subject: [PATCH 06/19] enable debug logging for cypress aciotn --- .github/workflows/ci-e2e.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/ci-e2e.yml b/.github/workflows/ci-e2e.yml index eaa95507163b5..40a5f0d2b7d35 100644 --- a/.github/workflows/ci-e2e.yml +++ b/.github/workflows/ci-e2e.yml @@ -234,6 +234,8 @@ jobs: env: E2E_TESTING: 1 OPT_OUT_CAPTURE: 0 + ACTIONS_STEP_DEBUG: true + DEBUG: 'cypress:*' GITHUB_ACTION_RUN_URL: '${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}' - name: Archive test screenshots From 4996dd3042d343aa49520e1c5486b4fc9d3a7b41 Mon Sep 17 00:00:00 2001 From: Raquel Smith Date: Tue, 27 Aug 2024 11:09:38 -0700 Subject: [PATCH 07/19] add more debug --- frontend/src/loadPostHogJS.tsx | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/frontend/src/loadPostHogJS.tsx b/frontend/src/loadPostHogJS.tsx index b83ac0fb884a7..7a1503126b93c 100644 --- a/frontend/src/loadPostHogJS.tsx +++ b/frontend/src/loadPostHogJS.tsx @@ -64,7 +64,14 @@ export function loadPostHogJS(): void { }) ) window.posthog?.capture('capturing posthog event') - window.console.warn('POSTHOG LOADED, EVENT CAPTURED') + window.console.warn('POSTHOG LOADED, STANDARD EVENT CAPTURED') + window.posthog?._onCapture('capturing posthog event', { + uuid: '01919505-3a07-7404-b4de-1877b907e539', + event: 'capturing posthog event', + properties: {}, + }) + window.console.warn('POSTHOG LOADED, EVENT CAPTURED VIA _ONCAPTURE DIRECTLY') + window.console.warn('WHAT IS IN _CYPRESS_POSTHOG_CAPTURES', window._cypress_posthog_captures) const Cypress = (window as any).Cypress From 3d18d178f64038df43cf649733b0eefb0b98f2a7 Mon Sep 17 00:00:00 2001 From: Phani Raj Date: Tue, 27 Aug 2024 13:34:43 -0500 Subject: [PATCH 08/19] pick out config so we can inspect the _onCapture event handler --- frontend/src/loadPostHogJS.tsx | 100 +++++++++++++++++++-------------- 1 file changed, 57 insertions(+), 43 deletions(-) diff --git a/frontend/src/loadPostHogJS.tsx b/frontend/src/loadPostHogJS.tsx index 7a1503126b93c..041aeb0e991cc 100644 --- a/frontend/src/loadPostHogJS.tsx +++ b/frontend/src/loadPostHogJS.tsx @@ -20,56 +20,70 @@ export function loadPostHogJS(): void { window.console.warn('LOADING POSTHOG') if (window.JS_POSTHOG_API_KEY) { window.console.warn('LOADING POSTHOG WITH KEY', window.JS_POSTHOG_API_KEY) - posthog.init( - window.JS_POSTHOG_API_KEY, - configWithSentry({ - api_host: window.JS_POSTHOG_HOST, - ui_host: window.JS_POSTHOG_UI_HOST, - rageclick: true, - persistence: 'localStorage+cookie', - bootstrap: window.POSTHOG_USER_IDENTITY_WITH_FLAGS ? window.POSTHOG_USER_IDENTITY_WITH_FLAGS : {}, - opt_in_site_apps: true, - api_transport: 'fetch', - loaded: (posthog) => { - if (posthog.sessionRecording) { - posthog.sessionRecording._forceAllowLocalhostNetworkCapture = true - } + const config = configWithSentry({ + api_host: window.JS_POSTHOG_HOST, + ui_host: window.JS_POSTHOG_UI_HOST, + rageclick: true, + persistence: 'localStorage+cookie', + bootstrap: window.POSTHOG_USER_IDENTITY_WITH_FLAGS ? window.POSTHOG_USER_IDENTITY_WITH_FLAGS : {}, + opt_in_site_apps: true, + api_transport: 'fetch', + loaded: (posthog) => { + if (posthog.sessionRecording) { + posthog.sessionRecording._forceAllowLocalhostNetworkCapture = true + } - if (window.IMPERSONATED_SESSION) { - window.console.warn('IMPERSONATING SESSION', window.IMPERSONATED_SESSION) - posthog.opt_out_capturing() - } else { - window.console.warn('OPTING IN CAPTURING') - posthog.opt_in_capturing() - } - }, - scroll_root_selector: ['main', 'html'], - autocapture: { - capture_copied_text: true, - }, - person_profiles: 'always', + if (window.IMPERSONATED_SESSION) { + window.console.warn('IMPERSONATING SESSION', window.IMPERSONATED_SESSION) + posthog.opt_out_capturing() + } else { + window.console.warn('OPTING IN CAPTURING') + posthog.opt_in_capturing() + } + }, + scroll_root_selector: ['main', 'html'], + autocapture: { + capture_copied_text: true, + }, + person_profiles: 'always', - // Helper to capture events for assertions in Cypress - _onCapture: (_, event) => { - ;(window as any).console.warn( + // Helper to capture events for assertions in Cypress + _onCapture: (event, eventPayload) => { + ;(window as any).console + .warn( '_CYPRESS_POSTHOG_CAPTURES', (window as any)._cypress_posthog_captures - ) - ;(window as any).console.warn('_CYPRESS_POSTHOG_CAPTURES EVENT', event) - + )(window as any) + .console.warn( + '_CYPRESS_POSTHOG_CAPTURES EVENT', + event + )(window as any) + .console.warn( + '_CYPRESS_POSTHOG_CAPTURES EVENT Data', + eventPayload + )( // if not exist, initialize as empty array - ;(window as any)._cypress_posthog_captures = (window as any)._cypress_posthog_captures || [] - ;(window as any)._cypress_posthog_captures.push(event) - }, - }) - ) + window as any + )._cypress_posthog_captures = + (window as any)._cypress_posthog_captures || + [](window as any)._cypress_posthog_captures.push(eventPayload) + }, + }) + + window.console.warn('POSTHOG CONFIG _onCapture is ,', config._onCapture) + + posthog.init(window.JS_POSTHOG_API_KEY, config) window.posthog?.capture('capturing posthog event') window.console.warn('POSTHOG LOADED, STANDARD EVENT CAPTURED') - window.posthog?._onCapture('capturing posthog event', { - uuid: '01919505-3a07-7404-b4de-1877b907e539', - event: 'capturing posthog event', - properties: {}, - }) + if (config._onCapture) { + config._onCapture('capturing posthog event', { + uuid: '01919505-3a07-7404-b4de-1877b907e539', + event: 'capturing posthog event', + properties: {}, + }) + } else { + window.console.warn('POSTHOG CONFIG _onCapture is undefined, cannot be called') + } window.console.warn('POSTHOG LOADED, EVENT CAPTURED VIA _ONCAPTURE DIRECTLY') window.console.warn('WHAT IS IN _CYPRESS_POSTHOG_CAPTURES', window._cypress_posthog_captures) From 696de4cac31cb387bbbe1f0378928f8875df323f Mon Sep 17 00:00:00 2001 From: Phani Raj Date: Tue, 27 Aug 2024 14:03:44 -0500 Subject: [PATCH 09/19] format sources --- frontend/src/loadPostHogJS.tsx | 27 ++++++++------------------- 1 file changed, 8 insertions(+), 19 deletions(-) diff --git a/frontend/src/loadPostHogJS.tsx b/frontend/src/loadPostHogJS.tsx index 041aeb0e991cc..39afcd5e5f95e 100644 --- a/frontend/src/loadPostHogJS.tsx +++ b/frontend/src/loadPostHogJS.tsx @@ -49,28 +49,17 @@ export function loadPostHogJS(): void { // Helper to capture events for assertions in Cypress _onCapture: (event, eventPayload) => { - ;(window as any).console - .warn( - '_CYPRESS_POSTHOG_CAPTURES', - (window as any)._cypress_posthog_captures - )(window as any) - .console.warn( - '_CYPRESS_POSTHOG_CAPTURES EVENT', - event - )(window as any) - .console.warn( - '_CYPRESS_POSTHOG_CAPTURES EVENT Data', - eventPayload - )( - // if not exist, initialize as empty array - window as any - )._cypress_posthog_captures = - (window as any)._cypress_posthog_captures || - [](window as any)._cypress_posthog_captures.push(eventPayload) + ;(window as any).console.warn('_CYPRESS_POSTHOG_CAPTURES', (window as any)._cypress_posthog_captures) + ;(window as any).console.warn('_CYPRESS_POSTHOG_CAPTURES EVENT', event) + ;(window as any).console.warn('_CYPRESS_POSTHOG_CAPTURES EVENT Data', eventPayload) + + // if not exist, initialize as empty array + ;(window as any)._cypress_posthog_captures = (window as any)._cypress_posthog_captures || [] + ;(window as any)._cypress_posthog_captures.push(eventPayload) }, }) - window.console.warn('POSTHOG CONFIG _onCapture is ,', config._onCapture) + window.console.warn('POSTHOG CONFIG _onCapture is ,', config._onCapture?.toString()) posthog.init(window.JS_POSTHOG_API_KEY, config) window.posthog?.capture('capturing posthog event') From 4a1d5fa87aa6dc97a928e18811f0894f8327ecbd Mon Sep 17 00:00:00 2001 From: Phani Raj Date: Tue, 27 Aug 2024 14:34:38 -0500 Subject: [PATCH 10/19] disable all access to window variables in handler --- frontend/src/loadPostHogJS.tsx | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/frontend/src/loadPostHogJS.tsx b/frontend/src/loadPostHogJS.tsx index 39afcd5e5f95e..0b36ed1f4a28d 100644 --- a/frontend/src/loadPostHogJS.tsx +++ b/frontend/src/loadPostHogJS.tsx @@ -49,13 +49,19 @@ export function loadPostHogJS(): void { // Helper to capture events for assertions in Cypress _onCapture: (event, eventPayload) => { - ;(window as any).console.warn('_CYPRESS_POSTHOG_CAPTURES', (window as any)._cypress_posthog_captures) - ;(window as any).console.warn('_CYPRESS_POSTHOG_CAPTURES EVENT', event) - ;(window as any).console.warn('_CYPRESS_POSTHOG_CAPTURES EVENT Data', eventPayload) - - // if not exist, initialize as empty array - ;(window as any)._cypress_posthog_captures = (window as any)._cypress_posthog_captures || [] - ;(window as any)._cypress_posthog_captures.push(eventPayload) + ;(window as any).console.warn( + 'DEBUG_CYPRESS_TEST_FAILURE in event handler, a NOOP , event is ', + event, + ` payload is `, + eventPayload + ) + // ;(window as any).console.warn('in event handler _CYPRESS_POSTHOG_CAPTURES', (window as any)._cypress_posthog_captures) + // ;(window as any).console.warn('in event handler _CYPRESS_POSTHOG_CAPTURES EVENT', event) + // ;(window as any).console.warn('in event handler _CYPRESS_POSTHOG_CAPTURES EVENT Data', eventPayload) + // + // // if not exist, initialize as empty array + // ;(window as any)._cypress_posthog_captures = (window as any)._cypress_posthog_captures || [] + // ;(window as any)._cypress_posthog_captures.push(eventPayload) }, }) From 0af6c1d7f08e760aa2d84f5aca7630c5a043e079 Mon Sep 17 00:00:00 2001 From: Phani Raj Date: Tue, 27 Aug 2024 15:13:35 -0500 Subject: [PATCH 11/19] try to bring back assignment to window properties --- frontend/src/loadPostHogJS.tsx | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/frontend/src/loadPostHogJS.tsx b/frontend/src/loadPostHogJS.tsx index 0b36ed1f4a28d..c3c6b082416ae 100644 --- a/frontend/src/loadPostHogJS.tsx +++ b/frontend/src/loadPostHogJS.tsx @@ -49,23 +49,26 @@ export function loadPostHogJS(): void { // Helper to capture events for assertions in Cypress _onCapture: (event, eventPayload) => { - ;(window as any).console.warn( - 'DEBUG_CYPRESS_TEST_FAILURE in event handler, a NOOP , event is ', - event, - ` payload is `, - eventPayload - ) // ;(window as any).console.warn('in event handler _CYPRESS_POSTHOG_CAPTURES', (window as any)._cypress_posthog_captures) // ;(window as any).console.warn('in event handler _CYPRESS_POSTHOG_CAPTURES EVENT', event) // ;(window as any).console.warn('in event handler _CYPRESS_POSTHOG_CAPTURES EVENT Data', eventPayload) // - // // if not exist, initialize as empty array - // ;(window as any)._cypress_posthog_captures = (window as any)._cypress_posthog_captures || [] - // ;(window as any)._cypress_posthog_captures.push(eventPayload) + // if not exist, initialize as empty array + const captures = (window as any)._cypress_posthog_captures || [] + captures.push(eventPayload) + ;(window as any).console.warn( + ' POST_DEBUG_CYPRESS_TEST_FAILURE in event handler, a NOOP , event is ', + event, + ` payload is `, + eventPayload, + ` captures is `, + captures + ) + ;(window as any)._cypress_posthog_captures = captures }, }) - window.console.warn('POSTHOG CONFIG _onCapture is ,', config._onCapture?.toString()) + // window.console.warn('POSTHOG CONFIG _onCapture is ,', config._onCapture?.toString()) posthog.init(window.JS_POSTHOG_API_KEY, config) window.posthog?.capture('capturing posthog event') From f57f37f5801b1c20112e34c020522677a7d59b8a Mon Sep 17 00:00:00 2001 From: Phani Raj Date: Tue, 27 Aug 2024 15:35:00 -0500 Subject: [PATCH 12/19] remove debugging settings --- .github/workflows/ci-e2e.yml | 2 -- 1 file changed, 2 deletions(-) diff --git a/.github/workflows/ci-e2e.yml b/.github/workflows/ci-e2e.yml index 40a5f0d2b7d35..eaa95507163b5 100644 --- a/.github/workflows/ci-e2e.yml +++ b/.github/workflows/ci-e2e.yml @@ -234,8 +234,6 @@ jobs: env: E2E_TESTING: 1 OPT_OUT_CAPTURE: 0 - ACTIONS_STEP_DEBUG: true - DEBUG: 'cypress:*' GITHUB_ACTION_RUN_URL: '${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}' - name: Archive test screenshots From 8a17b9c7c22585356e7320f03abe93edfabc8913 Mon Sep 17 00:00:00 2001 From: Phani Raj Date: Tue, 27 Aug 2024 15:54:36 -0500 Subject: [PATCH 13/19] stringify objects in log --- cypress/e2e/billing.cy.ts | 2 +- cypress/e2e/billingUpgradeCTA.cy.ts | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/cypress/e2e/billing.cy.ts b/cypress/e2e/billing.cy.ts index 456d85be4504f..9989b7f980422 100644 --- a/cypress/e2e/billing.cy.ts +++ b/cypress/e2e/billing.cy.ts @@ -22,7 +22,7 @@ describe('Billing', () => { cy.wait(5000) // Wait 5 seconds cy.window().then((win) => { - win.console.warn('_CYPRESS_POSTHOG_CAPTURES', (win as any)._cypress_posthog_captures) + win.console.warn('_CYPRESS_POSTHOG_CAPTURES', JSON.stringify((win as any)._cypress_posthog_captures)) const events = (win as any)._cypress_posthog_captures const matchingEvents = events.filter((event) => event.event === 'survey sent') expect(matchingEvents.length).to.equal(1) diff --git a/cypress/e2e/billingUpgradeCTA.cy.ts b/cypress/e2e/billingUpgradeCTA.cy.ts index 17d26463a3350..6d22e7ad62385 100644 --- a/cypress/e2e/billingUpgradeCTA.cy.ts +++ b/cypress/e2e/billingUpgradeCTA.cy.ts @@ -10,6 +10,7 @@ describe('Billing Upgrade CTA', () => { cy.get('[data-attr=billing-page-core-upgrade-cta] .LemonButton__content').should('have.text', 'Upgrade now') cy.window().then((win) => { const events = (win as any)._cypress_posthog_captures + win.console.warn('_CYPRESS_POSTHOG_CAPTURES', JSON.stringify(events)) const matchingEvents = events.filter((event) => event.event === 'billing CTA shown') // One for each product card From f813443822e300172b2aad67f573a30f9f63d22e Mon Sep 17 00:00:00 2001 From: Phani Raj Date: Tue, 27 Aug 2024 16:26:05 -0500 Subject: [PATCH 14/19] try to use _addCaptureHook --- .github/workflows/ci-e2e.yml | 1 + frontend/src/loadPostHogJS.tsx | 6 +++++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ci-e2e.yml b/.github/workflows/ci-e2e.yml index eaa95507163b5..40b0fb7240bca 100644 --- a/.github/workflows/ci-e2e.yml +++ b/.github/workflows/ci-e2e.yml @@ -234,6 +234,7 @@ jobs: env: E2E_TESTING: 1 OPT_OUT_CAPTURE: 0 + DEBUG: 'cypress:*' GITHUB_ACTION_RUN_URL: '${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}' - name: Archive test screenshots diff --git a/frontend/src/loadPostHogJS.tsx b/frontend/src/loadPostHogJS.tsx index c3c6b082416ae..3fb846de1061d 100644 --- a/frontend/src/loadPostHogJS.tsx +++ b/frontend/src/loadPostHogJS.tsx @@ -70,7 +70,11 @@ export function loadPostHogJS(): void { // window.console.warn('POSTHOG CONFIG _onCapture is ,', config._onCapture?.toString()) - posthog.init(window.JS_POSTHOG_API_KEY, config) + const instance = posthog.init(window.JS_POSTHOG_API_KEY, config) + instance?._addCaptureHook((event, payload) => { + ;(window as any).console.warn('DEBUG: _addCaptureHook :: event is ', event, ' payload is ', payload) + }) + window.posthog?.capture('capturing posthog event') window.console.warn('POSTHOG LOADED, STANDARD EVENT CAPTURED') if (config._onCapture) { From 1a18c6902aadf1137664b84e34de4edd58d701b6 Mon Sep 17 00:00:00 2001 From: Phani Raj Date: Tue, 27 Aug 2024 16:47:31 -0500 Subject: [PATCH 15/19] move back to v1.157.1 --- .github/workflows/ci-e2e.yml | 1 - package.json | 2 +- pnpm-lock.yaml | 8 ++++---- 3 files changed, 5 insertions(+), 6 deletions(-) diff --git a/.github/workflows/ci-e2e.yml b/.github/workflows/ci-e2e.yml index 40b0fb7240bca..eaa95507163b5 100644 --- a/.github/workflows/ci-e2e.yml +++ b/.github/workflows/ci-e2e.yml @@ -234,7 +234,6 @@ jobs: env: E2E_TESTING: 1 OPT_OUT_CAPTURE: 0 - DEBUG: 'cypress:*' GITHUB_ACTION_RUN_URL: '${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}' - name: Archive test screenshots diff --git a/package.json b/package.json index 7982e7c075666..0619355e0d131 100644 --- a/package.json +++ b/package.json @@ -148,7 +148,7 @@ "pmtiles": "^2.11.0", "postcss": "^8.4.31", "postcss-preset-env": "^9.3.0", - "posthog-js": "1.158.1", + "posthog-js": "1.157.1", "posthog-js-lite": "3.0.0", "prettier": "^2.8.8", "prop-types": "^15.7.2", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 346b44e94bb11..05824fed1e22c 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -266,8 +266,8 @@ dependencies: specifier: ^9.3.0 version: 9.3.0(postcss@8.4.31) posthog-js: - specifier: 1.158.1 - version: 1.158.1 + specifier: 1.157.1 + version: 1.157.1 posthog-js-lite: specifier: 3.0.0 version: 3.0.0 @@ -17668,8 +17668,8 @@ packages: resolution: {integrity: sha512-dyajjnfzZD1tht4N7p7iwf7nBnR1MjVaVu+MKr+7gBgA39bn28wizCIJZztZPtHy4PY0YwtSGgwfBCuG/hnHgA==} dev: false - /posthog-js@1.158.1: - resolution: {integrity: sha512-BRCZUpkZTsNPTTclpqv6tB9aGD9OH1Lh+3SZdqo/JMbPesKRQ2XSis6WhxWmujrTZDfdJtVa7tnQG1aT2Ag4Yg==} + /posthog-js@1.157.1: + resolution: {integrity: sha512-K9TWFrz9PI2e1AMhgfwp1/0eMHdP2DwcHhOsTawlSsj03keUvtybWWiOW36xmrhJzE1HcvlYpfYvpTnbr6MQqA==} dependencies: fflate: 0.4.8 preact: 10.23.2 From 21e7782c5fc6f2c312c89ab9858c976e4f06c1ec Mon Sep 17 00:00:00 2001 From: Phani Raj Date: Tue, 27 Aug 2024 17:23:02 -0500 Subject: [PATCH 16/19] prevent spinner since JS library uses a different host now --- cypress/support/e2e.ts | 1 + package.json | 2 +- pnpm-lock.yaml | 8 ++++---- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/cypress/support/e2e.ts b/cypress/support/e2e.ts index 4ef30e61c6ad4..c65e2195ca4da 100644 --- a/cypress/support/e2e.ts +++ b/cypress/support/e2e.ts @@ -45,6 +45,7 @@ beforeEach(() => { // un-intercepted sometimes this doesn't work and the page gets stuck on the SpinnerOverlay cy.intercept(/app.posthog.com\/api\/projects\/@current\/feature_flags\/my_flags.*/, (req) => req.reply([])) + cy.intercept(/us.i.posthog.com\/api\/projects\/@current\/feature_flags\/my_flags.*/, (req) => req.reply([])) cy.intercept('https://www.gravatar.com/avatar/**', (req) => req.reply({ statusCode: 404, body: 'Cypress forced 404' }) ) diff --git a/package.json b/package.json index 0619355e0d131..7982e7c075666 100644 --- a/package.json +++ b/package.json @@ -148,7 +148,7 @@ "pmtiles": "^2.11.0", "postcss": "^8.4.31", "postcss-preset-env": "^9.3.0", - "posthog-js": "1.157.1", + "posthog-js": "1.158.1", "posthog-js-lite": "3.0.0", "prettier": "^2.8.8", "prop-types": "^15.7.2", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 05824fed1e22c..346b44e94bb11 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -266,8 +266,8 @@ dependencies: specifier: ^9.3.0 version: 9.3.0(postcss@8.4.31) posthog-js: - specifier: 1.157.1 - version: 1.157.1 + specifier: 1.158.1 + version: 1.158.1 posthog-js-lite: specifier: 3.0.0 version: 3.0.0 @@ -17668,8 +17668,8 @@ packages: resolution: {integrity: sha512-dyajjnfzZD1tht4N7p7iwf7nBnR1MjVaVu+MKr+7gBgA39bn28wizCIJZztZPtHy4PY0YwtSGgwfBCuG/hnHgA==} dev: false - /posthog-js@1.157.1: - resolution: {integrity: sha512-K9TWFrz9PI2e1AMhgfwp1/0eMHdP2DwcHhOsTawlSsj03keUvtybWWiOW36xmrhJzE1HcvlYpfYvpTnbr6MQqA==} + /posthog-js@1.158.1: + resolution: {integrity: sha512-BRCZUpkZTsNPTTclpqv6tB9aGD9OH1Lh+3SZdqo/JMbPesKRQ2XSis6WhxWmujrTZDfdJtVa7tnQG1aT2Ag4Yg==} dependencies: fflate: 0.4.8 preact: 10.23.2 From 3a6f926a4dfbfe720ef8cad5b83b4956554f280a Mon Sep 17 00:00:00 2001 From: Phani Raj Date: Tue, 27 Aug 2024 20:57:13 -0500 Subject: [PATCH 17/19] Set opt_out_useragent_filter to true --- frontend/src/loadPostHogJS.tsx | 1 + 1 file changed, 1 insertion(+) diff --git a/frontend/src/loadPostHogJS.tsx b/frontend/src/loadPostHogJS.tsx index 3fb846de1061d..6b05190abfa65 100644 --- a/frontend/src/loadPostHogJS.tsx +++ b/frontend/src/loadPostHogJS.tsx @@ -25,6 +25,7 @@ export function loadPostHogJS(): void { ui_host: window.JS_POSTHOG_UI_HOST, rageclick: true, persistence: 'localStorage+cookie', + opt_out_useragent_filter: true, bootstrap: window.POSTHOG_USER_IDENTITY_WITH_FLAGS ? window.POSTHOG_USER_IDENTITY_WITH_FLAGS : {}, opt_in_site_apps: true, api_transport: 'fetch', From 9266595c17b1f9dff04454b1b24bfe712946f535 Mon Sep 17 00:00:00 2001 From: Phani Raj Date: Tue, 27 Aug 2024 21:42:15 -0500 Subject: [PATCH 18/19] remove debugging code --- cypress/e2e/billing.cy.ts | 2 +- frontend/src/loadPostHogJS.tsx | 37 ++-------------------------------- 2 files changed, 3 insertions(+), 36 deletions(-) diff --git a/cypress/e2e/billing.cy.ts b/cypress/e2e/billing.cy.ts index 9989b7f980422..e6824583d9418 100644 --- a/cypress/e2e/billing.cy.ts +++ b/cypress/e2e/billing.cy.ts @@ -22,8 +22,8 @@ describe('Billing', () => { cy.wait(5000) // Wait 5 seconds cy.window().then((win) => { - win.console.warn('_CYPRESS_POSTHOG_CAPTURES', JSON.stringify((win as any)._cypress_posthog_captures)) const events = (win as any)._cypress_posthog_captures + win.console.warn('_CYPRESS_POSTHOG_CAPTURES', JSON.stringify(events)) const matchingEvents = events.filter((event) => event.event === 'survey sent') expect(matchingEvents.length).to.equal(1) const matchingEvent = matchingEvents[0] diff --git a/frontend/src/loadPostHogJS.tsx b/frontend/src/loadPostHogJS.tsx index 6b05190abfa65..0f114c3f608ea 100644 --- a/frontend/src/loadPostHogJS.tsx +++ b/frontend/src/loadPostHogJS.tsx @@ -49,47 +49,14 @@ export function loadPostHogJS(): void { person_profiles: 'always', // Helper to capture events for assertions in Cypress - _onCapture: (event, eventPayload) => { - // ;(window as any).console.warn('in event handler _CYPRESS_POSTHOG_CAPTURES', (window as any)._cypress_posthog_captures) - // ;(window as any).console.warn('in event handler _CYPRESS_POSTHOG_CAPTURES EVENT', event) - // ;(window as any).console.warn('in event handler _CYPRESS_POSTHOG_CAPTURES EVENT Data', eventPayload) - // - // if not exist, initialize as empty array + _onCapture: (_, eventPayload) => { const captures = (window as any)._cypress_posthog_captures || [] captures.push(eventPayload) - ;(window as any).console.warn( - ' POST_DEBUG_CYPRESS_TEST_FAILURE in event handler, a NOOP , event is ', - event, - ` payload is `, - eventPayload, - ` captures is `, - captures - ) ;(window as any)._cypress_posthog_captures = captures }, }) - // window.console.warn('POSTHOG CONFIG _onCapture is ,', config._onCapture?.toString()) - - const instance = posthog.init(window.JS_POSTHOG_API_KEY, config) - instance?._addCaptureHook((event, payload) => { - ;(window as any).console.warn('DEBUG: _addCaptureHook :: event is ', event, ' payload is ', payload) - }) - - window.posthog?.capture('capturing posthog event') - window.console.warn('POSTHOG LOADED, STANDARD EVENT CAPTURED') - if (config._onCapture) { - config._onCapture('capturing posthog event', { - uuid: '01919505-3a07-7404-b4de-1877b907e539', - event: 'capturing posthog event', - properties: {}, - }) - } else { - window.console.warn('POSTHOG CONFIG _onCapture is undefined, cannot be called') - } - window.console.warn('POSTHOG LOADED, EVENT CAPTURED VIA _ONCAPTURE DIRECTLY') - window.console.warn('WHAT IS IN _CYPRESS_POSTHOG_CAPTURES', window._cypress_posthog_captures) - + posthog.init(window.JS_POSTHOG_API_KEY, config) const Cypress = (window as any).Cypress if (Cypress) { From 525888db1c9c0b204aa1e13cb871d1c9e3a02ec1 Mon Sep 17 00:00:00 2001 From: Phani Raj Date: Wed, 28 Aug 2024 07:25:21 -0500 Subject: [PATCH 19/19] remove sleep --- cypress/e2e/billing.cy.ts | 2 -- 1 file changed, 2 deletions(-) diff --git a/cypress/e2e/billing.cy.ts b/cypress/e2e/billing.cy.ts index e6824583d9418..891256be529a6 100644 --- a/cypress/e2e/billing.cy.ts +++ b/cypress/e2e/billing.cy.ts @@ -19,8 +19,6 @@ describe('Billing', () => { cy.get('[data-attr=unsubscribe-reason-too-expensive]').click() cy.get('[data-attr=unsubscribe-reason-survey-textarea]').type('Product analytics') cy.contains('.LemonModal .LemonButton', 'Unsubscribe').click() - cy.wait(5000) // Wait 5 seconds - cy.window().then((win) => { const events = (win as any)._cypress_posthog_captures win.console.warn('_CYPRESS_POSTHOG_CAPTURES', JSON.stringify(events))