Add AdSense, GDPR code

This commit is contained in:
Gabriele Cirulli
2018-11-12 20:03:49 +01:00
parent ca93878f6b
commit 1f5f0a32c8
6 changed files with 218 additions and 17 deletions
+20 -3
View File
@@ -3,9 +3,12 @@ window.requestAnimationFrame(function () {
new GameManager(4, KeyboardInputManager, HTMLActuator, LocalStorageManager);
// TODO: This code is in need of a refactor (along with the rest)
var storage = new LocalStorageManager;
var noticeClose = document.querySelector(".notice-close-button");
var notice = document.querySelector(".app-notice");
var storage = new LocalStorageManager;
var noticeClose = document.querySelector(".notice-close-button");
var notice = document.querySelector(".app-notice");
var cookieNotice = document.querySelector(".cookie-notice");
var cookieNoticeClose = document.querySelector(".cookie-notice-dismiss-button");
if (storage.getNoticeClosed()) {
notice.parentNode.removeChild(notice);
} else {
@@ -19,4 +22,18 @@ window.requestAnimationFrame(function () {
}
});
}
if (storage.getCookieNoticeClosed()) {
cookieNotice.parentNode.removeChild(cookieNotice);
} else {
cookieNoticeClose.addEventListener("click", function () {
cookieNotice.parentNode.removeChild(cookieNotice);
storage.setCookieNoticeClosed(true);
if (typeof gtag !== undefined){
gtag("event", "closed", {
event_category: "cookie-notice",
});
}
})
}
});
+12 -3
View File
@@ -19,9 +19,10 @@ window.fakeStorage = {
};
function LocalStorageManager() {
this.bestScoreKey = "bestScore";
this.gameStateKey = "gameState";
this.noticeClosedKey = "noticeClosed";
this.bestScoreKey = "bestScore";
this.gameStateKey = "gameState";
this.noticeClosedKey = "noticeClosed";
this.cookieNoticeClosedKey = "cookieNoticeClosed";
var supported = this.localStorageSupported();
this.storage = supported ? window.localStorage : window.fakeStorage;
@@ -70,3 +71,11 @@ LocalStorageManager.prototype.setNoticeClosed = function (noticeClosed) {
LocalStorageManager.prototype.getNoticeClosed = function () {
return JSON.parse(this.storage.getItem(this.noticeClosedKey) || "false");
};
LocalStorageManager.prototype.setCookieNoticeClosed = function (cookieNoticeClosed) {
this.storage.setItem(this.cookieNoticeClosedKey, JSON.stringify(cookieNoticeClosed));
};
LocalStorageManager.prototype.getCookieNoticeClosed = function () {
return JSON.parse(this.storage.getItem(this.cookieNoticeClosedKey) || "false");
};