Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: count variant metrics based on enabled state #131

Merged
merged 1 commit into from Dec 22, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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);
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line is the important change.

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