mirror of
https://github.com/fergalmoran/dss.git
synced 2026-03-26 07:28:10 +00:00
Made GA async
This commit is contained in:
@@ -1,10 +1,12 @@
|
||||
from django import template
|
||||
from dss import settings
|
||||
|
||||
register = template.Library()
|
||||
|
||||
|
||||
class ShowGoogleAnalyticsJS(template.Node):
|
||||
def render(self, context):
|
||||
code = getattr(settings, "GOOGLE_ANALYTICS_CODE", False)
|
||||
code = getattr(settings, "GOOGLE_ANALYTICS_CODE", False)
|
||||
if not code:
|
||||
return "<!-- Goggle Analytics not included because you haven't set the settings.GOOGLE_ANALYTICS_CODE variable! -->"
|
||||
|
||||
@@ -15,13 +17,17 @@ class ShowGoogleAnalyticsJS(template.Node):
|
||||
return "<!-- Goggle Analytics not included because you are in Debug mode! -->"
|
||||
|
||||
return """
|
||||
<script type="text/javascript">
|
||||
var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
|
||||
document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));
|
||||
</script>
|
||||
<script type="text/javascript">
|
||||
try {
|
||||
var pageTracker = _gat._getTracker('""" + str(code) + """');
|
||||
pageTracker._trackPageview();
|
||||
} catch(err) {}</script>
|
||||
<script type="text/javascript">
|
||||
|
||||
var _gaq = _gaq || [];
|
||||
_gaq.push(['" _setAccount', '""" + str(code) + """']);
|
||||
_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>
|
||||
"""
|
||||
Reference in New Issue
Block a user