Merge pull request #15677 from Budibase/fix/disable-session-recording
Disable Posthog session recording
This commit is contained in:
commit
b96a85ee11
|
@ -1,9 +1,12 @@
|
||||||
import posthog from "posthog-js"
|
import posthog from "posthog-js"
|
||||||
import { Events } from "./constants"
|
|
||||||
|
|
||||||
export default class PosthogClient {
|
export default class PosthogClient {
|
||||||
constructor(token) {
|
token: string
|
||||||
|
initialised: boolean
|
||||||
|
|
||||||
|
constructor(token: string) {
|
||||||
this.token = token
|
this.token = token
|
||||||
|
this.initialised = false
|
||||||
}
|
}
|
||||||
|
|
||||||
init() {
|
init() {
|
||||||
|
@ -12,6 +15,8 @@ export default class PosthogClient {
|
||||||
posthog.init(this.token, {
|
posthog.init(this.token, {
|
||||||
autocapture: false,
|
autocapture: false,
|
||||||
capture_pageview: false,
|
capture_pageview: false,
|
||||||
|
// disable by default
|
||||||
|
disable_session_recording: true,
|
||||||
})
|
})
|
||||||
posthog.set_config({ persistence: "cookie" })
|
posthog.set_config({ persistence: "cookie" })
|
||||||
|
|
||||||
|
@ -22,7 +27,7 @@ export default class PosthogClient {
|
||||||
* Set the posthog context to the current user
|
* Set the posthog context to the current user
|
||||||
* @param {String} id - unique user id
|
* @param {String} id - unique user id
|
||||||
*/
|
*/
|
||||||
identify(id) {
|
identify(id: string) {
|
||||||
if (!this.initialised) return
|
if (!this.initialised) return
|
||||||
|
|
||||||
posthog.identify(id)
|
posthog.identify(id)
|
||||||
|
@ -32,7 +37,7 @@ export default class PosthogClient {
|
||||||
* Update user metadata associated with current user in posthog
|
* Update user metadata associated with current user in posthog
|
||||||
* @param {Object} meta - user fields
|
* @param {Object} meta - user fields
|
||||||
*/
|
*/
|
||||||
updateUser(meta) {
|
updateUser(meta: Record<string, any>) {
|
||||||
if (!this.initialised) return
|
if (!this.initialised) return
|
||||||
|
|
||||||
posthog.people.set(meta)
|
posthog.people.set(meta)
|
||||||
|
@ -43,28 +48,22 @@ export default class PosthogClient {
|
||||||
* @param {String} event - event identifier
|
* @param {String} event - event identifier
|
||||||
* @param {Object} props - properties for the event
|
* @param {Object} props - properties for the event
|
||||||
*/
|
*/
|
||||||
captureEvent(eventName, props) {
|
captureEvent(event: string, props: Record<string, any>) {
|
||||||
if (!this.initialised) return
|
if (!this.initialised) {
|
||||||
|
return
|
||||||
props.sourceApp = "builder"
|
|
||||||
posthog.capture(eventName, props)
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Submit NPS feedback to posthog.
|
|
||||||
* @param {Object} values - NPS Values
|
|
||||||
*/
|
|
||||||
npsFeedback(values) {
|
|
||||||
if (!this.initialised) return
|
|
||||||
|
|
||||||
localStorage.setItem(Events.NPS.SUBMITTED, Date.now())
|
|
||||||
|
|
||||||
const prefixedFeedback = {}
|
|
||||||
for (let key in values) {
|
|
||||||
prefixedFeedback[`feedback_${key}`] = values[key]
|
|
||||||
}
|
}
|
||||||
|
|
||||||
posthog.capture(Events.NPS.SUBMITTED, prefixedFeedback)
|
props.sourceApp = "builder"
|
||||||
|
posthog.capture(event, props)
|
||||||
|
}
|
||||||
|
|
||||||
|
enableSessionRecording() {
|
||||||
|
if (!this.initialised) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
posthog.set_config({
|
||||||
|
disable_session_recording: false,
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
|
@ -31,6 +31,10 @@ class AnalyticsHub {
|
||||||
posthog.captureEvent(eventName, props)
|
posthog.captureEvent(eventName, props)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
enableSessionRecording() {
|
||||||
|
posthog.enableSessionRecording()
|
||||||
|
}
|
||||||
|
|
||||||
async logout() {
|
async logout() {
|
||||||
posthog.logout()
|
posthog.logout()
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,6 +8,7 @@ import {
|
||||||
SystemStatusResponse,
|
SystemStatusResponse,
|
||||||
} from "@budibase/types"
|
} from "@budibase/types"
|
||||||
import { BudiStore } from "../BudiStore"
|
import { BudiStore } from "../BudiStore"
|
||||||
|
import Analytics from "../../analytics"
|
||||||
|
|
||||||
interface AdminState extends GetEnvironmentResponse {
|
interface AdminState extends GetEnvironmentResponse {
|
||||||
loaded: boolean
|
loaded: boolean
|
||||||
|
@ -33,6 +34,8 @@ export class AdminStore extends BudiStore<AdminState> {
|
||||||
await this.getEnvironment()
|
await this.getEnvironment()
|
||||||
// enable system status checks in the cloud
|
// enable system status checks in the cloud
|
||||||
if (get(this.store).cloud) {
|
if (get(this.store).cloud) {
|
||||||
|
// in cloud allow this
|
||||||
|
Analytics.enableSessionRecording()
|
||||||
await this.getSystemStatus()
|
await this.getSystemStatus()
|
||||||
this.checkStatus()
|
this.checkStatus()
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue