Ripped from AppFusions - as this Add special parameters to GA.

<!--GOOGLE-ANALYTICS-PLUGIN-START-->
<!-- Updated: 2015-08-18 20:20:29 -->
<script type="text/javascript">
    // Disable any trackers that Atlassian may have added
    for (i=0; i < 50; i++) {  // normally it's 14, but let's use a hammer to kill any new ones too.
        window['ga-disable-UA-xxxxxx-'+i] = true;
    }
    var _gaq = _gaq || [];
    _gaq.push(['af._setAccount', 'UA-xxxxxx-1']); 
    AJS.toInit(function(){
        // set custom variables
        setCustomVarSpaceKey(); 
        setCustomVarUserKey();  
        if (typeof AJS.params.pageId === 'string') {
            _gaq.push(
                    ['af._setCustomVar', 3, 'confluence-page-id', AJS.params.pageId, 3 ],             
                    ['af._setCustomVar', 4, 'confluence-content-type', AJS.params.contentType, 3 ],   
                    ['af._set', 'title', AJS.params.pageTitle]                                        
            );
        }
        // track page view
        _gaq.push(['af._trackPageview']); 
        AJS.$("a[href*='/download/attachments/']").click(function(event) { 
            event.preventDefault();
            var pageIdAttachmentName = this.pathname.substring(this.pathname.indexOf('/download/attachments/') + 23);
            var parts = pageIdAttachmentName.split('/');
            // set custom variables
            setCustomVarSpaceKey(); 
            setCustomVarUserKey();  
            _gaq.push(
                    ['af._setCustomVar', 3, 'confluence-page-id', parts[0], 3 ],            
                    ['af._setCustomVar', 4, 'confluence-content-type', 'attachment', 3 ],   
                    ["af._set", "title", decodeURIComponent(parts[1])],                     
                    ['af._setReferrerOverride', location.href]                              
            );
            var attachmentUrl = AJS.$(this).attr('href');
            // track page views
            _gaq.push(['af._trackPageview', attachmentUrl]);
            setTimeout(function() { document.location.href = attachmentUrl; }, 500);
        }); 
        (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);
        })();
    });
    function setCustomVarSpaceKey() {
        if (typeof AJS.params.spaceKey === 'string') {
            _gaq.push(['af._setCustomVar', 1, 'confluence-space-key', AJS.params.spaceKey, 3 ]); 
        }
    }
    function setCustomVarUserKey() {
        if (typeof AJS.params.userKey === 'string') {
            _gaq.push(['af._setCustomVar', 2, 'confluence-user-key', AJS.params.userKey, 1 ]);        
        }
    }
</script>
<!--GOOGLE-ANALYTICS-PLUGIN-END-->