-
Notifications
You must be signed in to change notification settings - Fork 143
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
client.addEventSync() #188
Comments
This is a workaround:
|
@will123195 help me understand that – would that let you fire a payload off before the window closes? |
Yes, for example I'm tracking how long the user was on the page. |
hey @will123195 sorry for the lag! I really like this idea, we're discussing the best way to expose this functionality.. can you think of any other scenarios where you would want a synchronous request? |
It would help if you need your events to be logged in a specific order. Surely there are more performant ways to achieve that without blocking i/o, but could be convenient for testing or debugging things easily. |
@will123195 haven't forgotten about this.. not sure how we'll expose in the library, but here's a cool workaround I found that has a high success rate on mobile ( function setUnloadListener(){
var attachEvent, whichEvent;
if (window.onpagehide || window.onpagehide === null) {
window.addEventListener("pagehide", handleExit, false);
}
else {
attachEvent = window.attachEvent || window.addEventListener
whichEvent = window.attachEvent ? "onbeforeunload" : "beforeunload";
attachEvent(whichEvent, handleExit);
}
}
function handleExit(e){
client.trigger("exit");
}
// from superagent.js
function getXHR() {
if (window.XMLHttpRequest && ('file:' != window.location.protocol || !window.ActiveXObject)) {
return new XMLHttpRequest;
} else {
try { return new ActiveXObject('Microsoft.XMLHTTP'); } catch(e) {}
try { return new ActiveXObject('Msxml2.XMLHTTP.6.0'); } catch(e) {}
try { return new ActiveXObject('Msxml2.XMLHTTP.3.0'); } catch(e) {}
try { return new ActiveXObject('Msxml2.XMLHTTP'); } catch(e) {}
}
return false;
}
setUnloadListener();
client.on("exit", function(){
var request = getXHR();
var url = client.url("/projects/"+client.projectId()+"/events/" + "visit");
if (request) {
url += "?api_key=" + client.writeKey();
url += "&data=" + encodeURIComponent( Keen.Base64.encode( JSON.stringify( DataModel ) ) );
request.open('GET', url, false); // synchronous
request.send(null);
}
}); |
this is now possible in v3.2 by passing a fourth 'null' argument to |
that's #addEvent ^ mobile typo :) |
It would be nice if this worked for |
Is it possible to call
addEvent
synchronously?For example:
The text was updated successfully, but these errors were encountered: