[jQuery] Load Google Analytics from jQuery
Hello!
I guess if any of you have tried to load Google Analytics from JQuery.
What I want to do is as simple as this:
My original footer:
************ footer.php ************
<div id="footer">something</div>
</body>
</html>
************ /footer.php ************
Instead of put the Google Analytics on the footer, I want to include
the coce before DOM is loaded:
************ header.php ************
[...]
<script type="text/javascript" src="/media/js/jquery.js"></script>
<script type="text/javascript">
$(document).ready(function(){
// analytics code (end of page)
$('div#footer').after("\n\n<script src='http://www.google-
analytics.com/urchin.js' type='text/javascript'></script>\n" +
"<script type='text/javascript'>\n" +
"\t_uacct = 'UA-2158413-2'\n" +
"\turchinTracker();\n" +
"</
script>");
});</script>
************ header.php ************
That way, when the DOM is loaded, my footer should look like this:
************ mywebsite ************
[...]
<div id="footer">something</div>
<script style="display: none;" src="http://www.google-analytics.com/
urchin.js" type="text/javascript"></script>
<script type="text/javascript">
_uacct = 'UA-2158413-2'
urchinTracker();
</script>
</body>
</html>
************ /mywebsite ************
I have tried, but google doesn't seem to understand that the JS it's
been loaded, even it's not "on the page".
Thanks for reading!!
Skullman