Skip to content

chore: only load analytics scripts in production or staging environments #7644

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

Merged
merged 4 commits into from
May 22, 2024

Conversation

hbuchel
Copy link
Contributor

@hbuchel hbuchel commented May 21, 2024

Description of changes:

This PR changes it so our analytics scripts only load in production or staging environments. Before, we were loading the testing analytics scripts in all non production environments which caused a very noisy console for local development testing.

Testing (hosting)
https://removenonprodscripts.d2bfwhpcsj9awv.amplifyapp.com/

On this test site, my BUILD_ENV variable is set to "staging". So inspecting the DOM, you should see:

Screenshot 2024-05-22 at 2 48 23 PM Screenshot 2024-05-22 at 2 48 42 PM

Since this preview site's domain doesn't match up there will still be console errors related to those scripts in hosting.

Testing (local)
Currently, when testing locally, the console is very busy with errors related to CSP rules:

Screenshot 2024-05-22 at 1 28 59 PM

After this change the only error left is related to fetchPriority which was introduced in recent version of Next.js vercel/next.js#65161 This is fixed in their canary which currently requires bumping to React 19, so we'll have to wait to address that.

Screenshot 2024-05-22 at 1 27 21 PM

Additionally, there are no shortbread or awshome_s_code related scripts/css loaded.

Related GitHub issue #, if available:

Instructions

If this PR should not be merged upon approval for any reason, please submit as a DRAFT

Which product(s) are affected by this PR (if applicable)?

  • amplify-cli
  • amplify-ui
  • amplify-studio
  • amplify-hosting
  • amplify-libraries

Which platform(s) are affected by this PR (if applicable)?

  • JS
  • Swift
  • Android
  • Flutter
  • React Native

Please add the product(s)/platform(s) affected to the PR title

Checks

  • Does this PR conform to the styleguide?

  • Does this PR include filetypes other than markdown or images? Please add or update unit tests accordingly.

  • Are any files being deleted with this PR? If so, have the needed redirects been created?

  • Are all links in MDX files using the MDX link syntax rather than HTML link syntax?

    ref: MDX: [link](https://docs.amplify.aws/)
    HTML: <a href="https://docs.amplify.aws/">link</a>

When this PR is ready to merge, please check the box below

  • Ready to merge

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

@hbuchel hbuchel changed the title [DO NOT MERGE/POC]: Remove analytics scripts in non-prod environments chore: only load analytics scripts in production or staging environments May 22, 2024
@hbuchel hbuchel marked this pull request as ready for review May 22, 2024 18:57
@hbuchel hbuchel requested a review from a team as a code owner May 22, 2024 18:57
@hbuchel hbuchel merged commit 53f3df4 into main May 22, 2024
10 checks passed
@hbuchel hbuchel deleted the RemoveNonProdScripts branch May 22, 2024 20:30
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.

3 participants