question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[gatsby-plugin-google-analytics] trackingId is required in development after upgrading to 3.0.0

See original GitHub issue

Description

Using gatsby-plugin-google-analytics, it is noted in the docs that:

Note that this plugin is disabled while running gatsby develop. This way, actions are not tracked while you are still developing your project. Once you run gatsby build the plugin is enabled. Test it with gatsby serve.

Personally I keep my GA tracking id in netlify environment variable so it’s only available at build time. After upgrading to version 3.0.0 I get the following error message in development

ERROR #11331 PLUGIN

Invalid plugin options for “gatsby-plugin-google-analytics”:

  • “trackingId” is required

Steps to reproduce

  • Install gatsby-plugin-google-analytics version 3.0.0
  • Start development process with npm start

Expected result

The plugin should allow empty / undefined trackingId in development.

Actual result

Error is thrown and development process is stopped.

Environment

System: OS: Windows 10 10.0.19042 CPU: (8) x64 Intel® Core™ i7-8550U CPU @ 1.80GHz Binaries: Node: 14.15.1 - C:\Program Files\nodejs\node.EXE npm: 6.14.8 - C:\Program Files\nodejs\npm.CMD Browsers: Edge: Spartan (44.19041.423.0), Chromium (88.0.705.81) npmPackages: gatsby: ^3.0.0 => 3.0.0 gatsby-plugin-google-analytics: ^3.0.0 => 3.0.0 gatsby-plugin-image: ^1.0.0 => 1.0.0 gatsby-plugin-manifest: ^3.0.0 => 3.0.0 gatsby-plugin-mdx: ^2.0.0 => 2.0.0 gatsby-plugin-netlify: ^3.0.0 => 3.0.0 gatsby-plugin-offline: ^4.0.0 => 4.0.0 gatsby-plugin-react-helmet: ^4.0.0 => 4.0.0 gatsby-plugin-robots-txt: ^1.5.5 => 1.5.5 gatsby-plugin-sharp: ^3.0.0 => 3.0.0 gatsby-plugin-sitemap: ^3.0.0 => 3.0.0 gatsby-plugin-styled-components: ^4.0.0 => 4.0.0 gatsby-remark-autolink-headers: ^3.0.0 => 3.0.0 gatsby-remark-copy-linked-files: ^3.0.0 => 3.0.0 gatsby-remark-embedder: ^4.1.0 => 4.1.0 gatsby-remark-images: ^4.0.0 => 4.0.0 gatsby-remark-prismjs: ^4.0.0 => 4.0.0 gatsby-source-filesystem: ^3.0.0 => 3.0.0 gatsby-transformer-sharp: ^3.0.0 => 3.0.0

I would like to submit a PR if needed (with maybe a little help of getting around) 🚀

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:6 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
wardpeetcommented, Mar 2, 2021

You can use this pattern

const dynamicPlugins = [];
if (process.env.GA) {
  dynamicPlugins.push({
    resolve: 'gatsby-plugin-analytics',
    options: {
      trackingId: process.env.GA
    }
  })
}

module.exports = {
  // config
  plugins: [
    ...dynamicPlugins
  ]
}
1reaction
vladarcommented, Mar 2, 2021

I think this was intentional for the major bump: https://github.com/gatsbyjs/gatsby/pull/29413/files#diff-618b4bd7e0c4df7c7818d36a3f92517c9ceb898b635b72da933dc09ab7d4b9f8

But I don’t have enough context on it. CC @wardpeet @laurieontech

Read more comments on GitHub >

github_iconTop Results From Across the Web

[gatsby-plugin-google-gtag] Analytics isn't working #12967
gatsby-plugin-google-analytics : ^2.0.17 => 2.0.17 ... In addition, I think we also need to update a setting in Google Analytics admin as in ......
Read more >
gatsby-plugin-google-analytics - npm
js and we recommend it. Install. npm install gatsby-plugin-google-analytics. How to use. // In ...
Read more >
Capture Video Analytics in Gatsby.js Sites - Media Jams
The gatsby-plugin-google-analytics plugin doesn't send data to Google analytics in development. A production build is required. You can also ...
Read more >
gatsby/CHANGELOG.md - UNPKG
263, - **gatsby:** update nested input types when rebuilding SitePage ... 883, - **gatsby-plugin-google-analytics:** remove required on trackingId ...
Read more >
Getting started with Gatsby - DEV Community ‍ ‍
Gatsby will start a hot-reloading development environment accessible by ... We use gatsby-plugin-google-analytics to track site activity and ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found