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 all 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: 2 additions & 1 deletion cypress/e2e/billing.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,17 @@ 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.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]
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
68 changes: 37 additions & 31 deletions frontend/src/loadPostHogJS.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,41 +17,46 @@ const configWithSentry = (config: Partial<PostHogConfig>): Partial<PostHogConfig
}

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',
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) {
Expand All @@ -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) {
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