Files
kennethreitz.org/data/essays/2009-01-asynchronous_google_analytics.md
kennethreitz 0b2c6164ed Clean migration artifacts from 33 old essays (2008-2016)
Remove third-person sidenotes ("Kenneth's work..."), anachronistic
cross-links to 2025 essays, injected bridge paragraphs, and
over-annotation from short blog posts. Restore original first-person
voice across all pre-2017 content.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-24 17:22:32 -04:00

29 lines
1.0 KiB
Markdown

# Asynchronous Google Analytics!
*January 2009*
Google Analytics now supports Asynchronous loads, which allow the browser to continue loading content while **ga.js** is being loaded. Now it's safe to put the script tag in the `<head>` for you XHTML STRICT junkies.
**Here's the new code to do so:**
```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);
})();
```
## WordPress Plugin Update
I love this new code clip so much, I decided to write a WordPress Plugin for it. Enjoy!
* [GitHub Project Page](http://github.com/kennethreitz/async-google-analytics-wordpress-plugin)
* [Direct WordPress Plugin](http://github.com/kennethreitz/async-google-analytics-wordpress-plugin/zipball/master)