Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error: Plugin docusaurus-plugin-google-analytics is used 2 times with id=default. #3632

Closed
Southclaws opened this issue Oct 24, 2020 · 13 comments
Labels
closed: question This issue is a user error/misunderstanding.

Comments

@Southclaws
Copy link

馃悰 Bug Report

I upgraded to the latest version and got this

Error: Plugin docusaurus-plugin-google-analytics is used 2 times with id=default.
To use the same plugin multiple times on a Docusaurus site, you need to assign a unique id to each plugin instance.

Have you read the Contributing Guidelines on issues?

Yes

To Reproduce

Install google analytics plugin on a docusaurus instance (it might happen with other plugins but we only use the GA one)

Try it here https://github.com/openmultiplayer/wiki/ using commit 2b2321341d32121ff3195fc801d0831b1693ce10

I fixed it by giving the GA plugin an explicit ID: openmultiplayer/wiki@6fada68

Your Environment

  • Docusaurus version used: v2 alpha 66
  • Environment name and version (e.g. Chrome 78.0.3904.108, Node.js 10.17.0): latest stable node
  • Operating system and version (desktop or mobile): windows and vercel, so linux I think
@Southclaws Southclaws added bug An error in the Docusaurus core causing instability or issues with its execution status: needs triage This issue has not been triaged by maintainers labels Oct 24, 2020
@slorber
Copy link
Collaborator

slorber commented Oct 26, 2020

Hi,

If you use the classic preset with googleAnalytics themeConfig, you already use the google analytics plugin, as it's included in the preset.

So you actually have 2 instances of the google analytics plugin running on your site, which is likely not something you want right?

I'll improve the error message to make this clearer

@slorber slorber closed this as completed Oct 26, 2020
@Southclaws
Copy link
Author

Southclaws commented Oct 26, 2020

Ah, I didn't know it was added by default now. Thanks!

@slorber
Copy link
Collaborator

slorber commented Oct 27, 2020

it is added only when your preset classic has the googleAnalytics config attribute

@gulien
Copy link
Contributor

gulien commented Dec 17, 2020

Hello @slorber,

Sorry to comment on this closed issue, but I wonder where to put exactly the googleAnalytics config with preset classic?

I've tried:

presets: [
    [
      '@docusaurus/preset-classic',
      {
        themeConfig: {
          googleAnalytics: {
            trackingID: 'XXX',
            // Optional fields.
            anonymizeIP: true, // Should IPs be anonymized?
          },
        },
      },
    ],
  ],

And:

presets: [
    [
      '@docusaurus/preset-classic',
      {
        googleAnalytics: {
          trackingID: 'XXX',
          // Optional fields.
          anonymizeIP: true, // Should IPs be anonymized?
        },
      },
    ],
  ],

And:

module.exports = {
  themeConfig: {
    googleAnalytics: {
      trackingID: 'XXX',
      // Optional fields.
      anonymizeIP: true, // Should IPs be anonymized?
     },
  },
}

But no success so far 馃槃

Version: 2.0.0-alpha.69

Thank you for your help!

@slorber
Copy link
Collaborator

slorber commented Dec 17, 2020

https://v2.docusaurus.io/docs/api/plugins/@docusaurus/plugin-google-analytics/#configuration

this one should work:

module.exports = {
  themeConfig: {
    googleAnalytics: {
      trackingID: 'XXX',
      // Optional fields.
      anonymizeIP: true, // Should IPs be anonymized?
     },
  },
}

Note: it is only enabled on the production build, so you'll have to use docusaurus build && docusaurus serve to test that

@gulien
Copy link
Contributor

gulien commented Dec 17, 2020

Thanks @slorber for the quick answer. 馃槈

The "working" solution was the one I tried first but alas it did not and still do not work.

I'm using a GitHub workflow to deploy my documentation on the gh-pages branch. It runs the following instructions at the end:

yarn install --frozen-lockfile
yarn deploy

So either:

Thanks for your time! 馃槃

@slorber
Copy link
Collaborator

slorber commented Dec 17, 2020

@gulien I will only be able to help you if you provide me a repro using the config I gave you + a live deployment where I can indeed see it does not work.

@gulien
Copy link
Contributor

gulien commented Dec 17, 2020

My bad the documentation source code is located here:
https://github.com/thecodingmachine/symfony-boilerplate/tree/master/docs

And the documentation is available here: https://thecodingmachine.github.io/symfony-boilerplate/

@slorber
Copy link
Collaborator

slorber commented Dec 17, 2020

This works, as you can see

image

@gulien
Copy link
Contributor

gulien commented Dec 17, 2020

Ok so GA do not show anything, so I guess I actually did not configura GA correctly on my side...
Sorry for that, have a nice day :)

@slorber
Copy link
Collaborator

slorber commented Dec 17, 2020

that's probably it yes :) afaik it works on RN website

aridyckovsky added a commit to startyourlab/website that referenced this issue Apr 8, 2021
ggicci added a commit to ggicci/httpin that referenced this issue Nov 30, 2021
@Josh-Cena Josh-Cena added closed: question This issue is a user error/misunderstanding. and removed bug An error in the Docusaurus core causing instability or issues with its execution status: needs triage This issue has not been triaged by maintainers labels Mar 22, 2022
@adsazad
Copy link

adsazad commented Apr 24, 2022

I am using @docusaurus/preset-classic, in my case, it is not collecting data. I tried to google analytics as well as gtag method but neither one is working.

@slorber
Copy link
Collaborator

slorber commented Apr 27, 2022

@adsazad there were changes recently on this (config was moved from themeConfig to plugin options), and we can't help if you don't provide your docusaurus version and provide more context

If you follow the official doc of your exact docusaurus version (not production doc), you should be able to make it work and see GA requests in the network tab

Also note that Google launched Google Analytics 4, to progressively replace all the former analytics generations, and we don't support that yet. There's an issue to support it here: #7221

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
closed: question This issue is a user error/misunderstanding.
Projects
None yet
Development

No branches or pull requests

5 participants