Lack of interest A better template for Google Analytics, current cannot be extended

This suggestion has been closed automatically because it did not receive enough votes over an extended period of time. If you wish to see this, please search for an open suggestion and, if you don't find any, post a new one.

Rigel Kentaurus

Well-known member
The template used for Google Analytics, while good, is not extensible. A better one would be this

Code:
<xen:if is="{$xenOptions.googleAnalyticsWebPropertyId}"><script>
 
    var _gaq = [['_setAccount', '{$xenOptions.googleAnalyticsWebPropertyId}']];
    <xen:hook name="google_analytics_before" />   
    _gaq.push(['_trackPageview']);
    <xen:hook name="google_analytics_after" />
 
    !function(d, t)
    {
        var g = d.createElement(t),
            s = d.getElementsByTagName(t)[0];   
        g.async = true;
        g.src = ('https:' == d.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
        s.parentNode.insertBefore(g, s);
    }
    (document, 'script');
 
    </script><xen:comment><!--Adapted from http://mathiasbynens.be/notes/async-analytics-snippet--></xen:comment></xen:if>

This template adds two hooks before and after _trackPageview, this is necessary because there are some operations that need to be done before trackPageView (like custom vars for segments), and some that can be done after (like pageSpeed)
 
Upvote 1
This suggestion has been closed. Votes are no longer accepted.
Top Bottom