Mick
Mick I'm one of the co-founders of WebTuna Software.

Using the Microsoft URL rewriter to inject webtuna.js in to your IIS site

Using the Microsoft URL rewriter to inject webtuna.js in to your IIS site

This technique is useful if you have a third party application and don’t have a master page or source code which you can edit to include the webtuna.js in the of the pages.

The technique is described in more detail here although in our example we add the webtuna.js to the of the page rather than the end of the https://learn.iis.net/page.aspx/658/using-outbound-rules-to-add-web-analytics-tracking-code/

It is strongly recommended you try this on a test server first before doing this on a production

  1. Install URL Rewrite from here https://www.iis.net/download/urlrewrite
  2. Open IIS Manager, click on your site and then open the URL Rewrite feature
    url-rewriter-screen1
  3. In the Outbound Rule section click View Preconditions and the Add to add a new condition called IsHTML. The condition need check {RESPONSE_CONTENT_TYPE} matches the pattern ^text/html. This is so that we only insert our JavaScript code into HTML and not into any other content type.
    url-rewriter-screen2
  4. Next if you go back to Rule and add an new Outbound rule -> Blank rule
    url-rewriter-screen3
  5. The Outbound rule should check for our Precondition IsHTML, and then Match on a pattern <head> using an Exact Match. In the Action section we have a rewrite action which then rewrites <head> as <head><script type="text/javascript">var wt_start = new Date().getTime();</script> i.e appending the extra code needed in the HEAD from here)
  6. Now create another Outbound in the same way this time the rule should check for our Precondition IsHTML, and then Match on a pattern “” using an Exact Match. In the Action section we have a rewrite action which then rewrites </body> as <script type="text/javascript" src="/webtuna.js"></script></body> i.e appending the extra code needed in the BODY from here)
  7. Finally navigate to your web page and “view page source“ to verify the rewrite rule is working.