There are two ways to use this code.
- Place the code below before the </head> tag.
<script type="text/javascript"> var _gaq = _gaq || []; _gaq.push(['_setAccount', 'UA-XXXXX-X']); _gaq.push(['_trackPageview']); (function() { var ga = document.createElement('script'); ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js'; ga.setAttribute('async', 'true'); document.documentElement.firstChild.appendChild(ga); })(); </script>
- Split the code. Half of the code will be put before the </head> tag. Another half will be put at the end of the page, before the </body> tag.
The first half (before </head> the tag).
The second half (before </body> the tag).<script type="text/javascript"> var _gaq = _gaq || []; _gaq.push(['_setAccount', 'UA-XXXXX-X']); _gaq.push(['_trackPageview']); </script>
<script type="text/javascript"> (function() { var ga = document.createElement('script'); ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js'; ga.setAttribute('async', 'true'); document.documentElement.firstChild.appendChild(ga); })(); </script>
Note:
- Remove any existing Google Analytics code before using this asynchronous code.
- Disable any Google Analytics plugin (if you use one) for WordPress.
- Replace UA-XXXXX-X with your web property ID.