Skip to content

Commit

Permalink
fix: count variant metrics based on enabled state (#131)
Browse files Browse the repository at this point in the history
  • Loading branch information
FredrikOseberg committed Dec 22, 2022
1 parent 0ca4603 commit d5f0c74
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions src/index.ts
Expand Up @@ -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);
}
Expand All @@ -211,15 +211,15 @@ 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,
enabled,
toggleName,
IMPRESSION_EVENTS.GET_VARIANT,
toggle?.impressionData ?? undefined,
variant.name,
variant.name
);
this.emit(EVENTS.IMPRESSION, event);
}
Expand All @@ -243,9 +243,8 @@ export class UnleashClient extends TinyEmitter {

if (this.timerRef) {
await this.fetchToggles();
}
else {
await new Promise<void>(resolve => {
} else {
await new Promise<void>((resolve) => {
const listener = () => {
this.fetchToggles().then(() => {
this.off(EVENTS.READY, listener);
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit d5f0c74

Please sign in to comment.