awstats_misc_tracker.js

veit
2007-02-17
2012-10-11
  • veit
    veit
    2007-02-17

    Hi.

    I'm using awstats in a JSF webapp which is located at a contextroot under a top-level domain like:

    http://main-domain.foo/mywebapp

    Apache in front with mod_jk connected to a localhost tomcat installation.

    Now I have a problem with awstats combined with awstats_misc_tracker.js in this environment.

    Since I host different version of the application under different contextroots, the static variable:

    awstatsmisctrackerurl

    in awstats_misc_tracker.js is a problem for me. Since it must point to a static variable, it won't work with different
    contextroots (awstats is included in the webapp). In my page, where awstats_misc_tracker.js is called, I have access to the current contextroot and I could set it here.
    But since awstats_misc_tracker.js uses it's own hardcoded url path, and creates a img tag with this url, the contextroot won't match the "real"
    url. That leads to missing/loosing JSESSIONID cookie information - since the contextroot is different.

    I could do automatic search/replace on build-time, but that's isn't really a good solution.

    What about the idea, that the awstats_misc_tracker.js will take the contextroot part of it's <script ... src> call for building the awstatsmisctrackerurl? That would be consistent and more transparent than the current solution.

    Any comments?

    regards,
    Veit

     
    • Meanwhile I created a patch like I suggested above. I put this

      <code>
      // if not explicitly specified, use caller url
      if (typeof(awstatsmisctrackerurl)=="undefined") {
      var scripts = document.getElementsByTagName('script');
      var regex = /awstats_misc_tracker.js$/;
      // find caller src
      for (var i = 0, length = scripts.length; i < length; i++) {
      // does it end with awstats js?
      if (regex.test(scripts[i].src)) {
      // take url as trackerurl
      awstatsmisctrackerurl=scripts[i].src;
      break;
      }
      }
      }
      </code>

      directly after

      <code>
      // If you use pslogger.php to generate your log, you can change this line with
      // var awstatsmisctrackerurl="pslogger.php?loc=/js/awstats_misc_tracker.js";
      var awstatsmisctrackerurl;
      </code>

      That will take the url that was used in the caller page and will append the parameter. This will keep the contextroot.

      Works for me.

      regards,
      Veit