Gemini
Gemini

Reputation: 15

Google analytics Code Placing in head tag in master page?

Here is the code in the head of my master page ...

<link rel="stylesheet" type="text/css" href="App_Themes/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>

but when i see it in the browser view source ... it is showing it like this

<link rel="stylesheet" type="text/css" href="App_Themes/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>
   <link href="App_Themes/Site/style.css" type="text/css" rel="stylesheet" />

You notice there is a theme rendering at the end App_Themes/Site/style.css before the tag ... please tell me how can i fix it ... I need google analytics code before the tag ... but this theme rendering at the end forbids me to achieve my goal ...

Upvotes: 0

Views: 3597

Answers (1)

Darren Wainwright
Darren Wainwright

Reputation: 30737

I am going to guess you're using ASP.Net Themes?

ASP.Net renders your Theme and adds the style to the page.

Your best place to put the Google code is at the bottom of the page just before the </body> tag.

Google in fact recommends that it go just before the closing body tag, as documented here after the standard setup snippet

https://developers.google.com/analytics/devguides/collection/gajs/gaTrackingOverview

Upvotes: 1

Related Questions