facebook / facebook/docusaurus

Duplicate Google Analytics Events Triggered on Docusaurus Documentation Site

Abierto
#10,568 2 comentarios 0 reacciones 0 asignados Ver en GitHub
bug status: needs triage
Lenguaje dominante
TypeScript
Estrellas
66.2k
Forks
10k
Merge medio
1 d 3 h
PR fusionados (30 d)
52

Descripción

### Have you read the Contributing Guidelines on issues?

- [X] I have read the [Contributing Guidelines on issues](https://github.com/facebook/docusaurus/blob/main/CONTRIBUTING.md#issues).

### Prerequisites

- [X] I'm using the latest version of Docusaurus.
- [X] I have tried the `npm run clear` or `yarn clear` command.
- [X] I have tried `rm -rf node_modules yarn.lock package-lock.json` and re-installing packages.
- [ ] I have tried creating a repro with https://new.docusaurus.io.
- [X] I have read the console error message carefully (if applicable).

### Description

We are experiencing an issue where duplicate Google Analytics (GA) events are being sent when users visit our documentation site built using Docusaurus. This results in two page view counts for each user session in our GA reports.

Our main website is hosted at `www.test.com` and the documentation is available at `www.test.com/docs`. We have configured Google Analytics for the main website using a single gtag ID (`G-test`). We also configured the Docusaurus documentation site using the same gtag ID via Docusaurus' `@docusaurus/plugin-google-gtag`.

Whenever we access the documentation site (`www.test.com/docs`), we observe two `collect` network calls being made to Google Analytics, which results in inflated user visit counts.

### Reproducible demo

_No response_

### Steps to reproduce

1. Create a new Docusaurus documentation site (e.g., `my-docs-site`).
2. Pick a gtag ID from one of your existing websites that already has Google Analytics configured.
3. Use this gtag ID in the Docusaurus setup (`@docusaurus/plugin-google-gtag`).
4. Open the documentation site in the browser and navigate through pages.
5. Open the browser’s developer tools (Network tab).
6. Observe that two `collect` calls are made to Google Analytics for every user action.
7. Check Google Analytics and notice that two page view events are logged for every visit to the documentation.

### Expected behavior

- Only one `collect` call should be made when visiting the documentation.
- GA should only count one user visit per page load.

### Actual behavior

- Two `collect` calls are triggered for each page visit and navigation between pages on the documentation site, causing GA to log two user visits for every single page load or navigation event.

### Your environment

- Docusaurus version used: `3.5.2`
- Environment name: All browser
- Operating system: Windows/Linux/MacOS

### Self-service

- [ ] I'd be willing to fix this bug myself.

Guía de contribución

Abrir la guía de contribución

Evaluación

Este issue todavía no se ha evaluado.

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.