From 8e387afe0294f80214c12aa762af27d68bc6b0e1 Mon Sep 17 00:00:00 2001 From: jnaklaas Date: Mon, 25 Jan 2021 14:29:14 +0100 Subject: [PATCH] Accept utm_source query param as referrer --- components/metrics/RealtimeViews.js | 8 ++++++++ lib/filters.js | 2 +- tracker/index.js | 13 ++++++++++++- 3 files changed, 21 insertions(+), 2 deletions(-) diff --git a/components/metrics/RealtimeViews.js b/components/metrics/RealtimeViews.js index dca82f2e88..ee50a77fe4 100644 --- a/components/metrics/RealtimeViews.js +++ b/components/metrics/RealtimeViews.js @@ -57,6 +57,14 @@ export default function RealtimeViews({ websiteId, data, websites }) { row.y += 1; } } + } else { + const row = arr.find(({ x }) => x === referrer); + + if (!row) { + arr.push({ x: referrer, y: 1 }); + } else { + row.y += 1; + } } return arr; }, []) diff --git a/lib/filters.js b/lib/filters.js index d485361854..a09afedf69 100644 --- a/lib/filters.js +++ b/lib/filters.js @@ -84,7 +84,7 @@ export const refFilter = (data, { domain, domainOnly, raw }) => { return null; } catch { - return null; + return url; } }; diff --git a/tracker/index.js b/tracker/index.js index fc8458b009..28e5691b18 100644 --- a/tracker/index.js +++ b/tracker/index.js @@ -39,7 +39,18 @@ import { removeTrailingSlash } from '../lib/url'; const screen = `${width}x${height}`; const listeners = []; let currentUrl = `${pathname}${search}`; - let currentRef = document.referrer; + + const getQueryStringParams = query => { + return query + ? (/^[?#]/.test(query) ? query.slice(1) : query).split('&').reduce((params, param) => { + let [key, value] = param.split('='); + params[key] = value ? decodeURIComponent(value.replace(/\+/g, ' ')) : ''; + return params; + }, {}) + : {}; + }; + + let currentRef = getQueryStringParams(location.search).utm_source || document.referrer; /* Collect metrics */