Raising Analytics Events from a Custom 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.
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!"). 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 Oracle WebCenter Interaction
Tag Transformation Engine. For more information on using
tags, Oracle WebCenter Interaction Web Service Development Guide.
<p><html>
<body>
...
<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='http://www.plumtree.com/xmlschemas/ptui/'>
<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"/>
</pt:as.event>
</span>
</body>
</html>
- 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 setParameter() 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="com.plumtree.analytics.openusage.*"%></p><p><html>
<body>
<h1>OpenUsage Is A-OK!</h1>
<p>
(This page generates an event using the OpenUsage Java API)
<p>
<a href="demo.jsp">Back</a
<%
// create the event using the OpenUsage Java API
IManagedEvent evt = ASEventFactory.createManagedEvent("demo event");
evt.setParameter("page id", new Integer(3));
evt.setParameter("page name", "OpenUsage Is A-OK!");
evt.setParameter("event method", "OpenUsage Java API");
evt.setLongAsDateParameter("date", new Long(System.currentTimeMillis()));</p><p> // send it!
evt.sendEvent();
%>
</body>
</html>
You could also use a text box/submit button in the portlet
and use the OpenUsage API to raise an event. The form would include
a hidden input element that triggers a Java servlet to raise the event.
The code used by the servlet to raise the event would be identical
to the code above except it would take in the page name entered in
the text box and store this value in the page name dimension table.
The next step is to configure Analytics to store events from
your custom application.