Tutorial

Google Analytics has gone through a number of changes over the years. If you have been using it for along time you might remember the older Urchin tracking code. Then, they added a lighter Asynchronous code and for a while you were given the option of using one or the other. Now if you are new or login to your Google Analytics account the only option available seems to be the Asynchronous code.


When Google still had the Urchin code available they recommended adding it to the bottom of your page before the closing </body> tag.

The Asynchronous code they recommend adding it near the top before the closing </head> tag.

You can add the newer Asynchronous tracking code to either location. Near the top before the </head> tag or near the end before the closing </body> tag. It really doesn't matter and both locations will work.

You can check this page for more details if interested:
http://www.google.com/support/analytics/bin/answer.py?hl=en_US&answer=174090&utm_id=ad

On that page you will find:

For the best performance across all browsers we suggest you position other scripts in your site in one of these ways:

before the tracking code snippet in the <head> section of your HTML
after both the tracking code snippet and all page content (e.g. at the bottom of the HTML body) ie before </body>

*One of the main advantages of the asynchronous snippet is that you can position it at the top of the HTML document. This increases the likelihood that the tracking beacon will be sent before the user leaves the page. It is customary to place JavaScript code in the <head> section, and we recommend placing the snippet at the bottom of the <head> section for best performance.


What they don't tell you about adding it to the top of the page before </head> is that if Google Analytics is messing up or running slow it is much more likely that your site or page will hang right from the beginning since it will be some of the first code to load. Analytics doesn't mess up, run slow or hang very often, but it does happen.

Also if you happen to have a lot of heavy .js or .css in your header (<head> and </head>) already you may not want to add more.

For some it is just a matter of preference. I have been using Analytics for along time and I have always put the code at the bottom of the page before </body>.

Bottom line is you can use either location. Just make sure you only put the code in one location or the other. Do not put it in both or it will mess up your stats.



How To Add Google Analytics to Dolphin 7 Newer Asynchronous Code


Dolphin 7 Footer Method / Location

In the footer before </body> tag

Open /templates/base/_footer.html

Add the Asynchronous Google Analytics code:

<bx _ injection:injection _ footer />
<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>
</body>
</html>

Save the changes back to your hosting account.



Dolphin 7 Header Method / Location

In the header between <head> and </head> tags

Open /templates/base/_header.html

Add the Asynchronous Google Analytics code:

<bx _ injection:injection _ head />

<script type="text/javascript">
var oBxUserStatus = new BxUserStatus();
oBxUserStatus.userStatusInit('<bx _ url _ root />', __ is _ profile _ page __);
</script>
<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>
__ flush _ header __
<body <bx _ injection:injection _ body /> >
<bx _ injection:injection _ header />
<div id="notification _ window" class="notifi _ window"></div>
<div id="FloatDesc" style="position:absolute;display:none;z-index:100;"></div>

Save the changes back to your hosting account.



Clear Dolphin 7 Cache

Login to your Dolphin 7 Administration panel and clear template cache for the changes to take effect.

Visit and refresh your homepage.

View source / View page source with your favorite browser and verify the Google Analytics code is present.

Wait 24 hours for stats to update and start reporting.




How To Add Google Analytics to Dolphin 7 Older Urchin Code


In the footer before </body> tag

Open /templates/base/_footer.html


<bx _ injection:injection _ footer />
<script src="http://www.google-analytics.com/urchin.js" type="text/javascript">
</script>
<script type="text/javascript">
_uacct = "UA-XXXXX-X";
urchinTracker();
</script>
</body>
</html>

Save the changes back to your hosting account.



Clear Dolphin 7 Cache

Login to your Dolphin 7 Administration panel and clear template cache for the changes to take effect.

Visit and refresh your homepage.

View source / View page source with your favorite browser and verify the Google Analytics code is present.

Wait 24 hours for stats to update and start reporting.

 
Written By
Tutorial by: Jeremy LeSarge (AKA Ray)

I am the owner and administrator of DialMe.com. I write Tutorials for Boonex Dolphin as well as tips and resources surrounding website programming and development. I enjoy working with WordPress, SEO, and Web Hosting / Servers. I also maintain a WordPress Blog here on this site where you will find a variety of technology and webmaster resources.

Actions
Sponsored Links
Recommend