The Monitor service provides a passive client-side monitor framework. Monitors collect and aggregate data per page view and send that data to a server for Web analytics processing. The Account Manager 4 project includes a reference implementation.
Static instance of serviceImpl
An object registerer with the ObjectRegistry, that defines an initializeMonitor method, and that may define any handle_{event name} method listed for the MonitorService. The initializeMonitor method must return true for the object to be treated as a monitor and receive event notifications and intervall callbacks.
See Example Monitor #1 for an example of implementating the script on a page.
Demonstrate how to create and register a basic monitor object.
var oMonitor = {
handle_window_load:function(){
},
// Required by MonitorService
initializeMonitor:function(){
// must return true for monitoring to be enabled;
return 1;
}
};
// important to prepare object so 1) it can be registered, and 2) add it to the ObjectRegistry
Hemi.prepareObject("MyMonitor","1.0",true,oMonitor);
// add the monitor object
Hemi.monitor.service.addMonitor(oMonitor);Demonstrate alternate method to create and register a basic monitor object, and include inline configuration for the monitor.
function Monitor(){
}
Monitor.prototype.initializeMonitor = function(){
alert("Access configuration value: " + this.getConfigKey("myprop"));
// must return true for monitoring to be enabled;
return 1;
}
var oMonitor = new Monitor();
// important to prepare object so it can be registered; skip auto-registering for this demonstration.
Hemi.prepareObject("MyMonitor","1.0",false,oMonitor");
// Add object to the registry. It must be registered in order to be added as a monitor.
Hemi.registry.service.addObject(oMonitor);
Hemi.monitor.service.addMonitor(oMonitor,"myprop:myval&myprop2:myval2");Demonstrate how to create and register a monitor using an ApplicationComponent.
<!-- XML Component File -->
<application-components>
<application-component id = "demo_monitor">
<![CDATA[
component_init:function(){
Hemi.monitor.service.addMonitor(this);
},
initializeMonitor:function(){
return true;
},
handle_window_load:function(e){
alert("window load via monitor service");
}
]]>
</application-component>
</application-components>
<!-- HTML Page -->
<script type = "text/javascript">
var oComponent = Hemi.app.comp.newInstance();
oComponent.loadComponent("demo_monitor","/path/to/file.xml");
</script>Invoked by MonitorService doInterval. By default, this is invoked every one second. Each monitor can conttrol participating in the interval by setting the can_interval property to true or false, and can increase delay by setting the interval_offset property to the number of whole seconds that should elapse before doInterval is invoked again. The interval_offset is used as a degrading counter, so each monitor is responsible for setting its own delay after each invocation of doInterval. Method is virtual and can be overridden.
void doInterval( )
v = getConfigKey( c )
v as variant: Returns the String or int value for the corresponding key.
Returns the config_keys hash.
c = getConfigKeys( )
c as hash: Returns the hash containing the parsed inline configuration name/value pairs.
Returns the MonitorService to which this Monitor is registered.
m = getMonitorService( )
m as MonitorServiceImpl: A MonitorService implementation.
Invoked by MonitorService dispatchEvent to delegate the contextmenu event. Method is virtual and can be overridden.
void handle_context_menu( e )
Invoked by MonitorService dispatchEvent to delegate the document scroll event. Method is virtual and can be overridden.
void handle_document_scroll( e )
Invoked by MonitorService dispatchEvent to delegate the form reset event. Method is virtual and can be overridden.
void handle_form_reset( e )
Invoked by MonitorService dispatchEvent to delegate the form submit event. Method is virtual and can be overridden.
void handle_form_submit( e )
Invoked by MonitorService dispatchEvent to delegate the input blur event. Method is virtual and can be overridden.
void handle_input_blur( e )
Invoked by MonitorService dispatchEvent to delegate the input focus event. Method is virtual and can be overridden.
void handle_input_focus( e )
Invoked by MonitorService dispatchEvent to delegate the mouse click event. Method is virtual and can be overridden.
void handle_mouse_click( e )
Invoked by MonitorService dispatchEvent to delegate the mouse move event. Method is virtual and can be overridden.
void handle_mouse_move( e )
Invoked by MonitorService dispatchEvent to delegate the select change event. Method is virtual and can be overridden.
void handle_select_change( e )
Invoked by MonitorService dispatchEvent to delegate the beforeunload event. Method is virtual and can be overridden.
void handle_window_beforeunload( e )
Invoked by MonitorService dispatchEvent to delegate the window blur event. Method is virtual and can be overridden.
void handle_window_blur( e )
Invoked by MonitorService dispatchEvent to delegate the error event. TODO: need to fix handler parameters. At the moment, error information is not being passed. Method is virtual and can be overridden.
void handle_window_error( e )
Invoked by MonitorService dispatchEvent to delegate the window focus event. Method is virtual and can be overridden.
void handle_window_focus( e )
Invoked by MonitorService dispatchEvent to delegate the window keydown event. Method is virtual and can be overridden.
void handle_window_keydown( e )
Invoked by MonitorService dispatchEvent to delegate the load event and binds elements to internal handlers. Dispatches window_load to monitors. Method is virtual and can be overridden.
void handle_window_load( e )
Invoked by MonitorService dispatchEvent to delegate the window resize event. Method is virtual and can be overridden.
void handle_window_resize( e )
Invoked by MonitorService dispatchEvent to delegate the unload event. Method is virtual and can be overridden.
void handle_window_unload( e )
Invoked by addMonitor if the object met the basic criteria for participating in the MonitorService: it must be registered, and it must define this method. Returns true if the object was initialized, false otherwise. If returning false, the object will not be treated as monitor and receive no notifications or callbacks. Whether this returns true or false, the object will continue to define the members set when addMonitor was invoked. Method is virtual and can be overridden.
b = initializeMonitor( )
b as boolean: True if the object initialized and should be treated as a monitor, false if the object should be ignored.
A base class for creating beacon and XML transponders for monitoring Web pages.
Object API structure for storing sub structures: object_config.pointers and object_config.status.
object = object.object_config
Unique instance identifier.
String = object.object_id
The type of this object.
String = object.object_type
Version of the object class.
String = object.object_version
Object load and execution state. Follows: 0 unitialized, 1 through 3 variant, 4 ready, 5 destroyed.
int = object.ready_state
Adds an object to the monitor service, and allows that object to automatically receive event callbacks and easy access to MonitorService information. The specified object must define an initializeMonitor method, and the method must return true for the monitor to be added. Defines the getMonitorService method, can_interval, and interval_offset on the specified object.
void addMonitor( o, c )
Binds MonitorService event handlers to common Web page objects. Individual monitors participate in the event handler by defining a handle_{event name} function, such as handle_window_load. Method is private and should not be directly referenced.
void bindElements( )
Binds MonitorService event handlers to common browser objects. Individual monitors participate in the event handler by defining a handle_{event name} function, such as handle_window_load. Method is private and should not be directly referenced.
void bindObjects( )
Dispatches event notifications to Monitor instances that define a function named handle_{event key}, such as handle_window_load. The event object is passed as the only parameter. NOTES: should we bother with cancelling events? These are monitors, which shouldn't be tampering with anything. Method is private and should not be directly referenced.
void dispatchEvent( s, e )
A an interval (one second / one thousand milliseconds) that invokes the doInterval method on Monitor instances that set the can_interval property to true. Monitors can increase delay by setting the interval_offset property to the number of seconds that should elapse before doInterval is invoked again. The interval_offset is used as a degrading counter, so each monitor is responsible for setting its own delay after each invocation of doInterval. Method is private and should not be directly referenced.
void doInterval( )
Returns the application id. Defaults to Global. Can be specified by defining the global APPLICATION_ID variable to a custom value.
s = getApplicationId( )
s as String: String indicating the application identifier.
Returns a light hash of the current page location plus a few random numbers to uniquely identify the current page visit from other pages visits by this particular session. This value only has to be unique in relation to other context_ids for the session id.
s = getContextId( )
s as String: Light hash of the current Web page location plus a few random numbers.
Returns the object in which all monitoring should take place. Defaults to document. Can be specified by setting the global CONTEXT_OBJECT variable to a different object prior to loading the MonitorService.
d = getContextObject( )
d as DOMNode: The context node in which monitoring is to take place.
Returns the identifier used to describe the data being collected. Defaults to public. Can be specified by defining the global DATASET_ID variable to a custom value.
d = getDatasetId( )
d as String: Identifier representing the type of data being collected.
Returns true if the document has loaded, false otherwise.
b = getDatasetId( )
b as boolean: Bit indicating whether the document has loaded and, under normal circumstances, whether it is rendered.
Returns the unique id of the object.
i = getObjectId( )
i as String: The unique object instance id.
Returns the type of the object.
t = getObjectType( )
t as String: The type of the object instance.
Returns the version of the object.
v = getObjectVersion( )
v as String: The version of the object instance.
Returns the object_config.pointers sub structure.
o = getPointers( )
o as object: The object_config.pointers substructure.
Returns the state of the object.
s = getReadyState( )
s as int: The object ready state.
Returns the session id based on the pre-configured session cookie name. By default, the MonitorService ships with MONITOR_SESSION_ID, and the value is auto-generated. To use a different cookie name, the SDK must be used to alter the build configuration. TODO: Add support for configurable names at runtime.
s = getSessionId( )
s as String: String indicating the application session identifier.
Returns the object_config.status sub structure.
o = getStatus( )
o as object: The object_config.status substructure.
Returns an int representing the current state of the browser window. 0 = unknown, 1 = uninitialized, 2 = window not loaded, 3 = window loaded, 4 = window before unload, 5 = window unload
i = getWindowState( )
i as int: The current state of the browser window.
Handler that manages the contextmenu event. Dispatches context_menu to monitors. Method is private and should not be directly referenced.
void handle_context_menu( )
Handler that manages the document scroll event. Dispatches document_scroll to monitors. Method is private and should not be directly referenced.
void handle_document_scroll( )
Handler that manages the stop event. Dispatches document_stop to monitors. Method is private and should not be directly referenced.
void handle_document_stop( )
Handler that manages the form reset event. Dispatches form_reset to monitors. Method is private and should not be directly referenced.
void handle_form_reset( )
Handler that manages the form submit event. Dispatches form_submit to monitors. Method is private and should not be directly referenced.
void handle_form_submit( )
Handler that manages the input blur event. Dispatches input_blur to monitors. Method is private and should not be directly referenced.
void handle_input_blur( )
Handler that manages the input focus event. Dispatches input_focus to monitors. Method is private and should not be directly referenced.
void handle_input_focus( )
Handler that manages the mouse click event. Dispatches mouse_click to monitors. Method is private and should not be directly referenced.
void handle_mouse_click( )
Handler that manages the mouse move event. Dispatches mouse_move to monitors. Method is private and should not be directly referenced.
void handle_mouse_move( )
Handler that manages the select change event. Dispatches select_change to monitors. Method is private and should not be directly referenced.
void handle_select_change( )
Handler that manages the beforeunload event. Dispatches window_beforeunload to monitors. Method is private and should not be directly referenced.
void handle_window_beforeunload( )
Handler that manages the window blur event. Dispatches window_blur to monitors. Method is private and should not be directly referenced.
void handle_window_blur( )
Handler that manages the error event. Dispatches window_error to monitors. TODO: need to fix handler parameters. At the moment, error information is not being passed. Method is private and should not be directly referenced.
void handle_window_error( )
Handler that manages the window focus event. Dispatches window_focus to monitors. Method is private and should not be directly referenced.
void handle_window_focus( )
Handler that manages the interval thread. Note: this doesn't use the ThreadService, though probably should. Method is private and should not be directly referenced.
void handle_window_interval( )
Handler that manages the window keydown event. Dispatches window_keydown to monitors. Method is private and should not be directly referenced.
void handle_window_keydown( )
Handler that manages the load event and binds elements to internal handlers. Dispatches window_load to monitors. Method is private and should not be directly referenced.
void handle_window_load( )
Handler that manages the window resize event. Dispatches window_resize to monitors. Method is private and should not be directly referenced.
void handle_window_resize( )
Handler that manages the unload event. Dispatches window_unload to monitors. Method is private and should not be directly referenced.
void handle_window_unload( )
Hashes the document cookies into the <i>cookies</i> hash, where the default cookie structure of most browsers is: <i>name=value; name2=value2</i>. Optionally hashes embedded cookie values that use the following syntax: <i>subname:subvalue&subname2:subvalue2</i>. For example: <i>name=subname:subvalue; name2=subname2:subvalue2&subname3:subvalue3</i>
void hashCookie( n, b, f )
Hashes the value into the specified hash, using the specified delimiters, such as: <i>name=value; name2=value2</i>.
void hashValue( c, d, s, k )
Starts the MonitorService. This is automatically invoke when a MonitorService instance is created. Method is private and should not be directly referenced.
void initializeMonitorService( )
Remove an object from the monitor service.
b = removeMonitor( o )
b as boolean: Bit indicating whether the monitor was removed.
[ Hemi JavaScript Framework - Stephen W. Cote, 2002 - 2009. ]