Piwik延迟加载脚本

时间:2023-03-10 02:08:42
Piwik延迟加载脚本

piwik有时候会卡页面,为了不影响页面,可以将Piwik代码放到最后加载

  <!-- Piwik -->
<script type="text/javascript">
function addLoadEvent(func) {
window.addEventListener && window.addEventListener("load", func, false);
window.attachEvent && window.attachEvent("onload", func);
} addLoadEvent(function () {
var pkBaseURL = "http:/。。。。。/piwik/";
var piwikScript = window["document"]["createElement"]("script");
piwikScript["type"] = "text/javascript";
piwikScript["charset"] = "utf-8";
piwikScript["defer"] = "defer";
piwikScript["onload"] = function () {
try {
var piwikTracker = Piwik.getTracker(pkBaseURL + "piwik.php", );
piwikTracker.trackPageView(); piwikTracker.enableLinkTracking();
} catch (err) { }
};
piwikScript["src"] = pkBaseURL + "piwik.js";
document.head.appendChild(piwikScript);
});
</script>
<!-- End Piwik Code -->