Where Do I Place Google Analytics Code Inside a .ASPX Page?

Where Do I Place Google Analytics Code Inside .ASPX Page?

  • I just signed up with google analytics and I am trying to find where to add the tracking code on my page. I know how insert in basic html pages, I just have inherited a site that is a .aspx

  • Answer:

    You can insert it anywhere and it would work, as long as it's not inside an ASP.NET control. A good place to put it would be inside your Master Page file, if you have one (that way you just add the code once for your whole site). Many front-end developers recommend putting your script at the bottom of the page, so that if it breaks, your page will still work. I think the Google Analytics code should be pretty solid though, so you could place it in your HTML head section.

user1350722 at Stack Overflow Visit the source

Was this solution helpful to you?

Other answers

The tracking code is profile-specific, which is why you can only access it via the Profile Settings page for a specific profile. Please read Where can I find my tracking code? for full instructions. Below is an example of what the code snippet will look like. You'll need to update the "xxx-x" in the sample below with your own Google Analytic account number found in your personalized Google Analytic Tracking Code.

user1335543

Take the https://developers.google.com/analytics/devguides/collection/gajs/ code (available in your Google Analystics pages) and place it just inside the <head></head> element of your code: <head> <meta charset="utf-8" /> <link rel="stylesheet" type="text/css" href="/css/screen.css" /> <link rel="shortcut icon" href="/images/favicon.ico"> <script type="text/javascript"> var _gaq = _gaq || []; _gaq.push(['_setAccount', 'UA-XXXXX-X']); _gaq.push(['_trackPageview']); (function() { var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true; ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js'; var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s); })(); </script> </head> If you follow the link above, you'll see that you can split the script block, so that some of the code won't impact on the rendering of the page. However, you'll run the risk of losing some hits, if the user interacts with the page before the tracking code is loaded. So only do this if you have a specific need to do so.

CJM

Just Added Q & A:

Find solution

For every problem there is a solution! Proved by Solucija.

  • Got an issue and looking for advice?

  • Ask Solucija to search every corner of the Web for help.

  • Get workable solutions and helpful tips in a moment.

Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.