The Behavior Tracking Servlet Filter

As mentioned in Chapter 1, Quick Start, HTTP request tracking can be enabled either in spring configuration via inclusion of <bt:http-requests> or as a servlet filter. The primary difference is that the serlvet filter can record response codes and error messages in the event log.

Example 3.7. Defining BehaviorTrackingFilter in web.xml

<?xml version="1.0"?>
			
<web-app xmlns="http://java.sun.com/xml/ns/j2ee"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"
         version="2.4">
         
   ...
   <!-- normal web.xml configuration up to this point -->
   
   <!-- enable behavior tracking for servlet requests -->
   <filter>
      <filter-name>trackingFilter</filter-name>
      <filter-class>com.mtgi.analytics.servlet.BehaviorTrackingFilter</filter-class>
      <init-param>
         <param-name>com.mtgi.analytics.parameters.include</param-name>1
         <param-value>dispatch</param-value>
      </init-param>
      <init-param>
         <param-name>com.mtgi.analytics.parameters.name</param-name>2
         <param-value>dispatch</param-value>
      </init-param>
      <init-param>
         <param-name>com.mtgi.analytics.servlet.event</param-name>3
         <param-value>http-request</param-value>
      </init-param>
      <init-param>
         <param-name>com.mtgi.analytics.manager</param-name>4
         <param-value>defaultTrackingManager</param-value>
      </init-param>
   </filter>

   <filter-mapping>
      <filter-name>trackingFilter</filter-name>
      <servlet-name>action</servlet-name>
      <dispatcher>REQUEST</dispatcher>
   </filter-mapping>
             
</web-app>

1

An optional comma-separated list of parameters to include in the event data logs. If unspecified, all parameters are logged.

2

An optional comma-separated list of parameters to include with the request URI in the event name. If unspecified, no parameters are included in the name.

3

The value to specify for "event-type" in the event data logs. Primarily useful if you want to define several different filters and be able to identify which generated each event. Defaults to "http-request" if unspecified.

4

The Spring bean name of the BehaviorTrackingManager used to log events. Defaults to "defaultTrackingManager" if unspecified (if you only have one <bt:manager> tag in your Spring configuration, you should not need this parameter).