I have a simple problem. My site uses Google Analytic and the Analytic ID needs to be stored inside the settings of my .NET project. If the setting is empty, Analytic needs to be disabled. During deployment, the installation will ask for this ID and put it in the settings.
Google Analytic uses a bit of JavaScript and basically, this script needs to read the value from the settings. Unfortunately, the JavaScript is executed client-side while the setting resides on the server.
So I need a simple trick to read this ID on the server and get it included somehow in the resulting web page.
Hints on disabling Google Analytics if no ID has been provided are useful, but I don’t think that would be too complex. (Just don’t load the ga.js file from Google.) I might use something like <script runat="server" ID="Analytic" and set the URL (src tag) if there’s an ID. But if someone has a better suggestion, go ahead.
You can use the following solution:
Server-side (Ex: Getting AnalyticID from Settings static class):
Client-side (Ex: Using AnalyticID on the client side)