Browse Source

Use socketio to transmit when the user is viewing the page and remove timeme use.

develop
Sam Black 4 years ago
parent
commit
704208dee7
  1. 8
      LICENCES/timeme.js
  2. 26
      vowel/assets/js/vowel/analytics/engagement.js
  3. 43
      vowel/assets/js/vowel/common.js
  4. 2
      vowel/templates/layout/layout.html

8
LICENCES/timeme.js

@ -1,8 +0,0 @@
MIT License (MIT)
Copyright (c) 2017 Jason Zissman
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

26
vowel/assets/js/vowel/analytics/engagement.js

@ -16,15 +16,31 @@
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
function engagementTracking(engagementId) {
TimeMe.initialize({
currentPageName: engagementId,
idleTimeoutSeconds: 30
var engagement = io("/analytics/engagement");
engagement.on("connect", function() {
engagement.emit("init", engagementId);
});
function pageVisible() {
engagement.emit("visible", engagementId);
}
function pageHidden() {
engagement.emit("hidden", engagementId);
}
visibilityChecker(pageVisible, pageHidden);
// Ideally we'd use the "unload" event here,
// but this doesn't seem to fire before the page closes
window.addEventListener("beforeunload", function() {
engagement.emit("unload", engagementId);
});
}
$(document).ready(function() {
var engagementId = $(body).data("vowel-engagement");
if (socket.connected && engagementId) {
var engagementId = $("body").data("vowel-engagement");
if (engagementId) {
engagementTracking(engagementId);
}
});

43
vowel/assets/js/vowel/common.js

@ -18,6 +18,49 @@
var socket = io.connect();
Dropzone.autoDiscover = false;
/* This is pulled pretty much verbatim from the MDN Page Visibility API page;
https://developer.mozilla.org/en-US/docs/Web/API/Page_Visibility_API#Example
*/
function visibilityChecker(visibleCallback, hiddenCallback) {
var hidden,
visibilityChange;
if (typeof document.hidden !== "undefined") { // Opera 12.10 and Firefox 18 and later support
hidden = "hidden";
visibilityChange = "visibilitychange";
} else if (typeof document.msHidden !== "undefined") {
hidden = "msHidden";
visibilityChange = "msvisibilitychange";
} else if (typeof document.webkitHidden !== "undefined") {
hidden = "webkitHidden";
visibilityChange = "webkitvisibilitychange";
}
function handleVisibilityChange() {
if (document[hidden]) {
hiddenCallback();
} else {
visibleCallback();
}
}
if (typeof document.addEventListener === "undefined" || typeof document.hidden === "undefined") {
console.log("This demo requires a browser, such as Google Chrome or Firefox, that supports the Page Visibility API.");
} else {
// Handle page visibility change
document.addEventListener(visibilityChange, handleVisibilityChange, false);
// Handle the whole browser window being hidden
window.addEventListener("blur", function () {
hiddenCallback();
});
window.addEventListener("focus", function () {
visibleCallback();
});
}
}
/* End MDN */
$(document).ready(function () {
$("select.searchable").not(".template").select2({
theme: "default",

2
vowel/templates/layout/layout.html

@ -24,7 +24,7 @@
{% block head_css %}{% endblock %}
</head>
<body>
<body data-vowel-engagement="{{ request.path }}">
<div class="uk-offcanvas-content">
{# Blocks in 'includes' cannot be overridden from child templates,
so use "{% set ... %}{% endset %}" and override that way. #}

Loading…
Cancel
Save