This commit is contained in:
Martin McKeaveney 2021-09-21 20:28:33 +01:00
parent b4f9fd4f12
commit a00598ce38
3 changed files with 52 additions and 8 deletions

View File

@ -3,6 +3,9 @@ export default class IntercomClient {
this.token = token this.token = token
} }
/**
* Instantiate intercom using their provided script.
*/
init() { init() {
if (!this.token) return if (!this.token) return
@ -43,6 +46,11 @@ export default class IntercomClient {
} }
} }
/**
* Show the intercom chat bubble.
* @param {Object} user - user to identify
* @returns Intercom global object
*/
show(user = {}) { show(user = {}) {
if (!this.initialised) return if (!this.initialised) return
@ -52,21 +60,35 @@ export default class IntercomClient {
}) })
} }
/**
* Update intercom user details and messages.
* @returns Intercom global object
*/
update() { update() {
if (!this.initialised) return if (!this.initialised) return
return window.Intercom("update") return window.Intercom("update")
} }
/**
* Capture analytics events and send them to intercom.
* @param {String} event - event identifier
* @param {Object} props - properties for the event
* @returns Intercom global object
*/
captureEvent(event, props = {}) { captureEvent(event, props = {}) {
if (!this.initialised) return if (!this.initialised) return
window.Intercom("trackEvent", event, props) return window.Intercom("trackEvent", event, props)
} }
/**
* Disassociate the user from the current session.
* @returns Intercom global object
*/
logout() { logout() {
if (!this.initialised) return if (!this.initialised) return
window.Intercom("shutdown") return window.Intercom("shutdown")
} }
} }

View File

@ -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

View File

@ -13,12 +13,20 @@ export default class SentryClient {
} }
} }
/**
* Capture an exception and send it to sentry.
* @param {Error} err - JS error object
*/
captureException(err) { captureException(err) {
if (!this.initalised) return if (!this.initalised) return
Sentry.captureException(err) Sentry.captureException(err)
} }
/**
* Identify user in sentry.
* @param {String} id - Unique user id
*/
identify(id) { identify(id) {
if (!this.initalised) return if (!this.initalised) return