1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

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

Discussion in 'Closed Suggestions' started by Rigel Kentaurus, Nov 26, 2011.

  1. Rigel Kentaurus

    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)
     
    Claudio likes this.

Share This Page