Google Analytics Filter ver. 1.2


This is a Java servlet filter (as per Servlet API 2.3). UrchinFilter lets you add dynamically Google Analytics tracking code to the requested pages.

How to use it:

a) download urchinflt.jar and save it in WEB-INF/lib

b) describe this filter in web.xml. There is an initial parameter code describes your Google Analytics code (it is some like this UA-XXXXXX-X):
 


<filter>
  <filter-name>UrchinFilter</filter-name>
  <filter-class>com.cj.urchin.UrchinFilter</filter-class>
  <init-param>
    <param-name>code</param-name>
    <param-value>your_google_analytics_code</param-value>
  </init-param>
</filter>

c) describe a mapping for this filter in web.xml
 


<filter-mapping>
  <filter-name>UrchinFilter</filter-name>
  <url-pattern>*.jsp</url-pattern>
</filter-mapping>

in this case filter will be on for the each .jsp file

And now when you invoke any .jsp page: http://your_host/your_page.jsp UrchinFilter will add Google Analytics tracking code:
 


<script src="http://www.google-analytics.com/urchin.js" type="text/javascript">
</script>
<script type="text/javascript">
_uacct = "UA-XXXXXX-X";
urchinTracker();
</script>

at the end of your files.
 

    For downloading:   urchinflt.jar
 

 ©  Coldbeans     Comments?

See also JSOS - the largest collection of servlets and filters.

     

Also in JSOS: