Using the AquaLogic Interaction Analytics 2.0 OpenUsage API
Pages: 1, 2, 3, 4, 5

Step 3: Add Analytics Events to Your Application

After you have defined your events in Analytics Administration, you can use OpenUsage to raise events in response to user actions.

This example is a sample application implemented as a portlet, shown below in Figure 4. The portlet is a JSP page that displays two static links and a text box with a submit button ("Go to My Demo Page!"). At the bottom of the portlet, there are two radio buttons and another submit button ("View Events!").

Figure 4
Figure 4. Analytics demo portlet (click the image for a full-size screen shot)

Each link in the portlet uses a different approach to raise an event.

Using the OpenUsage event tag

The first link ("OpenUsage Rocks") takes the user to another JSP page that raises an event using the <pt:as.event> tag. As shown in the code snippet below, the tag is implemented by including it in the page. Include a pt:as.fact attribute for each parameter defined for the event in Analytics Administration. For additional details on syntax, see the OpenUsage TagDocs.

Note: Tags can be used only in portlets and gatewayed pages because they must be processed by the AquaLogic Interaction Tag Transformation Engine. For an introduction to using tags, see Using ALI Adaptive Tags in the ALUI development documentation.




<h1>OpenUsage Rocks!</h1>

<p>(This page generates an event using the OpenUsage Portal Tag Library)

<p><a href="demo.jsp">Back</a>

<!-- Send the event using the OpenUsage tag library -->

<span xmlns:pt=''>

<pt:as.event pt:name="demo event" pt:userID="1">

  <pt:as.fact pt:name="page id" pt:value="1" pt:type="integer"/>

  <pt:as.fact pt:name="page name" pt:value="OpenUsage Rocks!" pt:type="string"/>

  <pt:as.fact pt:name="event method" pt:value="OpenUsage Tag Library" pt:type="string"/>

  <pt:as.fact pt:name="date" pt:value="<%= currentDateString%>" pt:type="date"/>





Using the OpenUsage Java API

The second link in the portlet takes the user to another JSP page that raises an event using the OpenUsage API. First, a new event is created using the ASEventFactory.createManagedEvent() method. A set*Fact() method is called for each parameter defined for the event in Analytics Administration. Finally, the event is raised and sent to Analytics using the sendEvent() method. These methods can be used in any application that has access to the OpenUsage libraries and connection to a network that allows UDP traffic. For additional details on these methods, see the OpenUsage API documentation (javadoc).

<p><%@page import="java.text.SimpleDateFormat"%>

<%@page import="*"%></p><p><html>


<h1>OpenUsage Is A-OK!</h1>


  (This page generates an event using the OpenUsage Java API)


<a href="demo.jsp">Back</a


  // create the event using the OpenUsage Java API

  IManagedEvent evt = ASEventFactory.createManagedEvent("demo event");

  evt.setUserId(new Integer(1));

  evt.setFact("page id", new Integer(3));

  evt.setFact("page name", "OpenUsage Is A-OK!");

  evt.setFact("event method", "OpenUsage Java API");

  evt.setLongAsDateFact("date", new Long(System.currentTimeMillis()));</p><p> // send it!





The text box/submit button in the portlet ("Go to My Demo Page!") also uses the OpenUsage API to raise an event. The form includes a hidden input element that triggers a Java servlet to raise the event. The code used by the servlet to raise the event is identical to the code above except it takes in the page name entered in the text box. This value is stored in the page name dimension table.

See the Download section for all the files used in this sample application.

Pages: 1, 2, 3, 4, 5

Next Page ยป