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='</body>'>
<include name='**/**/*.html' />
<replacevalue><script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-########-#']);
_gaq.push(['_trackPageview']);
(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();
</script></body></replacevalue>
</replace>
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 <script> in the HTML (with parse="text").
Leave me a comment if you have solved this more elegantly.