feat(audience-consent): add CanTrack and CanIdentify predicates on ConsentLevel (SDK-226)#698
Merged
Merged
Conversation
…nsentLevel (SDK-226)
Centralise the consent rules behind two extension predicates and adopt
them at every internal gate site that previously inlined the rule.
ConsentLevelExtensions stays internal: same convention as
IdentityTypeExtensions, no external caller today, and a future PR can
promote when one lands.
Predicates:
CanTrack returns level != None.
Fail-open on out-of-range casts so an unrecognised value
still tracks, matching the gate shape every other call
site already uses.
CanIdentify returns level == Full.
Fail-closed on out-of-range casts. Identify and Alias
must not leak PII under uncertain consent.
Adoption:
ImmutableAudience.cs (5 sites): Identify gate, Alias gate, the
private static CanTrack body, Enqueue's drain-time recheck closure,
FireGameLaunch early return.
Identity.cs (1 site): GetOrCreate's null-on-no-consent guard.
Test coverage in Tests/Runtime/ConsentLevelTests.cs pins each enum
value against both predicates plus the out-of-range cast for both
fail policies, so a future change that flips either default breaks
the build loudly.
SDK-143 originally scoped the full consent infrastructure (state
machine, persistence, side effects, server sync, gates). The state
machine, persistence, side effects, and server sync shipped under
SDK-119, SDK-142, and SDK-147. SDK-226 was carved out for the
remaining slice this commit delivers.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
3ae963f to
8dfbfa0
Compare
nattb8
approved these changes
Apr 22, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
ConsentLevel.CanTrack()andConsentLevel.CanIdentify()extension predicates as the single source of truth for the SDK's consent gates.ImmutableAudience.cs, one inIdentity.cs).ConsentLevelExtensionsstaysinternal, matching the convention used byIdentityTypeExtensions.Tests/Runtime/ConsentLevelTests.cspins each enum value plus the out-of-range cast against both predicates.Linear:
Identify/Aliasrequire Full,Trackrequires Anonymous+