diff --git a/cypress/e2e/billing.cy.ts b/cypress/e2e/billing.cy.ts index a21188c0f42d0..891256be529a6 100644 --- a/cypress/e2e/billing.cy.ts +++ b/cypress/e2e/billing.cy.ts @@ -11,6 +11,7 @@ describe('Billing', () => { 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() @@ -18,9 +19,9 @@ 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.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 === 'survey sent') expect(matchingEvents.length).to.equal(1) const matchingEvent = matchingEvents[0] 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 diff --git a/cypress/support/e2e.ts b/cypress/support/e2e.ts index f2fad98287005..c65e2195ca4da 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 BEFORE LOAD') win._cypress_posthog_captures = [] }) @@ -44,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/frontend/src/loadPostHogJS.tsx b/frontend/src/loadPostHogJS.tsx index e0307ab977635..0f114c3f608ea 100644 --- a/frontend/src/loadPostHogJS.tsx +++ b/frontend/src/loadPostHogJS.tsx @@ -17,41 +17,46 @@ const configWithSentry = (config: Partial): Partial { - if (posthog.sessionRecording) { - posthog.sessionRecording._forceAllowLocalhostNetworkCapture = true - } + window.console.warn('LOADING POSTHOG WITH KEY', window.JS_POSTHOG_API_KEY) + const config = configWithSentry({ + api_host: window.JS_POSTHOG_HOST, + 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', + loaded: (posthog) => { + if (posthog.sessionRecording) { + posthog.sessionRecording._forceAllowLocalhostNetworkCapture = true + } - if (window.IMPERSONATED_SESSION) { - posthog.opt_out_capturing() - } else { - 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: (window as any)._cypress_posthog_captures - ? (_, event) => (window as any)._cypress_posthog_captures.push(event) - : undefined, - }) - ) + // Helper to capture events for assertions in Cypress + _onCapture: (_, eventPayload) => { + const captures = (window as any)._cypress_posthog_captures || [] + captures.push(eventPayload) + ;(window as any)._cypress_posthog_captures = captures + }, + }) + posthog.init(window.JS_POSTHOG_API_KEY, config) const Cypress = (window as any).Cypress if (Cypress) { @@ -72,6 +77,7 @@ export function loadPostHogJS(): void { // Make sure we have access to the object in window for debugging window.posthog = posthog } else { + window.console.warn('POSTHOG NOT LOADED') posthog.init('fake token', { autocapture: false, loaded: function (ph) { 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