0

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

notidaho
  • 588
  • 8
  • 28
  • https://stackoverflow.com/questions/49419250/is-sharing-google-analytics-tracking-id-safe – fuzzybear Mar 23 '22 at 16:09
  • Does this answer your question? [Is sharing Google Analytics tracking id safe?](https://stackoverflow.com/questions/49419250/is-sharing-google-analytics-tracking-id-safe) – fuzzybear Mar 23 '22 at 16:11

1 Answers1

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.

Deepak-MSFT
  • 10,379
  • 1
  • 12
  • 19