Clone wiki

analytics-info / Home

Google Analytics, Piwik & more for JIRA and Confluence

This is documentation for Analytics plugin for JIRA and Confluence

Marketplace Location

JIRA plugin is accessible under url: https://marketplace.atlassian.com/plugins/ovh.dwa.jira.jira-analytics/cloud/overview

Confluence will accessible under url: https://marketplace.atlassian.com/plugins/ovh.dwa.confluence.confluence-analytics/cloud/overview

Analytics settings location

In Confluence "Settings" > "Confguration" > "Analytics for Confluence"

In JIRA "Jira Administration" > "Advanced" > "Analytics for JIRA"

Custom code

Your reporting code will run inside iframe in dwa.ovh domain. To make analytics tool work properly you have to obtain real page url. You can access real url using JavaScript Atlassian Connect API calling AP.getLocation.

To load JavaScript Atlassian Connect API in your custom script you can use this code:

<script>
    (function () {
        var baseUrl = getUrlParam('xdm_e') + getUrlParam('cp');
        var script = loadScript(baseUrl + '/atlassian-connect/all.js', bridgeLoaded);

        function bridgeLoaded() {
            AP.getLocation(function (location) {
                // Here should go custom code 
            });
        }

        function getUrlParam(param) {
            var codedParam = (new RegExp(param + '=([^&]*)')).exec(window.location.search)[1];
            return decodeURIComponent(codedParam);
        }

        // this function will work cross-browser for loading scripts asynchronously
        function loadScript(src, callback) {
            var s,
                r;
            r = false;
            s = document.createElement('script');
            s.type = 'text/javascript';
            s.src = src;
            s.onload = s.onreadystatechange = function () {
                //console.log( this.readyState ); //uncomment this line to see which ready states are called.
                if (!r && (!this.readyState || this.readyState == 'complete')) {
                    r = true;
                    callback();
                }
            };
            document.getElementsByTagName("head")[0].appendChild(s);
            return s;
        }
    })();

</script>

This example will report to Google Analytics and Piwik at the same time:

<script>
    (function () {
        var baseUrl = getUrlParam('xdm_e') + getUrlParam('cp');
        var script = loadScript(baseUrl + '/atlassian-connect/all.js', bridgeLoaded);

        function bridgeLoaded() {
            AP.getLocation(function (location) {
                // My custom reporting

                // Google Analytics
                (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','https://www.google-analytics.com/analytics.js','ga');

                ga('create', '${GA_ID}', 'auto');
                ga('set', 'location', location);
                ga('send', 'pageview');


                // Piwik
                window._paq = window._paq || [];
                _paq.push(['trackPageView']);
                (function() {
                    var u="${PIWIK_TRACKER_URL}";
                    _paq.push(['setTrackerUrl', u+'piwik.php']);
                    _paq.push(['setSiteId', '${SITE_ID}']);
                    _paq.push(['setCustomUrl', location]);
                    var d=document, g=d.createElement('script'), s=d.getElementsByTagName('script')[0];
                    g.type='text/javascript'; g.async=true; g.defer=true; g.src=u+'piwik.js'; s.parentNode.insertBefore(g,s);
                })();
            });
        }

        function getUrlParam(param) {
            var codedParam = (new RegExp(param + '=([^&]*)')).exec(window.location.search)[1];
            return decodeURIComponent(codedParam);
        }

        // this function will work cross-browser for loading scripts asynchronously
        function loadScript(src, callback) {
            var s,
                r;
            r = false;
            s = document.createElement('script');
            s.type = 'text/javascript';
            s.src = src;
            s.onload = s.onreadystatechange = function () {
                //console.log( this.readyState ); //uncomment this line to see which ready states are called.
                if (!r && (!this.readyState || this.readyState == 'complete')) {
                    r = true;
                    callback();
                }
            };
            document.getElementsByTagName("head")[0].appendChild(s);
            return s;
        }
    })();

</script>

Updated