Supporting "Do Not Track" for Gogle Analytics and Sentry error reporting

This commit is contained in:
Jeff Avallone 2018-05-24 17:01:17 -04:00
parent 7698901451
commit 1a8bb762cb
4 changed files with 49 additions and 10 deletions

View File

@ -1,10 +1,12 @@
import ReactGA from 'react-ga';
const setupAnalytics = () => {
ReactGA.initialize(process.env.GA_PROPERTY, {
debug: (process.env.NODE_ENV !== 'production')
});
ReactGA.pageview(document.location.pathname);
if (navigator.doNotTrack !== '1' && window.doNotTrack !== '1') {
ReactGA.initialize(process.env.GA_PROPERTY, {
debug: (process.env.NODE_ENV !== 'production')
});
ReactGA.pageview(document.location.pathname);
}
};
export default setupAnalytics;

View File

@ -34,4 +34,24 @@ describe('setupAnalytics', () => {
setupAnalytics();
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();
});
});
});

View File

@ -1,12 +1,14 @@
import Raven from 'raven-js';
const setupRaven = () => {
Raven.config(process.env.SENTRY_KEY, {
whitelistUrls: [/https:\/\/(.*\.)?regexper\.com/],
environment: process.env.DEPLOY_ENV,
debug: (process.env.NODE_ENV !== 'production'),
release: process.env.BUILD_ID
});
if (navigator.doNotTrack !== '1' && window.doNotTrack !== '1') {
Raven.config(process.env.SENTRY_KEY, {
whitelistUrls: [/https:\/\/(.*\.)?regexper\.com/],
environment: process.env.DEPLOY_ENV,
debug: (process.env.NODE_ENV !== 'production'),
release: process.env.BUILD_ID
});
}
};
export default setupRaven;

View File

@ -45,4 +45,19 @@ describe('setupRaven', () => {
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();
});
});
});