diff --git a/browser/components/asrouter/docs/targeting-attributes.md b/browser/components/asrouter/docs/targeting-attributes.md index fcdb2afb7f9a..f3e49270f42e 100644 --- a/browser/components/asrouter/docs/targeting-attributes.md +++ b/browser/components/asrouter/docs/targeting-attributes.md @@ -19,6 +19,7 @@ Please note that some targeting attributes require stricter controls on the tele * [blockedCountByType](#blockedcountbytype) * [browserIsSelected](#browserisselected) * [browserSettings](#browsersettings) +* [buildId](#buildId) * [canCreateSelectableProfiles](#cancreateselectableprofiles) * [creditCardsSaved](#creditcardssaved) * [currentDate](#currentdate) @@ -205,6 +206,24 @@ declare const browserSettings: { } ``` +### `buildId` + +The build ID (`MOZ_BUILDID`) parsed as a number to allow for comparisons. + +#### Examples + +* Is the build from at least Jan 01 2025 + +```java +buildId >= 202501010000 +``` + +#### Definition + +```ts +declare const buildId: number; +``` + ### `currentDate` The current date at the moment message targeting is checked. diff --git a/browser/components/asrouter/modules/ASRouterTargeting.sys.mjs b/browser/components/asrouter/modules/ASRouterTargeting.sys.mjs index cabd7330296b..ffdacfaf9a7f 100644 --- a/browser/components/asrouter/modules/ASRouterTargeting.sys.mjs +++ b/browser/components/asrouter/modules/ASRouterTargeting.sys.mjs @@ -1199,6 +1199,10 @@ const TargetingGetters = { get profileGroupId() { return QueryCache.getters.profileGroupId.get(); }, + + get buildId() { + return parseInt(AppConstants.MOZ_BUILDID, 10); + }, }; export const ASRouterTargeting = { diff --git a/browser/components/asrouter/tests/browser/browser_asrouter_targeting.js b/browser/components/asrouter/tests/browser/browser_asrouter_targeting.js index 021e432a24bf..9dc2dada05ce 100644 --- a/browser/components/asrouter/tests/browser/browser_asrouter_targeting.js +++ b/browser/components/asrouter/tests/browser/browser_asrouter_targeting.js @@ -2031,3 +2031,22 @@ add_task(async function check_profileGroupIdTargeting() { "should select correct item by profile group id" ); }); + +add_task(async function test_buildId() { + is( + typeof ASRouterTargeting.Environment.buildId, + "number", + "Should return a number" + ); + + const message = { + id: "foo", + // Later than January 2025 + targeting: `buildId >= 20251010000`, + }; + is( + await ASRouterTargeting.findMatchingMessage({ messages: [message] }), + message, + "should select correct item when filtering by build ID" + ); +}); diff --git a/toolkit/components/nimbus/lib/TargetingContextRecorder.sys.mjs b/toolkit/components/nimbus/lib/TargetingContextRecorder.sys.mjs index eeedfc2f8046..485ec80385b5 100644 --- a/toolkit/components/nimbus/lib/TargetingContextRecorder.sys.mjs +++ b/toolkit/components/nimbus/lib/TargetingContextRecorder.sys.mjs @@ -99,6 +99,8 @@ function assertType(expectedType, attribute) { * type. */ const typeAssertions = { + integer: attribute => + assertType("number", attribute) && Number.isSafeInteger(attribute), string: attribute => assertType("string", attribute), boolean: attribute => assertType("boolean", attribute), quantity: attribute => Math.floor(assertType("number", attribute)), @@ -133,6 +135,7 @@ export const ATTRIBUTE_TRANSFORMS = Object.freeze({ browserSettings: pickWith({ update: pick("channel"), }), + buildId: typeAssertions.integer, currentDate: typeAssertions.date, defaultPDFHandler: pick("knownBrowser", "registered"), distributionId: typeAssertions.string, diff --git a/toolkit/components/nimbus/metrics.yaml b/toolkit/components/nimbus/metrics.yaml index b2920a0d0632..34fca8ce12cf 100644 --- a/toolkit/components/nimbus/metrics.yaml +++ b/toolkit/components/nimbus/metrics.yaml @@ -28,12 +28,14 @@ nimbus_targeting_environment: - https://bugzilla.mozilla.org/show_bug.cgi?id=1898394 - https://bugzilla.mozilla.org/show_bug.cgi?id=1949813 - https://bugzilla.mozilla.org/show_bug.cgi?id=1963160 + - https://bugzilla.mozilla.org/show_bug.cgi?id=1963183 data_reviews: &targeting_context_data_reviews - https://bugzilla.mozilla.org/show_bug.cgi?id=1928107 - https://bugzilla.mozilla.org/show_bug.cgi?id=1937207 - https://bugzilla.mozilla.org/show_bug.cgi?id=1898394 - https://bugzilla.mozilla.org/show_bug.cgi?id=1949813 - https://bugzilla.mozilla.org/show_bug.cgi?id=1963160 + - https://bugzilla.mozilla.org/show_bug.cgi?id=1963183 notification_emails: &targeting_context_notification_emails - beth@mozilla.com - project-nimbus@mozilla.com @@ -107,6 +109,7 @@ nimbus_targeting_environment: - "archBits" - "attributionData" - "browserSettings" + - "buildId" - "currentDate" - "defaultPDFHandler" - "distributionId" @@ -335,6 +338,18 @@ nimbus_targeting_context: channel: type: string + build_id: + bugs: *targeting_context_bugs + data_reviews: *targeting_context_data_reviews + expires: *targeting_context_expiry + notification_emails: *targeting_context_notification_emails + send_in_pings: *targeting_context_pings + description: The Build ID. + data_sensitivity: + - technical + type: quantity + unit: build ID + current_date: bugs: *targeting_context_bugs data_reviews: *targeting_context_data_reviews