Skip to content

Commit

Permalink
fix(glean): fix url metrics (#9516)
Browse files Browse the repository at this point in the history
* fix(glean): fix url metrics

* add base url for referrer
  • Loading branch information
fiji-flo authored Aug 19, 2023
1 parent e9f49cd commit f962258
Showing 1 changed file with 17 additions and 4 deletions.
21 changes: 17 additions & 4 deletions client/src/telemetry/glean-context.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,17 @@ export type GleanAnalytics = {
const FIRST_PARTY_DATA_OPT_OUT_COOKIE_NAME = "moz-1st-party-data-opt-out";
const GLEAN_APP_ID = "mdn-yari";

function urlOrNull(url?: string, base?: string | URL) {
if (!url) {
return null;
}
try {
return new URL(url, base);
} catch (_) {
return null;
}
}

function glean(): GleanAnalytics {
if (typeof window === "undefined" || !GLEAN_ENABLED) {
//SSR return noop.
Expand Down Expand Up @@ -74,11 +85,13 @@ function glean(): GleanAnalytics {

const gleanContext = {
page: (page: PageProps) => {
if (page.path) {
pageMetric.path.set(page.path);
const path = urlOrNull(page.path);
if (path) {
pageMetric.path.setUrl(path);
}
if (page.referrer) {
pageMetric.referrer.set(page.referrer);
const referrer = urlOrNull(page.referrer, window?.location.href);
if (referrer) {
pageMetric.referrer.setUrl(referrer);
}
pageMetric.httpStatus.set(page.httpStatus);
if (page.geo) {
Expand Down

0 comments on commit f962258

Please sign in to comment.