Skip to content

Commit 151d474

Browse files
committed
Disable Google Analytics on preview builds
Preview builds were firing page view events into the production GA property, inflating metrics with internal review traffic. Skip the @docusaurus/plugin-google-gtag plugin when DOCUSAURUS_IS_PREVIEW=true is set by pr-preview.yml.
1 parent b953ff2 commit 151d474

2 files changed

Lines changed: 15 additions & 8 deletions

File tree

.github/workflows/pr-preview.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ jobs:
3636
env:
3737
DOCUSAURUS_URL: https://usace-rmc.github.io
3838
DOCUSAURUS_BASE_URL: /RMC-Software-Documentation-Previews/pr-${{ github.event.pull_request.number }}/
39+
DOCUSAURUS_IS_PREVIEW: 'true'
3940
run: npm run build
4041
- uses: peaceiris/actions-gh-pages@v4
4142
with:

docusaurus.config.js

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -89,14 +89,20 @@ export default {
8989
],
9090

9191
plugins: [
92-
// Google Analytics plugin
93-
[
94-
'@docusaurus/plugin-google-gtag',
95-
{
96-
trackingID: 'G-LB2BWWGDTB',
97-
anonymizeIP: true,
98-
},
99-
],
92+
// Google Analytics plugin — production builds only.
93+
// Preview builds set DOCUSAURUS_IS_PREVIEW=true so they don't pollute
94+
// the production GA property with pr-preview page views.
95+
...(process.env.DOCUSAURUS_IS_PREVIEW === 'true'
96+
? []
97+
: [
98+
[
99+
'@docusaurus/plugin-google-gtag',
100+
{
101+
trackingID: 'G-LB2BWWGDTB',
102+
anonymizeIP: true,
103+
},
104+
],
105+
]),
100106

101107
// TailwindCSS as a custom plugin
102108
tailwindPlugin,

0 commit comments

Comments
 (0)