How to include Google Analytics snippet in Javadoc?

戏子无情 提交于 2019-12-12 20:06:53

问题


I would like to include the Google Analytics Javascript code in the head element of my generated Javadoc HTML output. How can I do this?

I figured I may need to write a custom Doclet, but this is probably going to be a nightmare of a learning curve. Isn't there a simpler way?


回答1:


You have 2 solutions, Using maven plugin Javadoc with

<reporting>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-javadoc-plugin</artifactId>
            <configuration>
                    <header>&lt;b&gt;test test&lt;/b&gt</header>    
            </configuration>
        </plugin>
    </plugins>
</reporting>

you change my "test test" with your google analytics script and don't forget to change < with < and > with > and then you call

mvn clean javadoc:javadoc

or using the old method http://docs.oracle.com/javase/7/docs/technotes/tools/windows/javadoc.html#header with your html script




回答2:


Use CData

<configuration>
    <!-- GA Tracking code -->
    <header>
    <![CDATA[
        <script type="text/javascript">
          var _gaq = _gaq || [];
          _gaq.push(['_setAccount', 'UA-XXXXXXXX-1']);
          _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>
    ]]>
    </header>
</configuration>


来源:https://stackoverflow.com/questions/8520337/how-to-include-google-analytics-snippet-in-javadoc

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!