flagsmith
flagsmith copied to clipboard
Segment rules should be able to operate on Identity IDs
Currently segment rule definitions can only be run against Identity traits. Users often expect the rules to operate on Identity ids as well.
We should introduce a reserved trait name, suggest id, which evaluates to the Identity unique identifier when the rules are being evaluated.
Technical Implementation
We can add the id transiently to the segment list with a special name e.g. id or similar before processing the rules.
Issues
It would mean that SDKs could not set a trait with id which would be a breaking change. What would happen to existing traits that have an ID set? Suggest that if they do, this overrides the coercion of the id.
We should have a special prefix for internal traits like this, one thing that was originally planned was automated traits such as device, browser. Doing so would also allow for this.
e.g $FS_id, $FS_browser
We should also consider adding date / time based values like: $FS_currentday, $FS_currenthour, $FS_currentminute. This would allow people to use segment overrides to create recurring schedules for their flags.
This has been implemented in https://github.com/Flagsmith/flagsmith-engine/pull/198 with the '$_' prefix for external values.
Now that I think of it, I'm in favour of adopting OpenAPI's reference syntax for local references, e.g.:
#/identity/identifier#/event/datetime#/contexts/company/address/postalCode