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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(gatsby-plugin-google-analytics): Don't create tracking code without an ID. #19592

Merged
merged 1 commit into from
Nov 18, 2019
Merged

fix(gatsby-plugin-google-analytics): Don't create tracking code without an ID. #19592

merged 1 commit into from
Nov 18, 2019

Conversation

laradevitt
Copy link
Contributor

@laradevitt laradevitt commented Nov 18, 2019

Hello, this is my first code-related PR.

Fixes #19479

There is no fancy string validation here; this fix just stops the tracking code from being created if (option) "trackingId" is empty or false. It also outputs a warning.

I'm not sure about my changes to tests. With this fix the existing tests now rely on "trackingId" being set, so I've made this the default while adding a new test that tests the opposite condition ("trackingId" is unset).

Edit: Fixed linked to related issue.

Copy link
Contributor

@wardpeet wardpeet left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks great! 😍 Thanks a bunch for adding this @laradevitt. This PR is 💯

@wardpeet wardpeet merged commit e883487 into gatsbyjs:master Nov 18, 2019
@muescha
Copy link
Contributor

muescha commented Nov 19, 2019

Should there also a warning if there is the default YOUR_GOOGLE_ANALYTICS_TRACKING_ID ?

(If I search over Gatsby Repo issues I see some gatsby-configs with this and if I search over GitHub also many starters with it)

@laradevitt
Copy link
Contributor Author

laradevitt commented Nov 20, 2019

@muescha - I looked around and I couldn't find any issues where the example ID given in the README is a problem. Or am I misunderstanding?

You have me thinking about this, though. Since people copy-and-paste the example I'm not crazy about having anything other than the actual sensible defaults there. And do we really need to scream YOUR_GOOGLE_ANALYTICS_TRACKING_ID for people to understand what goes there? I don't think so.

(This goes for all of the option properties that need an ID.)

@muescha
Copy link
Contributor

muescha commented Nov 20, 2019

i see many people leave exactly this text in the code (see issues #4693 #8099 #1449) or in code base like this search shows many places: Github Code Search for 'YOUR_GOOGLE_ANALYTICS_TRACKING_ID'

ok - leave it as it is - so people don't think the plugin is not working.

@laradevitt
Copy link
Contributor Author

I agree that this is potentially problematic but unfortunately if we implemented that check here we would have to do it for all of the plugins that do the same thing. I think a better solution might be to be more careful in how we document examples, since people do tend to just copy-and-paste into the config file, but that's a whole issue in itself. 🤷‍♀

@muescha
Copy link
Contributor

muescha commented Nov 23, 2019

🤷‍♀ yes you are right.

only soulution would be to use a process.env.YOUR_GOOGLE_ANALYTICS_TRACKING_ID then the value would be null, the user is pointed a little bit into the direction that he need to secure his settings. but this makes the examples also more complicated.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[gatsby-plugin-google-analytics] GA scripts are loaded even when 'trackingId' is invalid.
3 participants