Skip to content

feat(audience-env): explicit dev/sandbox/production selection#709

Merged
ImmutableJeffrey merged 1 commit intofeat/sdk-146-unityfrom
feat/audience-env
Apr 26, 2026
Merged

feat(audience-env): explicit dev/sandbox/production selection#709
ImmutableJeffrey merged 1 commit intofeat/sdk-146-unityfrom
feat/audience-env

Conversation

@ImmutableJeffrey
Copy link
Copy Markdown
Collaborator

@ImmutableJeffrey ImmutableJeffrey commented Apr 24, 2026

Summary

  • Adds AudienceEnvironment enum: Dev, Sandbox, Production.
  • Adds AudienceConfig.Environment field, default Sandbox.
  • Constants.BaseUrl / MessagesUrl / ConsentUrl / DataUrl take an AudienceEnvironment; the publishable-key parameter on these helpers is removed.
  • Adds Constants.DevBaseUrl; removes Constants.ResolveEnvironment and Constants.TestKeyPrefix.
  • HttpTransport constructor takes an AudienceEnvironment (default Sandbox); key-prefix URL derivation removed.
  • ImmutableAudience.Init wires config.Environment into HttpTransport; DeleteData and SetConsent thread it into their control-plane URLs.
  • Adds ImmutableAudience.CurrentEnvironment public getter; caches the last Init's env so the value survives Shutdown; ResetState restores the Sandbox default.

Behaviour change: integrations using a production-prefixed key that left Environment unset previously hit production via key-prefix detection. They now hit Sandbox until Environment = Production is set explicitly. Test-key integrations already hit Sandbox and are unaffected.

Linear: SDK-244.

Comment thread src/Packages/Audience/Runtime/Core/Constants.cs Outdated
Comment thread src/Packages/Audience/Runtime/AudienceEnvironment.cs Outdated
Base automatically changed from feat/audience-diagnostics to feat/sdk-146-unity April 24, 2026 04:49
@nattb8 nattb8 marked this pull request as ready for review April 24, 2026 04:52
@nattb8 nattb8 requested review from a team as code owners April 24, 2026 04:52
ImmutableJeffrey added a commit that referenced this pull request Apr 24, 2026
Addresses review feedback on #709 from @nattb8: avoid exposing a public
enum of environments and match the Web/Pixel SDK pattern.

Problems with the enum:
- Makes Dev a first-class, permanently-supported public choice that
  cannot be removed later without a breaking change.
- Forces every future backend addition onto the public enum surface.
- Diverges from @imtbl/audience, which has no enum.

This commit undoes the enum wiring and restores the key-prefix URL
derivation that existed before the PR. A follow-up commit adds an
optional BaseUrl override on AudienceConfig (Web SDK parity) so devs
who need Dev can point the SDK there directly.

- Delete AudienceEnvironment.cs.
- Constants: restore TestKeyPrefix and the
  MessagesUrl/ConsentUrl/DataUrl(string?) signatures.
- AudienceConfig: drop the Environment field.
- HttpTransport: drop the AudienceEnvironment ctor parameter; URL
  derives from publishableKey prefix.
- ImmutableAudience: remove the CurrentEnvironment getter and its
  cached backing field; revert DeleteData, SyncConsentToBackend, and
  Init to pass publishableKey into the URL helpers.
- Tests: remove the CurrentEnvironment_* cases and the per-env URL
  cases; restore the pre-PR test-key / prod-key URL assertions.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
ImmutableJeffrey added a commit that referenced this pull request Apr 24, 2026
Addresses review feedback on #709 from @nattb8: match the Web/Pixel SDK
pattern of letting callers override the API base URL.

