Added in init flag to ensure that analytic clients only init once
This commit is contained in:
parent
9da5467bfe
commit
86c6922bf4
|
@ -9,13 +9,17 @@ const intercom = new IntercomClient(process.env.INTERCOM_TOKEN)
|
||||||
class AnalyticsHub {
|
class AnalyticsHub {
|
||||||
constructor() {
|
constructor() {
|
||||||
this.clients = [posthog, intercom]
|
this.clients = [posthog, intercom]
|
||||||
|
this.initialised = false
|
||||||
}
|
}
|
||||||
|
|
||||||
async activate() {
|
async activate() {
|
||||||
// Check analytics are enabled
|
// Check analytics are enabled
|
||||||
const analyticsStatus = await API.getAnalyticsStatus()
|
const analyticsStatus = await API.getAnalyticsStatus()
|
||||||
if (analyticsStatus.enabled) {
|
if (analyticsStatus.enabled && !this.initialised) {
|
||||||
this.clients.forEach(client => client.init())
|
this.clients.forEach(client => {
|
||||||
|
client.init()
|
||||||
|
})
|
||||||
|
this.initialised = true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue