Skip to content

Commit 9e4c15b

Browse files
committed
Honour DNT
1 parent e6c63aa commit 9e4c15b

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

packages/app/src/app/pages/index.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ import _debug from 'app/utils/debug';
88
import Notifications from 'app/pages/common/Notifications';
99
import Loading from 'app/components/Loading';
1010

11+
import send, { DNT } from 'common/utils/analytics';
12+
1113
import Modals from './common/Modals';
1214
import Sandbox from './Sandbox';
1315
import NewSandbox from './NewSandbox';
@@ -88,9 +90,10 @@ class Routes extends React.Component<Props> {
8890
routeDebugger(
8991
`Sending '${location.pathname + location.search}' to ga.`
9092
);
91-
if (typeof window.ga === 'function') {
93+
if (typeof window.ga === 'function' && !DNT) {
9294
window.ga('set', 'page', location.pathname + location.search);
93-
window.ga('send', 'pageview');
95+
96+
send('pageview');
9497
}
9598
}
9699
return null;

packages/common/utils/analytics.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
export const DNT = !!(
2+
window.doNotTrack ||
3+
window.navigator.doNotTrack ||
4+
window.navigator.msDoNotTrack
5+
);
6+
7+
export default function track(eventName, secondArg: any) {
8+
if (window.ga && !DNT) {
9+
window.ga('send', secondArg);
10+
}
11+
}

0 commit comments

Comments
 (0)