Skip to content

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

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

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

Conversation

@Almaju
Copy link
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 added 3 commits March 18, 2026 17:19
The /v1/t tracking endpoint requires a `reason` query parameter for
report interactions. Add MozAdsReportReason enum with Inappropriate,
NotInterested, and SeenTooManyTimes variants and thread it through
the full stack, appending it to the callback URL before the request.
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. `rotation_days` is silently ignored (with a log warning) when
an external provider is supplied.

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.
@Almaju Almaju marked this pull request as draft March 18, 2026 23: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