Run track code after page load


#1

Good day, I need run track code after html code of page loaded, because I need parse some information from page.
For this I try use window.onload and jquery.

But with this function piwik track code doesn’t working


$(window).load(function () {

  var _paq = _paq || [];
  var fioparse = document.querySelector("#UserInfo_UserName").innerText;
  alert (fioparse);

  _paq.push(['trackPageView']);
  _paq.push(['enableLinkTracking']);
  (function() {
    var u="URL TO SITE";
    _paq.push(['setTrackerUrl', u+'piwik.php']);
    _paq.push(['setSiteId', 14]);
    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);
  })();
});

This code working good


  var _paq = _paq || [];
  var fioparse = document.querySelector("#UserInfo_UserName").innerText;
  alert (fioparse);

but next doesn’t :’(


_paq.push(['trackPageView']);
  _paq.push(['enableLinkTracking']);
  (function() {
    var u="URL TO SITE";
    _paq.push(['setTrackerUrl', u+'piwik.php']);
    _paq.push(['setSiteId', 14]);
    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);
  })();