Have a question?

J2EE SDK

Track customers directly in the J2EE Web Framework using Woopra’s J2EE SDK

Download the SDK

Download J2EE SDK from GitHub

J2EE SDK Documentation

This SDK allows our customers who have servers running the J2EE Framework to track their users by writing only Java code. Tracking directly in Java will allows you to track your users:

  • through front-end tracking: after configuring the tracker, identifying the user, and tracking page views and events in Java, the SDK will generate the corresponding JavaScript code, and by passing this code as an attribute of your request (examples will be shown below), you will be able to print that code in your JSP page’s header.
  • through back-end tracking: after configuring the tracker & identifying the user, add the optional parameter: true to the methods track or push, and the Java tracker will handle sending the data to Woopra by making HTTP Requests. By doing that, the client is never involved in the tracking process.

First, setup the tracker SDK in your Servlets. For example, if you want to set up tracking with Woopra on your homepage, the Servlet should look like:

public class Homepage extends HttpServlet {
   public void doGet(HttpServletRequest request, HttpServletResponse response) {
      WoopraTracker woopra = new WoopraTrackerEE(request);
      woopra.config(WoopraTracker.DOMAIN, "mybusiness.com");

      // Your code here...

You can also customize the properties of the tracker by repeating the above step with different parameters. For example, to update your idle timeout (default: 30 seconds):

woopra.config(WoopraTracker.IDLE_TIMEOUT, 15000); // in milliseconds

Configuration can also be done in a single step, by adding all the properties you wish to configure to a 2D Array:

woopra.config(new Object[][] {
   {WoopraTracker.DOMAIN, "mybusiness.com"},
   {WoopraTracker.IDLE_TIMEOUT, 15000},
   {WoopraTracker.PING, false},
});

To add custom visitor properties, pass a 2D Array to the identify(String[][] user) function:

woopra.identify(new String[][] {
   {"name", "User Name"},
   {"email", "user@company.com"},
   {"company", "User Business"}
});

To identify a user without a tracking event, you can push() the update to Woopra:

woopra.identify(user).push();
// or, to push through back-end:
woopra.identify(user).push(true);

To track page views, simply call track() :

woopra.track();
// or, for back-end tracking
woopra.track(true);

You can also track custom events through the front-end or the back-end. With all previous steps done at once, your Servlet should look like:

public class Homepage extends HttpServlet {
   public void doGet(HttpServletRequest request, HttpServletResponse response) {
      WoopraTracker woopra = new WoopraTrackerEE(request);
      woopra.config(WoopraTracker.DOMAIN, "mybusiness.com").identify(user).track();
      // Create an event
      myEvent = new WoopraEvent("play");
      myEvent.setProperty("artist", "Dave Brubeck");
      myEvent.setProperty("song", "Take Five");
      myEvent.setProperty("genre", "Jazz");
      woopra.track(myEvent);
      // Track it through the front end...
      woopra.track(myEvent)
      // ... or through the back end by passing the optional param True
      woopra.track(myEvent, true)

      //Your code here...

      // When you're done setting up your WoopraTracker object, set an attribute containing the
      // value of woopra.jsCode() among all the other attributes you are passing to the jsp:
      request.setAttribute("woopraCode", woopra.jsCode());
      this.getServletContext().getRequestDispatcher("/WEB-INF/homepage.jsp").forward(request, response);

and print the jsCode in your jsp’s header:

<head>
   ...
   <%= request.getAttribute("woopraCode") %>
</head>

If you prefer, you can also track an event without even having to create a WoopraEvent Object:

woopra.track("play", new Object[][] {
   {"artist", "Dave Brubeck"},
   {"song", "Take Five"},
   {"genre", "Jazz"},
}, true);

If you wish to track your users through back-end tracking, you should set the cookie on your user’s browser. However, If you are planning to use front-end tracking in addition you can skip this step, as the JavaScript tracker will handle it for you.

woopra.setWoopraCookie();
request.setAttribute("woopraCode", woopra.jsCode());
this.getServletContext().getRequestDispatcher("/WEB-INF/homepage.jsp").forward(request, response);

Need any help? Contact our Data Jedis