Docbkx-tools, DocBook 5 XML, and Google Analytics

Docbkx-tools logo Today I feel dirty for two reasons. I feel dirty on the outside because I rode hard on the bike at lunchtime and we have no showers at the office, yet. I feel dirty on the inside because I found a solution to add Google Analytics code into HTML generated from DocBook 5 XML with docbkx-tools, but the solution is sort of an ugly hack.

Using the maven-antrun-plugin, I added another task for Ant.

<replace dir='${basedir}/target/docbkx/html/' token='&lt;/body&gt;'>
  <include name='**/**/*.html' />
  <replacevalue>&lt;script type="text/javascript"&gt;
    var _gaq = _gaq || [];
    _gaq.push(['_setAccount', 'UA-########-#']);
    (function() {
      var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
      ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '';
      var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);

I would put that in a separate .xsl for HTML customizations, but I cannot find an appropriate parameter. I’m not chunking documents, so user.footer.content does not get used.

I tried going the external code file route, but either I get the <script> in the HTML and the FO (PDF, RTF) generation breaks, or I get &lt;script&gt; in the HTML (with parse="text").

Leave me a comment if you have solved this more elegantly.


2 thoughts on “Docbkx-tools, DocBook 5 XML, and Google Analytics

  1. The more I look at it, the more I like the idea of inserting analytics per HTML file, rather than per document. If legalnotice.html is getting more traffic than the release notes, that would actually be something worth knowing.

    Perhaps it would be a nice feature independently of the existing features.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s