BaseUrl is null by default. A null override keeps the existing
key-prefix derivation — "pk_imapik-test-" keys resolve to Sandbox and
every other key resolves to Production — so there is no behaviour
change for studios that never set this field. Integrations that need a
different backend (for example the Immutable-internal Dev API at
https://api.dev.immutable.com) pass the URL directly; no public env
token is surfaced.

- AudienceConfig: new BaseUrl string? property.
- Constants: BaseUrl / MessagesUrl / ConsentUrl / DataUrl accept an
  optional baseUrlOverride; override wins when non-empty, falls back to
  key-prefix derivation when null or empty.
- HttpTransport: ctor accepts baseUrlOverride and threads it into
  MessagesUrl.
- ImmutableAudience.Init passes config.BaseUrl into HttpTransport;
  DeleteData and SyncConsentToBackend pass it into DataUrl / ConsentUrl.
- Tests: BaseUrl resolution cases (test key, non-test key, null key,
  override wins, empty-string override falls back) and an end-to-end
  HttpTransport test confirming the override wins over a sandbox-
  derived key.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Comment thread src/Packages/Audience/Runtime/ImmutableAudience.cs Outdated
Comment thread src/Packages/Audience/Runtime/ImmutableAudience.cs
ImmutableJeffrey added a commit that referenced this pull request Apr 25, 2026
- `Initialized`: true once Init() finishes; false before Init / after Shutdown.
- `UserId`: cleared by Reset and any consent downgrade out of Full.
- `SessionId`: new ID at Init, Reset, on resume from a long-enough background pause, and on granting consent from None.

Plain-language style matches the audience-diagnostics docs follow-up.

Addresses PR #709 review: three getters lacked the per-member docs that the other public diagnostics getters already carry.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
ImmutableJeffrey added a commit that referenced this pull request Apr 25, 2026
- `Initialized`: true once Init() finishes; false before Init / after Shutdown.
- `UserId`: cleared by Reset and any consent downgrade out of Full.
- `SessionId`: new ID at Init, Reset, on resume from a long-enough background pause, and on granting consent from None.
- Drops the shared "diagnostic getters" block header; per-getter docs now cover each member's behaviour directly.

Plain-language style matches the audience-diagnostics docs follow-up.

Addresses PR #709 review: three getters lacked the per-member docs that the other public diagnostics getters already carry.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
ImmutableJeffrey added a commit that referenced this pull request Apr 25, 2026
- `Initialized`: true once Init() finishes; false before Init / after Shutdown.
- `UserId`: cleared by Reset and any consent downgrade out of Full.
- `SessionId`: new ID at Init, Reset, on resume from a long-enough
  background pause, and on granting consent from None.
- Drops the shared "diagnostic getters" block header; per-getter docs
  now cover each member's behaviour directly.

Plain-language style matches the audience-diagnostics docs follow-up.

Addresses PR #709 review: three getters lacked the per-member docs
that the other public diagnostics getters already carry.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
ImmutableJeffrey added a commit that referenced this pull request Apr 25, 2026
Addresses review feedback on #709 from @nattb8: match the Web/Pixel SDK
pattern of letting callers override the API base URL.

BaseUrl is null by default. A null override keeps the existing
key-prefix derivation — "pk_imapik-test-" keys resolve to Sandbox and
every other key resolves to Production — so there is no behaviour
change for studios that never set this field. Integrations that need a
different backend (for example the Immutable-internal Dev API at
https://api.dev.immutable.com) pass the URL directly; no public env
token is surfaced.

- AudienceConfig: new BaseUrl string? property.
- Constants: BaseUrl / MessagesUrl / ConsentUrl / DataUrl accept an
  optional baseUrlOverride; override wins when non-empty, falls back to
  key-prefix derivation when null or empty.
- HttpTransport: ctor accepts baseUrlOverride and threads it into
  MessagesUrl.
- ImmutableAudience.Init passes config.BaseUrl into HttpTransport;
  DeleteData and SyncConsentToBackend pass it into DataUrl / ConsentUrl.
- Tests: BaseUrl resolution cases (test key, non-test key, null key,
  override wins, empty-string override falls back) and an end-to-end
  HttpTransport test confirming the override wins over a sandbox-
  derived key.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Adds six public diagnostic getters on ImmutableAudience:
- Initialized: true between Init and Shutdown.
- CurrentConsent: live consent level.
- UserId: last Identify value; null below Full consent.
- AnonymousId: anonymous, persistent ID.
- SessionId: current session id; rotates on Init / Reset / timeout.
- QueueSize: number of unsent events (memory + disk).

Each getter is safe from any thread and returns a safe default
when the SDK cannot answer. EventQueue gains an internal
InMemoryCount property so QueueSize can sum without locking.

Adds optional AudienceConfig.BaseUrl override (matches Web/Pixel
SDK pattern; addresses #709 review). Null preserves the key-prefix
derivation; integrations needing a different backend pass the URL
directly.

Tests cover diagnostics lifecycle and BaseUrl resolution.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@ImmutableJeffrey ImmutableJeffrey merged commit 62fcd03 into feat/sdk-146-unity Apr 26, 2026
18 checks passed
@ImmutableJeffrey ImmutableJeffrey deleted the feat/audience-env branch April 26, 2026 23:32
ImmutableJeffrey added a commit that referenced this pull request Apr 27, 2026
Adds six public diagnostic getters on ImmutableAudience:
- Initialized: true between Init and Shutdown.
- CurrentConsent: live consent level.
- UserId: last Identify value; null below Full consent.
- AnonymousId: anonymous, persistent ID.
- SessionId: current session id; rotates on Init / Reset / timeout.
- QueueSize: number of unsent events (memory + disk).

Each getter is safe from any thread and returns a safe default
when the SDK cannot answer. EventQueue gains an internal
InMemoryCount property so QueueSize can sum without locking.

Adds optional AudienceConfig.BaseUrl override (matches Web/Pixel
SDK pattern; addresses #709 review). Null preserves the key-prefix
derivation; integrations needing a different backend pass the URL
directly.

Tests cover diagnostics lifecycle and BaseUrl resolution.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Development

Successfully merging this pull request may close these issues.

2 participants