Skip to content

Commit

Permalink
chore(telemetry): send geo_iso with pings (#9909)
Browse files Browse the repository at this point in the history
Co-authored-by: Leo McArdle <lmcardle@mozilla.com>
  • Loading branch information
caugner and LeoMcA authored Nov 6, 2023
1 parent 37bf90c commit 2c94a69
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 1 deletion.
2 changes: 2 additions & 0 deletions client/src/env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
13 changes: 13 additions & 0 deletions client/src/telemetry/generated/navigator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
5 changes: 5 additions & 0 deletions client/src/telemetry/glean-context.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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
Expand Down
17 changes: 17 additions & 0 deletions client/src/telemetry/metrics.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 8 additions & 1 deletion client/src/user-context.tsx
Original file line number Diff line number Diff line change
@@ -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 = [
Expand Down Expand Up @@ -76,6 +80,7 @@ export type User = {
email: string | null | undefined;
geo: {
country: string;
country_iso: string;
};
maintenance?: string;
settings: null | UserPlusSettings;
Expand Down Expand Up @@ -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,
Expand Down
8 changes: 8 additions & 0 deletions docs/envvars.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand Down

0 comments on commit 2c94a69

Please sign in to comment.