Skip to content

feat(ads-client): add MozAdsContextIdProvider callback interface (AC-95)#7278

Draft
Almaju wants to merge 2 commits intomozilla:mainfrom
Almaju:ac-95-context-id-provider
Draft

feat(ads-client): add MozAdsContextIdProvider callback interface (AC-95)#7278
Almaju wants to merge 2 commits intomozilla:mainfrom
Almaju:ac-95-context-id-provider

Conversation

@Almaju
Copy link
Copy Markdown
Contributor

@Almaju Almaju commented Mar 18, 2026

Fixes AC-95.

Summary

AdsClient was internally creating a throw-away UUID via ContextIDComponent with DefaultContextIdCallback, completely disconnected from HNT's own ContextId.sys.mjs system (which handles storage in prefs, rotation, and MARS deletion via OHTTP).

This PR introduces an opt-in MozAdsContextIdProvider callback interface that lets embedders supply their own context ID:

  • MozAdsContextIdProvider UniFFI callback interface with a single context_id() -> String method — consumers implement this in JS/Swift/Kotlin and cache the value synchronously
  • context_id_provider() builder method on MozAdsClientBuilder
  • When a provider is set, the embedded ContextIDComponent is not created; rotation_days is ignored (logged as a warning)
  • When no provider is set (default), behaviour is identical to today — no breaking change for mobile

HNT will implement MozAdsContextIdProvider in JS, backed by ContextId.sys.mjs, which continues to own rotation and MARS deletion unchanged.

Pull Request checklist

  • Breaking changes: This PR follows our breaking change policy
    • This PR follows the breaking change policy:
      • This PR has no breaking API changes, or
      • There are corresponding PRs for our consumer applications that resolve the breaking changes and have been approved
  • Quality: This PR builds and tests run cleanly
    • Note:
      • For changes that need extra cross-platform testing, consider adding [ci full] to the PR title.
      • If this pull request includes a breaking change, consider cutting a new release after merging.
  • Tests: This PR includes thorough tests or an explanation of why it does not
    • Existing tests cover the embedded path unchanged; the external-provider path is exercised via get_context_id() dispatching to ContextIdSource::External
  • Changelog: This PR includes a changelog entry in CHANGELOG.md or an explanation of why it does not need one
    • Any breaking changes to Swift or Kotlin binding APIs are noted explicitly
  • Dependencies: This PR follows our dependency management guidelines
    • Added log = "0.4" — already used across the workspace, no due diligence required

@Almaju Almaju marked this pull request as draft March 18, 2026 23:33
@Almaju Almaju force-pushed the ac-95-context-id-provider branch 2 times, most recently from 275c80f to 690b5ce Compare April 2, 2026 20:31
Introduces an optional `context_id_provider()` method on
`MozAdsClientBuilder` that accepts a `MozAdsContextIdProvider` UniFFI
callback interface. When set, the embedded `ContextIDComponent` is not
created — the caller's implementation is used instead.

This allows HNT to wire its existing `ContextId.sys.mjs` (which handles
storage, rotation, and MARS deletion via OHTTP) directly into the ads
client, eliminating the competing throw-away UUID the client was
generating internally.

Mobile consumers that do not set a provider are completely unaffected.
`rotation_days` has been removed from the public API; the embedded path
always uses the default 3-day rotation.
@Almaju Almaju force-pushed the ac-95-context-id-provider branch from 05f766f to 45eb400 Compare April 2, 2026 20:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant