MAPG-178 add Google Analytics
style adaptations cookie notice improvements
This commit is contained in:
parent
e7ee7bbe8e
commit
f8a570d0d5
@ -16,7 +16,7 @@
|
|||||||
|
|
||||||
initialize: function () {
|
initialize: function () {
|
||||||
document.getElementById('loading').style.visibility = 'visible';
|
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('currentRound').innerHTML = '1/' + String(Game.NUMBER_OF_ROUNDS);
|
||||||
document.getElementById('currentScoreSum').innerHTML = '0/0';
|
document.getElementById('currentScoreSum').innerHTML = '0/0';
|
||||||
|
|
||||||
@ -27,7 +27,7 @@
|
|||||||
|
|
||||||
MapGuesser.httpRequest('GET', '/game/' + mapId + '/newPlace.json', function () {
|
MapGuesser.httpRequest('GET', '/game/' + mapId + '/newPlace.json', function () {
|
||||||
document.getElementById('loading').style.visibility = 'hidden';
|
document.getElementById('loading').style.visibility = 'hidden';
|
||||||
document.getElementById('guessCover').style.visibility = 'hidden';
|
document.getElementById('panoCover').style.visibility = 'hidden';
|
||||||
|
|
||||||
if (this.response.error) {
|
if (this.response.error) {
|
||||||
//TODO: handle this error
|
//TODO: handle this error
|
||||||
@ -98,7 +98,7 @@
|
|||||||
lastRound.line.setVisible(false);
|
lastRound.line.setVisible(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
document.getElementById('guessCover').style.visibility = 'hidden';
|
document.getElementById('panoCover').style.visibility = 'hidden';
|
||||||
document.getElementById('showGuessButton').style.visibility = null;
|
document.getElementById('showGuessButton').style.visibility = null;
|
||||||
document.getElementById('guess').style.visibility = null;
|
document.getElementById('guess').style.visibility = null;
|
||||||
document.getElementById('guess').classList.remove('result')
|
document.getElementById('guess').classList.remove('result')
|
||||||
@ -152,7 +152,7 @@
|
|||||||
document.getElementById('guess').classList.remove('adapt');
|
document.getElementById('guess').classList.remove('adapt');
|
||||||
}
|
}
|
||||||
document.getElementById('loading').style.visibility = 'visible';
|
document.getElementById('loading').style.visibility = 'visible';
|
||||||
document.getElementById('guessCover').style.visibility = 'visible';
|
document.getElementById('panoCover').style.visibility = 'visible';
|
||||||
|
|
||||||
var data = new FormData();
|
var data = new FormData();
|
||||||
data.append('lat', String(guessPosition.lat));
|
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)) {
|
if (!('ontouchstart' in document.documentElement)) {
|
||||||
Game.adaptGuess = true;
|
Game.adaptGuess = true;
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,49 @@
|
|||||||
var MapGuesser = {
|
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) {
|
httpRequest: function (method, url, callback, data) {
|
||||||
var xhr = new XMLHttpRequest();
|
var xhr = new XMLHttpRequest();
|
||||||
|
|
||||||
|
@ -59,19 +59,21 @@ $jsFiles = [
|
|||||||
</div>
|
</div>
|
||||||
</form>
|
</form>
|
||||||
</div>
|
</div>
|
||||||
|
<div class="full">
|
||||||
<div id="map"></div>
|
<div id="map"></div>
|
||||||
<div id="control">
|
|
||||||
<button id="saveButton" class="fullWidth" disabled>Save</button>
|
|
||||||
</div>
|
|
||||||
<div id="panorama"></div>
|
<div id="panorama"></div>
|
||||||
<div id="noPano">
|
<div id="noPano">
|
||||||
<p class="bold">No panorama is available for this location.</p>
|
<p class="bold">No panorama is available for this location.</p>
|
||||||
</div>
|
</div>
|
||||||
|
<div id="control">
|
||||||
|
<button id="saveButton" class="fullWidth" disabled>Save</button>
|
||||||
|
</div>
|
||||||
<div id="placeControl">
|
<div id="placeControl">
|
||||||
<button id="applyButton" class="fullWidth">Apply</button>
|
<button id="applyButton" class="fullWidth">Apply</button>
|
||||||
<button id="closeButton" class="gray fullWidth marginTop">Close</button>
|
<button id="closeButton" class="gray fullWidth marginTop">Close</button>
|
||||||
<button id="deleteButton" class="red fullWidth marginTop">Delete</button>
|
<button id="deleteButton" class="red fullWidth marginTop">Delete</button>
|
||||||
</div>
|
</div>
|
||||||
|
</div>
|
||||||
<script>
|
<script>
|
||||||
var tileUrl = '<?= $_ENV['LEAFLET_TILESERVER_URL'] ?>';
|
var tileUrl = '<?= $_ENV['LEAFLET_TILESERVER_URL'] ?>';
|
||||||
var tileAttribution = '<?= $_ENV['LEAFLET_TILESERVER_ATTRIBUTION'] ?>';
|
var tileAttribution = '<?= $_ENV['LEAFLET_TILESERVER_ATTRIBUTION'] ?>';
|
||||||
|
@ -21,7 +21,8 @@ $jsFiles = [
|
|||||||
--><span>Score <span id="currentScoreSum" class="bold"></span></span>
|
--><span>Score <span id="currentScoreSum" class="bold"></span></span>
|
||||||
</p>
|
</p>
|
||||||
</header>
|
</header>
|
||||||
<div id="guessCover"></div>
|
<div class="full">
|
||||||
|
<div id="panoCover"></div>
|
||||||
<div id="panorama"></div>
|
<div id="panorama"></div>
|
||||||
<div id="showGuessButtonContainer">
|
<div id="showGuessButtonContainer">
|
||||||
<button id="showGuessButton" class="fullWidth">Show guess map</button>
|
<button id="showGuessButton" class="fullWidth">Show guess map</button>
|
||||||
@ -55,6 +56,7 @@ $jsFiles = [
|
|||||||
<button id="startNewGameButton" class="fullWidth">Play this map again</button>
|
<button id="startNewGameButton" class="fullWidth">Play this map again</button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
</div>
|
||||||
<script>
|
<script>
|
||||||
var mapId = <?= $mapId ?>;
|
var mapId = <?= $mapId ?>;
|
||||||
var mapBounds = <?= json_encode($bounds) ?>;
|
var mapBounds = <?= json_encode($bounds) ?>;
|
||||||
|
@ -1,7 +1,10 @@
|
|||||||
<script>
|
<script>
|
||||||
const STATIC_ROOT = '<?= $_ENV['STATIC_ROOT'] ?>';
|
const STATIC_ROOT = '<?= $_ENV['STATIC_ROOT'] ?>';
|
||||||
const REVISION = '<?= REVISION ?>';
|
const REVISION = '<?= REVISION ?>';
|
||||||
const ANTI_CSRF_TOKEN = '<?= $_SESSION['anti_csrf_token'] ?>';
|
var ANTI_CSRF_TOKEN = '<?= \Container::$request->session()->get('anti_csrf_token') ?>';
|
||||||
|
<?php if (!empty($_ENV['GOOGLE_ANALITICS_ID'])): ?>
|
||||||
|
const GOOGLE_ANALITICS_ID = '<?= $_ENV['GOOGLE_ANALITICS_ID'] ?>';
|
||||||
|
<?php endif; ?>
|
||||||
</script>
|
</script>
|
||||||
<script src="<?= $_ENV['STATIC_ROOT'] ?>/js/mapguesser.js?rev=<?= REVISION ?>"></script>
|
<script src="<?= $_ENV['STATIC_ROOT'] ?>/js/mapguesser.js?rev=<?= REVISION ?>"></script>
|
||||||
<?php if (isset($jsFiles)) : ?>
|
<?php if (isset($jsFiles)) : ?>
|
||||||
@ -17,22 +20,14 @@
|
|||||||
<?php if (!isset($_COOKIE['COOKIES_CONSENT'])): ?>
|
<?php if (!isset($_COOKIE['COOKIES_CONSENT'])): ?>
|
||||||
<script>
|
<script>
|
||||||
(function () {
|
(function () {
|
||||||
var MapGuesser = {
|
// we don't want user to agree cookies when clicking on the notice itself
|
||||||
cookiesAgreed: false,
|
document.getElementById('cookiesNotice').onclick = function (e) {
|
||||||
|
e.stopPropagation();
|
||||||
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.cookiesAgreed = true;
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
document.getElementById('agreeCookies').onclick = function () {
|
document.getElementById('agreeCookiesButton').onclick = function () {
|
||||||
|
MapGuesser.agreeCookies();
|
||||||
|
|
||||||
document.getElementById('cookiesNotice').style.display = 'none';
|
document.getElementById('cookiesNotice').style.display = 'none';
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -41,6 +36,14 @@
|
|||||||
};
|
};
|
||||||
})();
|
})();
|
||||||
</script>
|
</script>
|
||||||
|
<?php else: ?>
|
||||||
|
<?php if (!empty($_ENV['GOOGLE_ANALITICS_ID'])): ?>
|
||||||
|
<script>
|
||||||
|
(function () {
|
||||||
|
MapGuesser.initGoogleAnalitics();
|
||||||
|
})();
|
||||||
|
</script>
|
||||||
|
<?php endif; ?>
|
||||||
<?php endif; ?>
|
<?php endif; ?>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
@ -27,7 +27,7 @@
|
|||||||
<p class="small">
|
<p class="small">
|
||||||
<?= $_ENV['APP_NAME'] ?> uses cookies to improve user experience. By using the app or clicking 'Agree', you consent to our use of cookies.
|
<?= $_ENV['APP_NAME'] ?> uses cookies to improve user experience. By using the app or clicking 'Agree', you consent to our use of cookies.
|
||||||
</p>
|
</p>
|
||||||
<button id="agreeCookies" class="small marginTop">Agree</button>
|
<button id="agreeCookiesButton" class="small marginTop">Agree</button>
|
||||||
</div>
|
</div>
|
||||||
<?php endif; ?>
|
<?php endif; ?>
|
||||||
<div id="loading">
|
<div id="loading">
|
||||||
|
Loading…
Reference in New Issue
Block a user