Supporting "Do Not Track" for Gogle Analytics and Sentry error reporting
This commit is contained in:
parent
7698901451
commit
1a8bb762cb
@ -1,10 +1,12 @@
|
|||||||
import ReactGA from 'react-ga';
|
import ReactGA from 'react-ga';
|
||||||
|
|
||||||
const setupAnalytics = () => {
|
const setupAnalytics = () => {
|
||||||
ReactGA.initialize(process.env.GA_PROPERTY, {
|
if (navigator.doNotTrack !== '1' && window.doNotTrack !== '1') {
|
||||||
debug: (process.env.NODE_ENV !== 'production')
|
ReactGA.initialize(process.env.GA_PROPERTY, {
|
||||||
});
|
debug: (process.env.NODE_ENV !== 'production')
|
||||||
ReactGA.pageview(document.location.pathname);
|
});
|
||||||
|
ReactGA.pageview(document.location.pathname);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
export default setupAnalytics;
|
export default setupAnalytics;
|
||||||
|
@ -34,4 +34,24 @@ describe('setupAnalytics', () => {
|
|||||||
setupAnalytics();
|
setupAnalytics();
|
||||||
expect(ReactGA.pageview).toHaveBeenCalled();
|
expect(ReactGA.pageview).toHaveBeenCalled();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('when "Do Not Track" is set', () => {
|
||||||
|
beforeEach(() => {
|
||||||
|
navigator.doNotTrack = '1';
|
||||||
|
});
|
||||||
|
|
||||||
|
afterEach(() => {
|
||||||
|
navigator.doNotTrack = undefined;
|
||||||
|
});
|
||||||
|
|
||||||
|
it('does not initialize', () => {
|
||||||
|
setupAnalytics();
|
||||||
|
expect(ReactGA.initialize).not.toHaveBeenCalled();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('does not trigger a pageview', () => {
|
||||||
|
setupAnalytics();
|
||||||
|
expect(ReactGA.pageview).not.toHaveBeenCalled();
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
@ -1,12 +1,14 @@
|
|||||||
import Raven from 'raven-js';
|
import Raven from 'raven-js';
|
||||||
|
|
||||||
const setupRaven = () => {
|
const setupRaven = () => {
|
||||||
Raven.config(process.env.SENTRY_KEY, {
|
if (navigator.doNotTrack !== '1' && window.doNotTrack !== '1') {
|
||||||
whitelistUrls: [/https:\/\/(.*\.)?regexper\.com/],
|
Raven.config(process.env.SENTRY_KEY, {
|
||||||
environment: process.env.DEPLOY_ENV,
|
whitelistUrls: [/https:\/\/(.*\.)?regexper\.com/],
|
||||||
debug: (process.env.NODE_ENV !== 'production'),
|
environment: process.env.DEPLOY_ENV,
|
||||||
release: process.env.BUILD_ID
|
debug: (process.env.NODE_ENV !== 'production'),
|
||||||
});
|
release: process.env.BUILD_ID
|
||||||
|
});
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
export default setupRaven;
|
export default setupRaven;
|
||||||
|
@ -45,4 +45,19 @@ describe('setupRaven', () => {
|
|||||||
release: 'test ID'
|
release: 'test ID'
|
||||||
}));
|
}));
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('when "Do Not Track" is set', () => {
|
||||||
|
beforeEach(() => {
|
||||||
|
navigator.doNotTrack = '1';
|
||||||
|
});
|
||||||
|
|
||||||
|
afterEach(() => {
|
||||||
|
navigator.doNotTrack = undefined;
|
||||||
|
});
|
||||||
|
|
||||||
|
it('does not intialize', () => {
|
||||||
|
setupRaven();
|
||||||
|
expect(Raven.config).not.toHaveBeenCalled();
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
Loading…
Reference in New Issue
Block a user