Skip to content

Commit

Permalink
Filter domain from referrers.
Browse files Browse the repository at this point in the history
  • Loading branch information
mikecao committed Aug 7, 2020
1 parent 00e232f commit 0a411a9
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 8 deletions.
2 changes: 1 addition & 1 deletion components/WebsiteDetails.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ export default function WebsiteDetails({ websiteId, defaultDateRange = '7day' })
websiteId={websiteId}
startDate={startDate}
endDate={endDate}
dataFilter={refFilter}
dataFilter={refFilter(data.domain)}
/>
</div>
</div>
Expand Down
2 changes: 1 addition & 1 deletion components/interface/UserButton.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ export default function UserButton() {
return (
<div ref={ref} className={styles.container}>
<div onClick={() => setShowMenu(state => !state)}>
<Icon icon={<User />} size="L" className={styles.icon} />
<Icon icon={<User />} size="L" />
<Icon icon={<Chevron />} size="S" />
</div>
{showMenu && <Menu options={menuOptions} onSelect={handleSelect} align="right" />}
Expand Down
4 changes: 0 additions & 4 deletions components/interface/UserButton.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,6 @@
cursor: pointer;
}

.icon {
margin-right: 8px;
}

.username {
border-bottom: 1px solid var(--gray500);
}
Expand Down
9 changes: 7 additions & 2 deletions lib/filters.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
import escape from 'escape-string-regexp';
import { BROWSERS, ISO_COUNTRIES, DEVICES } from './constants';

export const browserFilter = data =>
data.map(({ x, ...props }) => ({ x: BROWSERS[x] || x, ...props }));

export const urlFilter = data => data.filter(({ x }) => x !== '' && !x.startsWith('#'));

export const refFilter = data =>
data.filter(({ x }) => x !== '' && !x.startsWith('/') && !x.startsWith('#'));
export const refFilter = domain => data => {
const regex = new RegExp(escape(domain));
return data.filter(
({ x }) => x !== '' && !x.startsWith('/') && !x.startsWith('#') && !regex.test(x),
);
};

export const deviceFilter = data =>
data.map(({ x, ...props }) => ({ x: DEVICES[x] || x, ...props }));
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
"date-fns-tz": "^1.0.10",
"detect-browser": "^5.1.1",
"dotenv": "^8.2.0",
"escape-string-regexp": "^4.0.0",
"formik": "^2.1.5",
"geolite2-redist": "^1.0.7",
"is-localhost-ip": "^1.4.0",
Expand Down
5 changes: 5 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3605,6 +3605,11 @@ escape-string-regexp@^1.0.2, escape-string-regexp@^1.0.5:
resolved "https://registry.yarnpkg.com/escape-string-regexp/-/escape-string-regexp-1.0.5.tgz#1b61c0562190a8dff6ae3bb2cf0200ca130b86d4"
integrity sha1-G2HAViGQqN/2rjuyzwIAyhMLhtQ=

escape-string-regexp@^4.0.0:
version "4.0.0"
resolved "https://registry.yarnpkg.com/escape-string-regexp/-/escape-string-regexp-4.0.0.tgz#14ba83a5d373e3d311e5afca29cf5bfad965bf34"
integrity sha512-TtpcNJ3XAzx3Gq8sWRzJaVajRs0uVxA2YAkdb1jm2YkPz4G6egUFAyA3n5vtEIZefPk5Wa4UXbKuS5fKkJWdgA==

eslint-config-prettier@^6.11.0:
version "6.11.0"
resolved "https://registry.yarnpkg.com/eslint-config-prettier/-/eslint-config-prettier-6.11.0.tgz#f6d2238c1290d01c859a8b5c1f7d352a0b0da8b1"
Expand Down

0 comments on commit 0a411a9

Please sign in to comment.