Skip to content

Commit

Permalink
Accept utm_source query param as referrer
Browse files Browse the repository at this point in the history
  • Loading branch information
jnaklaas committed Jan 25, 2021
1 parent 0b8336f commit 8e387af
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 2 deletions.
8 changes: 8 additions & 0 deletions components/metrics/RealtimeViews.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}, [])
Expand Down
2 changes: 1 addition & 1 deletion lib/filters.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ export const refFilter = (data, { domain, domainOnly, raw }) => {

return null;
} catch {
return null;
return url;
}
};

Expand Down
13 changes: 12 additions & 1 deletion tracker/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 */

Expand Down

1 comment on commit 8e387af

@vercel
Copy link

@vercel vercel bot commented on 8e387af Jan 25, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.