From c01f3534b698118adf3041ba004872470bf5fcb1 Mon Sep 17 00:00:00 2001 From: Claas Augner Date: Mon, 30 Oct 2023 21:09:28 +0100 Subject: [PATCH 1/4] chore(glean): send geo_iso with pings --- client/src/env.ts | 2 ++ client/src/telemetry/generated/navigator.ts | 13 +++++++++++++ client/src/telemetry/glean-context.tsx | 4 ++++ client/src/telemetry/metrics.yaml | 17 +++++++++++++++++ client/src/user-context.tsx | 8 +++++++- docs/envvars.md | 8 ++++++++ 6 files changed, 51 insertions(+), 1 deletion(-) 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..c50773517a6b 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.geo_iso.set(page.geo_iso); + } if (page.userAgent) { navigatorMetric.userAgent.set(page.userAgent); } diff --git a/client/src/telemetry/metrics.yaml b/client/src/telemetry/metrics.yaml index 348d57b8f01c..48cb266c8bc9 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 navigators 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..6c7e7975207f 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 = [ @@ -199,6 +203,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` From 4112b79a501e5424712695f02d70e36436f41651 Mon Sep 17 00:00:00 2001 From: Claas Augner Date: Tue, 31 Oct 2023 18:39:01 +0100 Subject: [PATCH 2/4] fixup! chore(glean): send geo_iso with pings --- client/src/telemetry/glean-context.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/client/src/telemetry/glean-context.tsx b/client/src/telemetry/glean-context.tsx index c50773517a6b..2bc8371dfb8b 100644 --- a/client/src/telemetry/glean-context.tsx +++ b/client/src/telemetry/glean-context.tsx @@ -119,7 +119,7 @@ function glean(): GleanAnalytics { navigatorMetric.geo.set(page.geo); } if (page.geo_iso) { - navigatorMetric.geo_iso.set(page.geo_iso); + navigatorMetric.geoIso.set(page.geo_iso); } if (page.userAgent) { navigatorMetric.userAgent.set(page.userAgent); From da4e5014cdc5f55d56513cd2922e7c9fada05451 Mon Sep 17 00:00:00 2001 From: Claas Augner Date: Tue, 31 Oct 2023 19:00:24 +0100 Subject: [PATCH 3/4] fixup! chore(glean): send geo_iso with pings --- client/src/telemetry/glean-context.tsx | 1 + client/src/user-context.tsx | 1 + 2 files changed, 2 insertions(+) diff --git a/client/src/telemetry/glean-context.tsx b/client/src/telemetry/glean-context.tsx index 2bc8371dfb8b..f69803d35f68 100644 --- a/client/src/telemetry/glean-context.tsx +++ b/client/src/telemetry/glean-context.tsx @@ -208,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/user-context.tsx b/client/src/user-context.tsx index 6c7e7975207f..7839cb1b0a16 100644 --- a/client/src/user-context.tsx +++ b/client/src/user-context.tsx @@ -80,6 +80,7 @@ export type User = { email: string | null | undefined; geo: { country: string; + country_iso: string; }; maintenance?: string; settings: null | UserPlusSettings; From da2db7ea9c68d34425e8b6b3474762d292540a5e Mon Sep 17 00:00:00 2001 From: Claas Augner <495429+caugner@users.noreply.github.com> Date: Mon, 6 Nov 2023 18:26:48 +0100 Subject: [PATCH 4/4] Update client/src/telemetry/metrics.yaml Co-authored-by: Leo McArdle --- client/src/telemetry/metrics.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/client/src/telemetry/metrics.yaml b/client/src/telemetry/metrics.yaml index 48cb266c8bc9..75bee79369ca 100644 --- a/client/src/telemetry/metrics.yaml +++ b/client/src/telemetry/metrics.yaml @@ -128,7 +128,7 @@ navigator: - page - action description: | - The navigators ISO 3166 country code based on geo ip. + The navigator's two-letter ISO 3166 country code based on geo ip. data_sensitivity: - web_activity bugs: