'Can/should I hide my Google Analytics Measurement ID in the site config

I need to add the latest Google Analytics (GA4) script to a site, for the business.

enter image description here It is an ASP.NET Core MVC webapp so it's going in the _layout page.

There a few potential issues I see with the Measurement ID:

  • It is visible to the public via the page source (so anyone could track the stats)
  • It would require a code change if the production ID needs to change
  • There is no difference between IDs for the development vs production environment

enter image description here

My question(s) is:

  • In general is it worth putting the Measurement ID in to a config to alleviate the above conerns?
  • What would the best practice way of achieving this e.g. appsettings.json, user secret?

Many thanks



Solution 1:[1]

For general scenarios, you could try to save it in the appsettings.json file. For storing sensitive data, I would suggest you use Azure Key Vault.

For more detailed information, you could refer to this helpful article.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Deepak-MSFT