Added in init flag to ensure that analytic clients only init once

This commit is contained in:
Dean 2024-02-15 15:25:07 +00:00
parent 9da5467bfe
commit 86c6922bf4
1 changed files with 6 additions and 2 deletions

View File

@ -9,13 +9,17 @@ const intercom = new IntercomClient(process.env.INTERCOM_TOKEN)
class AnalyticsHub {
constructor() {
this.clients = [posthog, intercom]
this.initialised = false
}
async activate() {
// Check analytics are enabled
const analyticsStatus = await API.getAnalyticsStatus()
if (analyticsStatus.enabled) {
this.clients.forEach(client => client.init())
if (analyticsStatus.enabled && !this.initialised) {
this.clients.forEach(client => {
client.init()
})
this.initialised = true
}
}