Passing username into Web Analytics - SOLVED

Hi guys, anyone knows how to pass the HTMLEXE username string using
<script language="JavaScript">document.write(window.external.GetGlobalVariable('HEPubUserName', ''));</script> into the script below. It’s web analytics but I want to be able to use the username from the publication in the analytics without manually typing in name for every publication.

  <script type="text/javascript">
      var _paq = _paq || [];
      /* tracker methods like "setCustomDimension" should be called before "trackPageView" */
      _paq.push(["setDocumentTitle", document.domain + "/" + document.title]);
      _paq.push(["setCookieDomain", "*.heserver"]);
      _paq.push(["setDomains", ["*.heserver"]]);
      // you can set up to 5 custom variables for each visitor
      _paq.push(["setCustomVariable", 1, "Username", "John Doe", "visit"]);
      _paq.push(['trackPageView']);
      _paq.push(['enableLinkTracking']);
      (function() {
        var u="//wvmref.com/piwik/piwik/";
        _paq.push(['setTrackerUrl', u+'piwik.php']);
        _paq.push(['setSiteId', '1']);
        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);
      })();
    </script>
<script type="text/javascript">
      var _paq = _paq || [];
      /* tracker methods like "setCustomDimension" should be called before "trackPageView" */
      _paq.push(["setDocumentTitle", document.domain + "/" + document.title]);
      _paq.push(["setCookieDomain", "*.heserver"]);
      _paq.push(["setDomains", ["*.heserver"]]);
      // you can set up to 5 custom variables for each visitor
      _paq.push(["setCustomVariable", 1, "Username", window.external.GetGlobalVariable('HEPubUserName', ''), "visit"]);
      _paq.push(['trackPageView']);
      _paq.push(['enableLinkTracking']);
      (function() {
        var u="//wvmref.com/piwik/piwik/";
        _paq.push(['setTrackerUrl', u+'piwik.php']);
        _paq.push(['setSiteId', '1']);
        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);
      })();
    </script>

Note that you may have legal privacy problems: be sure to inform your users that you do that in a privacy policy or EULA for instance.

Thank you it worked. Yes the software i’m using has “opt-in” option for users, so before the tracking a box will show users the reason for it and give them the option to allow it or not. Thanks again:slight_smile: