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 { 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
} }
} }