Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(deps): Update posthog-js to 1.158.1 #24578

Closed
wants to merge 19 commits into from
Closed
Show file tree
Hide file tree
Changes from 16 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions cypress/e2e/billing.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,18 @@ 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()
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', 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)
Expand Down
1 change: 1 addition & 0 deletions cypress/e2e/billingUpgradeCTA.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions cypress/support/e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
cy.spy(win.console, 'error')
cy.spy(win.console, 'warn')

win.console.warn('SETTING _CYPRESS_POSTHOG_CAPTURES BEFORE LOAD')
win._cypress_posthog_captures = []
})

Expand All @@ -44,6 +45,7 @@

// 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([]))

Check failure

Code scanning / CodeQL

Incomplete regular expression for hostnames High

This regular expression has an unescaped '.' before 'posthog.com', so it might match more hosts than expected.
cy.intercept('https://www.gravatar.com/avatar/**', (req) =>
req.reply({ statusCode: 404, body: 'Cypress forced 404' })
)
Expand Down
98 changes: 68 additions & 30 deletions frontend/src/loadPostHogJS.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,40 +17,77 @@
}

export function loadPostHogJS(): void {
window.console.warn('LOADING POSTHOG')
if (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
}
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',
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: (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
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)

Check failure on line 90 in frontend/src/loadPostHogJS.tsx

View workflow job for this annotation

GitHub Actions / Code quality checks

Property '_cypress_posthog_captures' does not exist on type 'Window & typeof globalThis'.

const Cypress = (window as any).Cypress

Expand All @@ -72,6 +109,7 @@
// 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) {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
14 changes: 7 additions & 7 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading