diff --git a/client/src/env.ts b/client/src/env.ts index 2c35966521e7..8aeb1a29e403 100644 --- a/client/src/env.ts +++ b/client/src/env.ts @@ -78,6 +78,8 @@ export const FXA_MANAGE_SUBSCRIPTIONS_URL = export const DEFAULT_GEO_COUNTRY = process.env.REACT_APP_DEFAULT_GEO_COUNTRY || "United States"; +export const DEFAULT_GEO_COUNTRY_ISO = + process.env.REACT_APP_DEFAULT_GEO_COUNTRY_ISO || "US"; export const BCD_BASE_URL = process.env.REACT_APP_BCD_BASE_URL ?? "https://bcd.developer.allizom.org"; diff --git a/client/src/telemetry/generated/navigator.ts b/client/src/telemetry/generated/navigator.ts index 329dae37316f..951207cca542 100644 --- a/client/src/telemetry/generated/navigator.ts +++ b/client/src/telemetry/generated/navigator.ts @@ -20,6 +20,19 @@ export const geo = new StringMetricType({ disabled: false, }); +/** + * The navigators ISO 3166 country code based on geo ip. + * + * Generated from `navigator.geo_iso`. + */ +export const geoIso = new StringMetricType({ + category: "navigator", + name: "geo_iso", + sendInPings: ["action", "page"], + lifetime: "application", + disabled: false, +}); + /** * The subscription type of the user. can be one of * 'core','mdn_plus_5m','mdn_plus_5y','mdn_plus_10m','mdn_plus_10y' diff --git a/client/src/telemetry/glean-context.tsx b/client/src/telemetry/glean-context.tsx index 8f1d76c457aa..f69803d35f68 100644 --- a/client/src/telemetry/glean-context.tsx +++ b/client/src/telemetry/glean-context.tsx @@ -32,6 +32,7 @@ export type PageProps = { httpStatus: HTTPStatus; subscriptionType: string; geo: string | undefined; + geo_iso: string | undefined; userAgent: string | undefined; viewportBreakpoint: ViewportBreakpoint | undefined; viewportRatio: number; @@ -117,6 +118,9 @@ function glean(): GleanAnalytics { if (page.geo) { navigatorMetric.geo.set(page.geo); } + if (page.geo_iso) { + navigatorMetric.geoIso.set(page.geo_iso); + } if (page.userAgent) { navigatorMetric.userAgent.set(page.userAgent); } @@ -204,6 +208,7 @@ export function useGleanPage(pageNotFound: boolean, doc?: Doc) { httpStatus: pageNotFound ? "404" : "200", userAgent: navigator?.userAgent, geo: userData?.geo?.country, + geo_iso: userData?.geo?.country_iso, subscriptionType: userData?.subscriptionType || "anonymous", viewportBreakpoint: VIEWPORT_BREAKPOINTS.find( ([_, width]) => width <= window.innerWidth diff --git a/client/src/telemetry/metrics.yaml b/client/src/telemetry/metrics.yaml index 348d57b8f01c..75bee79369ca 100644 --- a/client/src/telemetry/metrics.yaml +++ b/client/src/telemetry/metrics.yaml @@ -121,6 +121,23 @@ navigator: notification_emails: - mdn-team@mozilla.com expires: 2024-09-05 + geo_iso: + type: string + lifetime: application + send_in_pings: + - page + - action + description: | + The navigator's two-letter ISO 3166 country code based on geo ip. + data_sensitivity: + - web_activity + bugs: + - https://bugzilla.mozilla.org/show_bug.cgi?id=1798296 + data_reviews: + - https://github.com/mdn/yari/pull/7457#issuecomment-1296934544 + notification_emails: + - mdn-team@mozilla.com + expires: 2024-09-05 user_agent: type: string lifetime: application diff --git a/client/src/user-context.tsx b/client/src/user-context.tsx index 2f1d9032f674..7839cb1b0a16 100644 --- a/client/src/user-context.tsx +++ b/client/src/user-context.tsx @@ -1,7 +1,11 @@ import * as React from "react"; import useSWR from "swr"; -import { DISABLE_AUTH, DEFAULT_GEO_COUNTRY } from "./env"; +import { + DISABLE_AUTH, + DEFAULT_GEO_COUNTRY, + DEFAULT_GEO_COUNTRY_ISO, +} from "./env"; import { FREQUENTLY_VIEWED_STORAGE_KEY } from "./plus/collections/frequently-viewed"; const DEPRECATED_LOCAL_STORAGE_KEYS = [ @@ -76,6 +80,7 @@ export type User = { email: string | null | undefined; geo: { country: string; + country_iso: string; }; maintenance?: string; settings: null | UserPlusSettings; @@ -199,6 +204,8 @@ export function UserDataProvider(props: { children: React.ReactNode }) { email: data.email || null, geo: { country: (data.geo && data.geo.country) || DEFAULT_GEO_COUNTRY, + country_iso: + (data.geo && data.geo.country_iso) || DEFAULT_GEO_COUNTRY_ISO, }, maintenance: data.maintenance, settings, diff --git a/docs/envvars.md b/docs/envvars.md index 2c59375a002a..1a442e5e680a 100644 --- a/docs/envvars.md +++ b/docs/envvars.md @@ -311,6 +311,14 @@ If the `/api/v1/whoami` does not include a `geo.country` value, fall back on this. Setting this allows you to pretend the XHR request to `/api/v1/whoami` included this value for `geo.country`. +### `REACT_APP_DEFAULT_GEO_COUNTRY_ISO` + +**Default: `US`** + +If the `/api/v1/whoami` does not include a `geo.country_iso` value, fall back on +this. Setting this allows you to pretend the XHR request to `/api/v1/whoami` +included this value for `geo.country_iso`. + ## Glean (Analytics) ### `REACT_APP_GLEAN_CHANNEL`