Adding Google Analytics to Online Documentation

It's quite common to have Google Analytics or some other analytics engine to determine traffic on your content.

It's easy to add this functionality to each of your help file's topics by adding the Google Analtics script to the bottom of the _layout.wcs template.

For example:

    if(!helpBuilder.isLocalUrl()) {
        // *** Your analytics or other script(s)
        (function (i, s, o, g, r, a, m) {
            i['GoogleAnalyticsObject'] = r; i[r] = i[r] || function () {
                (i[r].q = i[r].q || []).push(arguments)
            }, i[r].l = 1 * new Date(); a = s.createElement(o),
            m = s.getElementsByTagName(o)[0]; a.async = 1; a.src = g; m.parentNode.insertBefore(a, m)
        })(window, document, 'script', '//', 'ga');
        ga('create', 'YOUR_ID HERE', 'YOURSITE.COM');
        ga('send', 'pageview');

Local Script Warning

Note the if (!helpBuilder.isLocalUrl()) wrapper. This block is required to avoid loading the script on local HTML display inside of Help Builder while editing, and in HTML Help (CHM) files which causes hanging problems. Make sure you always include the wrapper for any external script loaded to avoid problems with local script execution.

© West Wind Techologies, 1996-2019 • Updated: 01/18/16
Comment or report problem with topic