Skip to content
Snippets Groups Projects
Commit e3097966 authored by Shane Tomlinson's avatar Shane Tomlinson
Browse files

fixing interaction data

parent f3875465
No related branches found
No related tags found
No related merge requests found
...@@ -31,6 +31,7 @@ BrowserID.Modules.InteractionData = (function() { ...@@ -31,6 +31,7 @@ BrowserID.Modules.InteractionData = (function() {
sc; sc;
function onSessionContext(msg, result) { function onSessionContext(msg, result) {
console.log("session context");
var self=this; var self=this;
// defend against onSessionContext being called multiple times // defend against onSessionContext being called multiple times
...@@ -41,48 +42,51 @@ BrowserID.Modules.InteractionData = (function() { ...@@ -41,48 +42,51 @@ BrowserID.Modules.InteractionData = (function() {
// session data must be published independently of whether the current // session data must be published independently of whether the current
// dialog session is allowed to sample data. This is because the original // dialog session is allowed to sample data. This is because the original
// dialog session has already decided whether to collect data. // dialog session has already decided whether to collect data.
publishStored();
// set the sample rate as defined by the server. It's a value // Continuation after publishing MUST be done
// between 0..1, integer or float, and it specifies the percentage publishStored(function() {
// of the time that we should capture // set the sample rate as defined by the server. It's a value
var sampleRate = result.data_sample_rate || 0; // between 0..1, integer or float, and it specifies the percentage
// of the time that we should capture
if (typeof self.samplingEnabled === "undefined") { var sampleRate = result.data_sample_rate || 0;
// now that we've got sample rate, let's smash it into a boolean
// probalistically if (typeof self.samplingEnabled === "undefined") {
self.samplingEnabled = Math.random() <= sampleRate; // now that we've got sample rate, let's smash it into a boolean
} // probalistically
self.samplingEnabled = Math.random() <= sampleRate;
}
// if we're not going to sample, kick out early. // if we're not going to sample, kick out early.
if (!self.samplingEnabled) { if (!self.samplingEnabled) {
return; return;
} }
var currentData = { var currentData = {
event_stream: self.initialEventStream, event_stream: self.initialEventStream,
sample_rate: sampleRate, sample_rate: sampleRate,
timestamp: result.server_time, timestamp: result.server_time,
local_timestamp: self.startTime.toString(), local_timestamp: self.startTime.toString(),
lang: dom.getAttr('html', 'lang') || null, lang: dom.getAttr('html', 'lang') || null,
};
if (window.screen) {
currentData.screen_size = {
width: window.screen.width,
height: window.screen.height
}; };
}
// cool. now let's persist the initial data. This data will be published if (window.screen) {
// as soon as the first session_context completes for the next dialog currentData.screen_size = {
// session. Use a push because old data *may not* have been correctly width: window.screen.width,
// published to a down server or erroring web service. height: window.screen.height
storage.push(currentData); };
}
// cool. now let's persist the initial data. This data will be published
// as soon as the first session_context completes for the next dialog
// session. Use a push because old data *may not* have been correctly
// published to a down server or erroring web service.
console.log("pushing currentData");
storage.push(currentData);
self.initialEventStream = null; self.initialEventStream = null;
self.samplesBeingStored = true; self.samplesBeingStored = true;
});
} }
// At every load, after session_context returns, we'll try to publish // At every load, after session_context returns, we'll try to publish
...@@ -98,8 +102,10 @@ BrowserID.Modules.InteractionData = (function() { ...@@ -98,8 +102,10 @@ BrowserID.Modules.InteractionData = (function() {
// XXX: should we even try to post data if it's larger than some reasonable // XXX: should we even try to post data if it's larger than some reasonable
// threshold? // threshold?
console.log(data);
if (data && data.length !== 0) { if (data && data.length !== 0) {
network.sendInteractionData(data, function() { network.sendInteractionData(data, function() {
console.log("clear");
storage.clear(); storage.clear();
complete(oncomplete, true); complete(oncomplete, true);
}, function(status) { }, function(status) {
...@@ -126,11 +132,13 @@ BrowserID.Modules.InteractionData = (function() { ...@@ -126,11 +132,13 @@ BrowserID.Modules.InteractionData = (function() {
var eventData = [ eventName, new Date() - self.startTime ]; var eventData = [ eventName, new Date() - self.startTime ];
if (self.samplesBeingStored) { if (self.samplesBeingStored) {
console.log("add stored event:" + eventName);
var d = storage.current() || {}; var d = storage.current() || {};
if (!d.event_stream) d.event_stream = []; if (!d.event_stream) d.event_stream = [];
d.event_stream.push(eventData); d.event_stream.push(eventData);
storage.setCurrent(d); storage.setCurrent(d);
} else { } else {
console.log("add initial event:" + eventName);
self.initialEventStream.push(eventData); self.initialEventStream.push(eventData);
} }
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment