Changeset 879 for trunk/autoquest-htmlmonitor/src/main/js
- Timestamp:
- 10/15/12 14:53:44 (12 years ago)
- Location:
- trunk/autoquest-htmlmonitor
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/autoquest-htmlmonitor
-
Property
svn:ignore
set to
target
-
Property
svn:ignore
set to
-
trunk/autoquest-htmlmonitor/src/main/js/autoquest-htmlmonitor.js
r876 r879 25 25 * the server to send the recorded data to 26 26 */ 27 var destination = "http://localhost:8090"; // change to the location of your server27 var autoquestDestination; 28 28 29 29 /** 30 30 * the maximum number of recorded events to be put into one package sent to the server 31 31 */ 32 var packageSize = 10;32 var autoquestPackageSize = 10; 33 33 34 34 /** … … 36 36 * event handling action to be monitored 37 37 */ 38 var a ctionConfig = [38 var autoquestActionConfig = [ 39 39 { "tag": "body", "actions": [ "onunload", "onscroll" ] }, 40 40 { "tag": "a", "actions": [ "onclick", "ondblclick", "onfocus" ] }, … … 45 45 * a possibility to trace, what is going on 46 46 */ 47 var doLog = false;47 var autoquestDoLog = false; 48 48 49 49 /*var matchedTags = ["A", "ABBR", "ACRONYM", "ADDRESS", "AREA", "B", "BIG", "BLOCKQUOTE", "BODY", … … 61 61 * stores events, which were recorded but not sent to the server yet 62 62 */ 63 var recordedEvents = [];63 var autoquestRecordedEvents = []; 64 64 65 65 /** … … 77 77 if (document.body) { 78 78 log("adding event handling attributes"); 79 determineDestination(); 79 80 addEventHandlingAttributes(document.documentElement, ""); 80 81 … … 90 91 91 92 /** 92 * traverses the DOM-structure of the HTML-site, and adds event handling attributes to each 93 * traverses the DOM-structure of the HTML-site and determines the URL of this script. Based on 94 * this URL, it calculates the destination to which the traced interactions must be sent 95 */ 96 function determineDestination() { 97 var scriptElements = document.getElementsByTagName("script"); 98 var i; 99 var index; 100 101 for (i = 0; i < scriptElements.length; i++) { 102 if ((scriptElements[i].type === "text/javascript") && (scriptElements[i].src)) { 103 index = scriptElements[i].src.lastIndexOf("script/autoquest-htmlmonitor.js"); 104 if (index > -1) { 105 autoquestDestination = scriptElements[i].src.substring(0, index - 1); 106 log("using destination " + autoquestDestination); 107 } 108 } 109 } 110 } 111 112 /** 113 * traverses the DOM-structure of the HTML-site and adds event handling attributes to each 93 114 * relevant node 94 115 * … … 105 126 106 127 if (node.nodeType === Node.ELEMENT_NODE) { 107 for (i = 0; i < a ctionConfig.length; i++) {108 if (node.tagName.toLowerCase() === a ctionConfig[i].tag.toLowerCase()) {109 for (k = 0; k < a ctionConfig[i].actions.length; k++) {110 value = "handleEvent('" + a ctionConfig[i].actions[k] + "', '" + nodePath+111 "', event);";112 113 if (!node.getAttribute(a ctionConfig[i].actions[k])) {114 node.setAttribute(a ctionConfig[i].actions[k], value);128 for (i = 0; i < autoquestActionConfig.length; i++) { 129 if (node.tagName.toLowerCase() === autoquestActionConfig[i].tag.toLowerCase()) { 130 for (k = 0; k < autoquestActionConfig[i].actions.length; k++) { 131 value = "handleEvent('" + autoquestActionConfig[i].actions[k] + "', '" + 132 nodePath + "', event);"; 133 134 if (!node.getAttribute(autoquestActionConfig[i].actions[k])) { 135 node.setAttribute(autoquestActionConfig[i].actions[k], value); 115 136 } 116 137 else { 117 var oldValue = node.getAttribute(a ctionConfig[i].actions[k]);138 var oldValue = node.getAttribute(autoquestActionConfig[i].actions[k]); 118 139 if (oldValue.indexOf(value) < 0) { 119 node.setAttribute(actionConfig[i].actions[k], value + ' ' + oldValue); 140 node.setAttribute(autoquestActionConfig[i].actions[k], 141 value + ' ' + oldValue); 120 142 } 121 143 } … … 189 211 * of the nodes. These attributes are generated by the 190 212 * {@link #addEventHandlingAttributes(node,parentPath)} function. It creates a new Event object and 191 * add it to the list of <code> recordedEvents</code>. If this list achieves the maximum192 * <code> packageSize</code> the events in the list are sent to the server asynchronously through193 * calling {@link #sendRequest()}.213 * add it to the list of <code>autoquestRecordedEvents</code>. If this list achieves the maximum 214 * <code>autoquestPackageSize</code> the events in the list are sent to the server asynchronously 215 * through calling {@link #sendRequest()}. 194 216 * 195 217 * @param eventName the name of the event, e.g. onscroll … … 198 220 */ 199 221 function handleEvent(eventName, nodePath, event) { 222 log("handling event " + eventName); 223 224 if (!autoquestDestination) { 225 // do nothing if we have no destination to send data to 226 return; 227 } 228 200 229 var eventType = eventName.toLowerCase(); 201 230 202 var eventObj = recordedEvents.pop();231 var eventObj = autoquestRecordedEvents.pop(); 203 232 204 233 // reuse previous on scroll events to prevent too many events 205 234 if ((eventName !== "onscroll") || (!eventObj) || (eventObj.type !== "onscroll")) { 206 235 if (eventObj) { 207 recordedEvents.push(eventObj);236 autoquestRecordedEvents.push(eventObj); 208 237 } 209 238 eventObj = new Event(eventType, nodePath); … … 224 253 } 225 254 226 recordedEvents.push(eventObj); 227 228 if ((recordedEvents.length >= packageSize) || (eventType === "onunload")) { 255 log("storing event " + eventName); 256 autoquestRecordedEvents.push(eventObj); 257 258 if (autoquestRecordedEvents.length >= autoquestPackageSize) { 259 log("initiating sending events"); 229 260 setTimeout(sendRequest, 100); 230 261 } 262 else if (eventType === "onunload") { 263 log("initiating sending events"); 264 sendRequest(); 265 } 231 266 232 267 } … … 234 269 /** 235 270 * sends the collected data to the server, named in the destination-variable. For this it generates 236 * a JSON formatted message and uses Ajax and the <code>destination</code> to send it to the server 271 * a JSON formatted message and uses Ajax and the <code>autoquestDestination</code> to send it to 272 * the server 237 273 */ 238 274 function sendRequest() { … … 243 279 var request; 244 280 245 if (recordedEvents.length > 0) { 246 eventList = recordedEvents; 247 recordedEvents = []; 281 if (autoquestRecordedEvents.length > 0) { 282 log("creating message"); 283 eventList = autoquestRecordedEvents; 284 autoquestRecordedEvents = []; 248 285 249 286 message = "{\"message\":{\"clientInfos\":{"; … … 283 320 } 284 321 285 request.open("POST", destination, true); 322 log("sending message"); 323 request.open("POST", autoquestDestination, true); 286 324 287 325 log("sending " + message); … … 434 472 */ 435 473 function log(text) { 436 if ( doLog) {474 if (autoquestDoLog) { 437 475 var loggingInfo = document.getElementById("loggingInfoParagraph"); 438 476
Note: See TracChangeset
for help on using the changeset viewer.