Tracking starts, exits, and transitions between states
You can view reports that describe high-level user behavior, such as session lengths and screen views per session. To view these types of reports, your application must track each time a BlackBerry® device user starts or exits a session, or moves your application to the background or foreground.
To enable your application to track starts and transitions between states, you application must extend either the WebtrendsApplication class or the WebtrendsUiApplication class. To enable your application to track exits, you must override onClose() and invoke onApplicationTerminate().
The following code sample demonstrates how you can create a framework for an application that tracks starts, exits and transitions between states:
public class AnalyticsDemo extends WebtrendsUiApplication
{
public static void main(String[] args)
{
AnalyticsDemo theApp = new AnalyticsDemo();
theApp.enterEventDispatcher();
}
public AnalyticsDemo()
{
pushScreen(new AnalyticsDemoScreen());
}
public class AnalyticsDemoScreen extends MainScreen implements FieldChangeListener
{
public AnalyticsDemoScreen()
{
//Code contained in the constructor.
}
public boolean onClose()
{
try
{
WebtrendsDataCollector.getInstance().onApplicationTerminate
("Application Terminate", null);
}
catch (IllegalWebtrendsParameterValueException err)
{
WebtrendsDataCollector.getLog().e(err.getMessage());
}
System.exit(0);
return true;
}
}
}
To see how this code sample works in an application that you can compile, see the full code sample .