Skip to content
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

Respect doNotTrack setting #98

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 40 additions & 10 deletions js/h5p-x-api-event.js
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,29 @@ H5P.XAPIEvent.prototype.setContext = function (instance) {
* Set the actor. Email and name will be added automatically.
*/
H5P.XAPIEvent.prototype.setActor = function () {

/*
* Check for doNotTrack setting by user. Could be placed in h5p.js.
* @param {boolean} [strict=true] If True, will assume "do no track" if unset.
* @return {boolean} True, if user should not be tracked.
*/
const isDoNotTrackSet = function (strict) {
strict = (typeof strict === 'boolean') ? strict : true;

// User explicitly does not want to be tracked
if (window.doNotTrack === '1' || navigator.doNotTrack === 'yes' || navigator.doNotTrack === '1') {
return true;
}

// Strict and user/browser did not specify doNotTrack setting
if (strict && !(window.doNotTrack || navigator.doNotTrack)) {
return true;
}

// Not strict or user explicitly allowed tracking
return false;
}

if (H5PIntegration.user !== undefined) {
this.data.statement.actor = {
'name': H5PIntegration.user.name,
Expand All @@ -200,19 +223,26 @@ H5P.XAPIEvent.prototype.setActor = function () {
}
else {
var uuid;
try {
if (localStorage.H5PUserUUID) {
uuid = localStorage.H5PUserUUID;

if (isDoNotTrackSet()) {
uuid = 'not-trackable-' + H5P.createUUID();
}
else {
try {
if (localStorage.H5PUserUUID) {
uuid = localStorage.H5PUserUUID;
}
else {
uuid = H5P.createUUID();
localStorage.H5PUserUUID = uuid;
}
}
else {
uuid = H5P.createUUID();
localStorage.H5PUserUUID = uuid;
catch (err) {
// LocalStorage and Cookies are probably disabled. Do not track the user.
uuid = 'not-trackable-' + H5P.createUUID();
}
}
catch (err) {
// LocalStorage and Cookies are probably disabled. Do not track the user.
uuid = 'not-trackable-' + H5P.createUUID();
}

this.data.statement.actor = {
'account': {
'name': uuid,
Expand Down