Quantcast
Channel: Piwik Forums - Support & Bugs
Viewing all articles
Browse latest Browse all 13117

Re: Accessing Piwik singleton when using async tracker

$
0
0
Loading it as a callback using onload seems to work:

//example callback
var loadCallback = function(){console.log(Piwik)};

  var d=document, g=d.createElement("script"), s=d.getElementsByTagName("script")[0]; g.type="text/javascript";
        g.defer=true; g.async=true; g.src=u+"piwik.js";

        //add the onload callback, with support for IE8 as a fallback
        if (!g.addEventListener) {
            g.attachEvent("onload", loadCallback);
        }
        else {
            g.addEventListener("load", loadCallback, false);
        }
        
        s.parentNode.insertBefore(g,s);

Viewing all articles
Browse latest Browse all 13117

Trending Articles