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

$active_feature_flags should filter non active flags #73

Merged
merged 6 commits into from
Oct 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
## Next

- Update device type [#63](https://github.com/PostHog/posthog-ios/pull/63)
- `$active_feature_flags` event should filter non active flags ([#41](https://github.com/PostHog/posthog-android/pull/41))

## 2.0.4 - 2023-10-05

Expand Down
22 changes: 20 additions & 2 deletions PostHog/Internal/PHGPostHogIntegration.m
Original file line number Diff line number Diff line change
Expand Up @@ -235,18 +235,36 @@ - (NSDictionary *)liveContext
}

context[@"$groups"] = [self getGroups];
context[@"$active_feature_flags"] = [self getFeatureFlags];

NSDictionary *flagsAndValues = [self getFeatureFlagsAndValues];

NSMutableArray *activeFlags = [NSMutableArray array];
int n = 0;
for(id flag in flagsAndValues){
NSString *key = [NSString stringWithFormat:@"$feature/%@", flag];
// $active_feature_flags__x is legacy and likely not used anymore
NSString *enumeratedKey = [NSString stringWithFormat:@"$active_feature_flags__%d", n];
context[key] = [flagsAndValues objectForKey:flag];

id value = [flagsAndValues valueForKey:flag];

context[key] = value;
context[enumeratedKey] = flag;

// only add active feature flags
// a flag is only inactive if its a boolean: false
bool isActive = YES;
if ([value isKindOfClass:[NSNumber class]]) {
isActive = [value boolValue];
}
if (isActive) {
[activeFlags addObject:key];
}

n++;
}
if ([activeFlags count] > 0) {
[context setObject:activeFlags forKey:@"$active_feature_flags"];
}

#if TARGET_OS_IOS
static dispatch_once_t networkInfoOnceToken;
Expand Down