add cookies banner, refactor whole GA loading flow

This commit is contained in:
Matthias Kretschmann 2018-05-15 12:04:15 +02:00
parent f9f61badb7
commit 13a3a85880
Signed by: m
GPG Key ID: 606EEEF3C479A91F
5 changed files with 61 additions and 82 deletions

View File

@ -2,6 +2,7 @@
//=include svg4everybody/dist/svg4everybody.js
//=include jquery/dist/jquery.js
//=include smooth-scroll/dist/js/smooth-scroll.js
//=include cookies-eu-banner/dist/cookies-eu-banner.js
//=include bigchain/analytics.js
//=include bigchain/dnt.js
@ -15,10 +16,6 @@ jQuery(function($) {
//
Forms.init()
if (!_dntEnabled()) {
GoogleAnalytics.init();
}
//
// init Smooth Scroll

View File

@ -0,0 +1,6 @@
<div id="cookies-eu-banner" style="display: none;">
By continuing your visit to this site, you accept the use of cookies by Google Analytics to make visits statistics.
<a href="./read-more.html" id="cookies-eu-more">Read more</a>
<button id="cookies-eu-reject">Reject</button>
<button id="cookies-eu-accept">Accept</button>
</div>

View File

@ -1,17 +1,11 @@
<!--
//
// Site scripts
//
-->
<script src="/assets/js/bigchain.min.js"></script>
{% if page.js %}
<script src="/assets/js/{{ page.js }}"></script>
{% elsif layout.js %}
<script src="/assets/js/{{ layout.js }}"></script>
{% endif %}
<script src="/assets/js/bigchain.min.js"></script> {% if page.js %}
<script src="/assets/js/{{ page.js }}"></script> {% elsif layout.js %}
<script src="/assets/js/{{ layout.js }}"></script> {% endif %}
<!--
svg4everybody.js
@ -25,81 +19,60 @@ svg4everybody.js
//
-->
<script>
if (!_dntEnabled()) {
(function(window) {
if (!_dntEnabled()) {
new CookiesEuBanner(function () {
(function (window) {
// Google Analytics async snippet
// http://goo.gl/3FPNDx
window.ga = window.ga || function () { (ga.q = ga.q || []).push(arguments) };
ga.l = +new Date;
// Google Analytics async snippet
// http://goo.gl/3FPNDx
window.ga=window.ga||function(){(ga.q=ga.q||[]).push(arguments)};
ga.l=+new Date;
var d=document,
g=d.createElement('script'),
s=d.getElementsByTagName('script')[0];
g.async=true;
// Create the GA tracker
ga('create', '{{ site.analyticsID }}', 'auto', {siteSpeedSampleRate: 10});
{% if jekyll.environment == "production" %}
g.src='https://www.google-analytics.com/analytics.js';
{% else %}
g.src='https://www.google-analytics.com/analytics_debug.js';
{% endif%}
{% if jekyll.environment != 'production' %}
// In non-production mode, simply log GA hits to the console.
// Note, tasks must be set before sending the first hit
ga(function(tracker) {
tracker.set('sendHitTask', function() {
// Throw to stop subsequent tasks.
throw 'Abort tracking in non-production environments.'
});
});
{% endif %}
s.parentNode.insertBefore(g,s);
// IP Anonymization
ga('set', 'anonymizeIp', true);
// Create the GA tracker
ga('create', '{{ site.analyticsID }}', 'auto', { siteSpeedSampleRate: 10 });
// Send initial pageview
ga('send', 'pageview');
{% if jekyll.environment != 'production' %}
// In non-production mode, simply log GA hits to the console.
// Note, tasks must be set before sending the first hit
ga(function (tracker) {
tracker.set('sendHitTask', function () {
// Throw to stop subsequent tasks.
throw 'Abort tracking in non-production environments.'
});
});
{% endif %}
// Track uncaught errors
window.onerror = function(message, url, line, col) {
var desc = message + ' (line: ' + line + ', url: ' + url + ', col: '
+ col + ')';
// IP Anonymization
ga('set', 'anonymizeIp', true);
ga('send', 'exception', {
exDescription: 'window.onerror: ' + desc,
exFatal: false
});
};
// Send initial pageview
ga('send', 'pageview');
}(window));
}
// Track uncaught errors
window.onerror = function (message, url, line, col) {
var desc = message + ' (line: ' + line + ', url: ' + url + ', col: ' + col + ')';
ga('send', 'exception', {
exDescription: 'window.onerror: ' + desc,
exFatal: false
});
};
}(window));
GoogleAnalytics.init()
}, true);
}
</script>
{% if jekyll.environment == "production" %}
<script async src="//www.google-analytics.com/analytics.js"></script>
{% else %}
<script async src="//www.google-analytics.com/analytics_debug.js"></script>
{% endif%}
<!--
//
// Disqus comments
//
-->
{% if page.comments %}
<script>
var disqus_config = function () {
this.page.url = '{{ site.url }}{{ page.url }}';
this.page.identifier = '{{ page.id }}';
this.page.title = '{{ page.title }}';
};
{% if jekyll.environment == "development" %}
var disqus_developer = 1;
{% endif %}
(function() {
var d = document, s = d.createElement('script');
s.src = '//{{ site.disqus }}.disqus.com/embed.js';
s.setAttribute('data-timestamp', +new Date());
(d.head || d.body).appendChild(s);
})();
</script>
<noscript>Please enable JavaScript to view the <a href="https://disqus.com/?ref_noscript" rel="nofollow">comments powered by Disqus.</a></noscript>
{% endif %}

View File

@ -19,6 +19,8 @@
{% include footer.html %}
{% include cookie-banner.html %}
{% include scripts.html %}
</body>

View File

@ -28,6 +28,7 @@
"bigchaindb-driver": "^4.0.0",
"bootstrap": "^4.1.0",
"clipboard": "^2.0.0",
"cookies-eu-banner": "^1.2.10",
"gumshoe": "github:cferdinandi/gumshoe",
"is-in-viewport": "^3.0.0",
"jquery": "^3.3.1",