From d5f0c7435280f15f8e2adcd6fd2592819fe8b9ec Mon Sep 17 00:00:00 2001 From: Fredrik Strand Oseberg Date: Thu, 22 Dec 2022 10:35:03 +0100 Subject: [PATCH] fix: count variant metrics based on enabled state (#131) --- src/index.ts | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/src/index.ts b/src/index.ts index 1e66c7e..deb65e4 100644 --- a/src/index.ts +++ b/src/index.ts @@ -198,7 +198,7 @@ export class UnleashClient extends TinyEmitter { enabled, toggleName, IMPRESSION_EVENTS.IS_ENABLED, - toggle?.impressionData ?? undefined, + toggle?.impressionData ?? undefined ); this.emit(EVENTS.IMPRESSION, event); } @@ -211,7 +211,7 @@ export class UnleashClient extends TinyEmitter { const enabled = toggle?.enabled || false; const variant = toggle ? toggle.variant : defaultVariant; - this.metrics.count(toggleName, true); + this.metrics.count(toggleName, enabled); if (toggle?.impressionData || this.impressionDataAll) { const event = this.eventsHandler.createImpressionEvent( this.context, @@ -219,7 +219,7 @@ export class UnleashClient extends TinyEmitter { toggleName, IMPRESSION_EVENTS.GET_VARIANT, toggle?.impressionData ?? undefined, - variant.name, + variant.name ); this.emit(EVENTS.IMPRESSION, event); } @@ -243,9 +243,8 @@ export class UnleashClient extends TinyEmitter { if (this.timerRef) { await this.fetchToggles(); - } - else { - await new Promise(resolve => { + } else { + await new Promise((resolve) => { const listener = () => { this.fetchToggles().then(() => { this.off(EVENTS.READY, listener); @@ -353,9 +352,13 @@ export class UnleashClient extends TinyEmitter { try { const isPOST = this.usePOSTrequests; - const url = isPOST ? this.url : urlWithContextAsQuery(this.url, this.context); + const url = isPOST + ? this.url + : urlWithContextAsQuery(this.url, this.context); const method = isPOST ? 'POST' : 'GET'; - const body = isPOST ? JSON.stringify({context: this.context}) : undefined; + const body = isPOST + ? JSON.stringify({ context: this.context }) + : undefined; const response = await this.fetch(url.toString(), { method,