Skip to content

Commit

Permalink
more bundle size changes
Browse files Browse the repository at this point in the history
  • Loading branch information
lucasheriques committed Jan 21, 2025
1 parent 118c8ac commit 564d8bb
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 4 deletions.
5 changes: 3 additions & 2 deletions src/entrypoints/surveys.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import { generateSurveys } from '../extensions/surveys'
import { generateSurveys, getNextSurveyStep } from '../extensions/surveys'

import { assignableWindow } from '../utils/globals'
import { canActivateRepeatedly } from '../extensions/surveys/surveys-utils'
import { assignableWindow } from '../utils/globals'

assignableWindow.__PosthogExtensions__ = assignableWindow.__PosthogExtensions__ || {}
assignableWindow.__PosthogExtensions__.canActivateRepeatedly = canActivateRepeatedly
assignableWindow.__PosthogExtensions__.generateSurveys = generateSurveys
assignableWindow.__PosthogExtensions__.getNextSurveyStep = getNextSurveyStep

// this used to be directly on window, but we moved it to __PosthogExtensions__
// it is still on window for backwards compatibility
Expand Down
9 changes: 7 additions & 2 deletions src/posthog-surveys.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { SURVEYS } from './constants'
import { getNextSurveyStep } from './extensions/surveys'
import { getSurveySeenStorageKeys } from './extensions/surveys/surveys-utils'
import { PostHog } from './posthog-core'
import { Survey, SurveyCallback, SurveyUrlMatchType } from './posthog-surveys-types'
Expand Down Expand Up @@ -194,7 +193,13 @@ export class PostHogSurveys {
return this.instance.featureFlags.isFeatureEnabled(value)
})
}
getNextSurveyStep = getNextSurveyStep
getNextSurveyStep(survey: Survey, currentQuestionIndex: number, response: string | string[] | number | null) {
if (isNullish(assignableWindow.__PosthogExtensions__?.getNextSurveyStep)) {
logger.warn('init was not called')
return 0
}
return assignableWindow.__PosthogExtensions__.getNextSurveyStep(survey, currentQuestionIndex, response)
}

// this method is lazily loaded onto the window to avoid loading preact and other dependencies if surveys is not enabled
private _canActivateRepeatedly(survey: Survey) {
Expand Down
6 changes: 6 additions & 0 deletions src/utils/globals.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { ErrorProperties } from '../extensions/exception-autocapture/error-conversion'
import type { PostHog } from '../posthog-core'
import { SurveyQuestionBranchingType } from '../posthog-surveys-types'
import { SessionIdManager } from '../sessionid'
import {
DeadClicksAutoCaptureConfig,
Expand Down Expand Up @@ -78,6 +79,11 @@ interface PostHogExtensions {
rrwebPlugins?: { getRecordConsolePlugin: any; getRecordNetworkPlugin?: any }
canActivateRepeatedly?: (survey: any) => boolean
generateSurveys?: (posthog: PostHog) => any | undefined
getNextSurveyStep?: (
survey: any,
currentQuestionIndex: number,
response: string | string[] | number | null
) => number | SurveyQuestionBranchingType.End
postHogWebVitalsCallbacks?: {
onLCP: (metric: any) => void
onCLS: (metric: any) => void
Expand Down

0 comments on commit 564d8bb

Please sign in to comment.