Skip to content

Commit

Permalink
$active_feature_flags should filter non active flags (#73)
Browse files Browse the repository at this point in the history
  • Loading branch information
marandaneto authored Oct 6, 2023
1 parent aab0004 commit 95bf057
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
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

0 comments on commit 95bf057

Please sign in to comment.