|
|
@ -20,24 +20,31 @@ export default class PosthogClient { |
|
|
this.initialised = true |
|
|
this.initialised = true |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* Set the posthog context to the current user |
|
|
|
|
|
* @param {String} id - unique user id |
|
|
|
|
|
*/ |
|
|
identify(id) { |
|
|
identify(id) { |
|
|
if (!this.initialised) return |
|
|
if (!this.initialised) return |
|
|
|
|
|
|
|
|
posthog.identify(id) |
|
|
posthog.identify(id) |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* Update user metadata associated with current user in posthog |
|
|
|
|
|
* @param {Object} meta - user fields |
|
|
|
|
|
*/ |
|
|
updateUser(meta) { |
|
|
updateUser(meta) { |
|
|
if (!this.initialised) return |
|
|
if (!this.initialised) return |
|
|
|
|
|
|
|
|
posthog.people.set(meta) |
|
|
posthog.people.set(meta) |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
captureException(err) { |
|
|
/** |
|
|
if (!this.initialised) return |
|
|
* Capture analytics events and send them to posthog. |
|
|
|
|
|
* @param {String} event - event identifier |
|
|
this.captureEvent("Error", { error: err.message ? err.message : err }) |
|
|
* @param {Object} props - properties for the event |
|
|
} |
|
|
*/ |
|
|
|
|
|
|
|
|
captureEvent(eventName, props) { |
|
|
captureEvent(eventName, props) { |
|
|
if (!this.initialised) return |
|
|
if (!this.initialised) return |
|
|
|
|
|
|
|
|
@ -45,6 +52,10 @@ export default class PosthogClient { |
|
|
posthog.capture(eventName, props) |
|
|
posthog.capture(eventName, props) |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* Submit NPS feedback to posthog. |
|
|
|
|
|
* @param {Object} values - NPS Values |
|
|
|
|
|
*/ |
|
|
npsFeedback(values) { |
|
|
npsFeedback(values) { |
|
|
if (!this.initialised) return |
|
|
if (!this.initialised) return |
|
|
|
|
|
|
|
|
@ -58,6 +69,9 @@ export default class PosthogClient { |
|
|
posthog.capture(Events.NPS.SUBMITTED, prefixedFeedback) |
|
|
posthog.capture(Events.NPS.SUBMITTED, prefixedFeedback) |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* Reset posthog user back to initial state on logout. |
|
|
|
|
|
*/ |
|
|
logout() { |
|
|
logout() { |
|
|
if (!this.initialised) return |
|
|
if (!this.initialised) return |
|
|
|
|
|
|
|
|
|