Skip to content

Commit

Permalink
[website] Sample GA to avoid hit limit
Browse files Browse the repository at this point in the history
  • Loading branch information
oliviertassinari committed Feb 5, 2022
1 parent 27f1c28 commit e1fb1d4
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions docs/pages/_document.js
Expand Up @@ -29,7 +29,10 @@ if (process.env.NODE_ENV === 'production') {
cleanCSS = new CleanCSS();
}

const GOOGLE_ID = process.env.NODE_ENV === 'production' ? 'UA-106598593-2' : 'UA-106598593-3';
const PRODUCTION_DEPLOYEMENT =
process.env.PULL_REQUEST !== 'true' && process.env.NODE_ENV === 'production';

const GOOGLE_ANALYTICS_ID = PRODUCTION_DEPLOYEMENT ? 'UA-106598593-2' : 'UA-106598593-3';

export default class MyDocument extends Document {
render() {
Expand Down Expand Up @@ -140,7 +143,9 @@ export default class MyDocument extends Document {
dangerouslySetInnerHTML={{
__html: `
window.ga=window.ga||function(){(ga.q=ga.q||[]).push(arguments)};ga.l=+new Date;
window.ga('create','${GOOGLE_ID}','auto');
window.ga('create','${GOOGLE_ANALYTICS_ID}',{
sampleRate: ${PRODUCTION_DEPLOYEMENT ? 80 : 100},
});
`,
}}
/>
Expand Down

0 comments on commit e1fb1d4

Please sign in to comment.