From f8a570d0d5e5a3f70f67d8c9b82fc8a91b77c593 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C5=91cze=20Bence?= Date: Thu, 25 Jun 2020 14:02:39 +0200 Subject: [PATCH] MAPG-178 add Google Analytics style adaptations cookie notice improvements --- public/static/js/game.js | 16 +++++++--- public/static/js/mapguesser.js | 45 ++++++++++++++++++++++++++ views/admin/map_editor.php | 26 ++++++++------- views/game.php | 56 +++++++++++++++++---------------- views/templates/main_footer.php | 33 ++++++++++--------- views/templates/main_header.php | 2 +- 6 files changed, 119 insertions(+), 59 deletions(-) diff --git a/public/static/js/game.js b/public/static/js/game.js index 8a835c0..0f557ee 100644 --- a/public/static/js/game.js +++ b/public/static/js/game.js @@ -16,7 +16,7 @@ initialize: function () { document.getElementById('loading').style.visibility = 'visible'; - document.getElementById('guessCover').style.visibility = 'visible'; + document.getElementById('panoCover').style.visibility = 'visible'; document.getElementById('currentRound').innerHTML = '1/' + String(Game.NUMBER_OF_ROUNDS); document.getElementById('currentScoreSum').innerHTML = '0/0'; @@ -27,7 +27,7 @@ MapGuesser.httpRequest('GET', '/game/' + mapId + '/newPlace.json', function () { document.getElementById('loading').style.visibility = 'hidden'; - document.getElementById('guessCover').style.visibility = 'hidden'; + document.getElementById('panoCover').style.visibility = 'hidden'; if (this.response.error) { //TODO: handle this error @@ -98,7 +98,7 @@ lastRound.line.setVisible(false); } - document.getElementById('guessCover').style.visibility = 'hidden'; + document.getElementById('panoCover').style.visibility = 'hidden'; document.getElementById('showGuessButton').style.visibility = null; document.getElementById('guess').style.visibility = null; document.getElementById('guess').classList.remove('result') @@ -152,7 +152,7 @@ document.getElementById('guess').classList.remove('adapt'); } document.getElementById('loading').style.visibility = 'visible'; - document.getElementById('guessCover').style.visibility = 'visible'; + document.getElementById('panoCover').style.visibility = 'visible'; var data = new FormData(); data.append('lat', String(guessPosition.lat)); @@ -370,6 +370,14 @@ } }; + MapGuesser.sessionAvailableHooks.reinitializeGame = function () { + MapGuesser.httpRequest('GET', '/game/' + mapId + '/json', function () { + mapBounds = this.response.bounds; + + Game.initialize(); + }); + }; + if (!('ontouchstart' in document.documentElement)) { Game.adaptGuess = true; } diff --git a/public/static/js/mapguesser.js b/public/static/js/mapguesser.js index cc7198f..0af777a 100644 --- a/public/static/js/mapguesser.js +++ b/public/static/js/mapguesser.js @@ -1,4 +1,49 @@ var MapGuesser = { + cookiesAgreed: false, + sessionAvailableHooks: {}, + + initGoogleAnalitics: function () { + if (typeof GOOGLE_ANALITICS_ID === 'undefined') { + return; + } + + // Global site tag (gtag.js) - Google Analytics + var script = document.createElement('script'); + script.src = 'https://www.googletagmanager.com/gtag/js?id=' + GOOGLE_ANALITICS_ID; + script.async = true; + + document.head.appendChild(script); + + window.dataLayer = window.dataLayer || []; + function gtag(){dataLayer.push(arguments);} + gtag('js', new Date()); + gtag('config', GOOGLE_ANALITICS_ID); + }, + + agreeCookies: function () { + if (MapGuesser.cookiesAgreed) { + return; + } + + var expirationDate = new Date(new Date().getTime() + 20 * 365 * 24 * 60 * 60 * 1000).toUTCString(); + document.cookie = 'COOKIES_CONSENT=1; expires=' + expirationDate + '; path=/'; + + MapGuesser.initGoogleAnalitics(); + MapGuesser.httpRequest('GET', '/startSession.json', function () { + ANTI_CSRF_TOKEN = this.response.antiCsrfToken; + + for (var hookId in MapGuesser.sessionAvailableHooks) { + if (!MapGuesser.sessionAvailableHooks.hasOwnProperty(hookId)) { + continue; + } + + MapGuesser.sessionAvailableHooks[hookId](); + } + }); + + MapGuesser.cookiesAgreed = true; + }, + httpRequest: function (method, url, callback, data) { var xhr = new XMLHttpRequest(); diff --git a/views/admin/map_editor.php b/views/admin/map_editor.php index 28b6c4d..5b8d74a 100644 --- a/views/admin/map_editor.php +++ b/views/admin/map_editor.php @@ -59,18 +59,20 @@ $jsFiles = [ -
-
- -
-
-
-

No panorama is available for this location.

-
-
- - - +
+
+
+
+

No panorama is available for this location.

+
+
+ +
+
+ + + +
@@ -17,22 +20,14 @@ + + + + \ No newline at end of file diff --git a/views/templates/main_header.php b/views/templates/main_header.php index 23e6e15..a88457d 100644 --- a/views/templates/main_header.php +++ b/views/templates/main_header.php @@ -27,7 +27,7 @@

uses cookies to improve user experience. By using the app or clicking 'Agree', you consent to our use of cookies.

- +