Skip to content

Commit

Permalink
Simpler
Browse files Browse the repository at this point in the history
  • Loading branch information
pauldambra committed Nov 13, 2024
1 parent 64cde82 commit 7aa7765
Showing 1 changed file with 18 additions and 21 deletions.
39 changes: 18 additions & 21 deletions src/posthog-core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ import { uuidv7 } from './uuidv7'
import { Survey, SurveyCallback, SurveyQuestionBranchingType } from './posthog-surveys-types'
import {
isArray,
isBoolean,
isEmptyObject,
isEmptyString,
isFunction,
Expand Down Expand Up @@ -1821,37 +1820,35 @@ export class PostHog {
startSessionRecording(
override?: { sampling?: boolean; linked_flag?: boolean; url_trigger?: true; event_trigger?: true } | true
): void {
const overrideAll = isBoolean(override) && override
if (
overrideAll ||
override?.sampling ||
override?.linked_flag ||
override?.url_trigger ||
override?.event_trigger
) {
const overrideAll = override === true
const overrideConfig = {
sampling: overrideAll || !!override?.sampling,
linked_flag: overrideAll || !!override?.linked_flag,
url_trigger: overrideAll || !!override?.url_trigger,
event_trigger: overrideAll || !!override?.event_trigger,
}

if (Object.values(overrideConfig).some(Boolean)) {
// allow the session id check to rotate session id if necessary
const ids = this.sessionManager?.checkAndGetSessionAndWindowId()
let msg = 'Session recording with id "' + ids?.sessionId + '" started'
this.sessionManager?.checkAndGetSessionAndWindowId()

if (overrideAll || override?.sampling) {
if (overrideConfig.sampling) {
this.sessionRecording?.overrideSampling()
msg += ' with sampling override'
}
if (overrideAll || override?.linked_flag) {

if (overrideConfig.linked_flag) {
this.sessionRecording?.overrideLinkedFlag()
msg += ' with linked_flag override'
}
if (overrideAll || override?.url_trigger) {

if (overrideConfig.url_trigger) {
this.sessionRecording?.overrideTrigger('url')
msg += ' with url_trigger override'
}
if (overrideAll || override?.event_trigger) {

if (overrideConfig.event_trigger) {
this.sessionRecording?.overrideTrigger('event')
msg += ' with event_trigger override'
}

logger.info(msg)
}

this.set_config({ disable_session_recording: false })
}

Expand Down

0 comments on commit 7aa7765

Please sign in to comment.