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

[refs #5080] Use google analytics only on user's confirmation #19

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
14 changes: 14 additions & 0 deletions ecolex/static/css/bootstrap.custom.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

92 changes: 47 additions & 45 deletions ecolex/templates/bits/ga.html
Original file line number Diff line number Diff line change
@@ -1,56 +1,58 @@
{% if settings.GA_ENABLED %}
<script>
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','https://www.google-analytics.com/analytics.js','ga');

var ecolex_code = '{{ settings.ECOLEX_CODE }}',
informea_code = '{{ settings.INFORMEA_CODE }}',
faolex_code = '{{ settings.FAOLEX_CODE }}',
faolex_code_2 = '{{ settings.FAOLEX_CODE_2 }}';

ga('create', ecolex_code, 'auto');
ga('send', 'pageview');

ga('create', informea_code, 'auto', {'name': 'informea'});
ga('create', faolex_code, 'auto', {'name': 'faolex'});
ga('create', faolex_code_2, 'auto', {'name': 'allSites'});

document.source = "ecolex"
if (document.informea_url) {
document.referrer = document.location.href;
document.source = "informea";
send_hit('informea', document.informea_url)
} else if (document.faolex_url) {
if (!document.referrer && document.referrer.indexOf('informea.org/') == -1) {
if ($.cookie('analyticsState') == 'true'){
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','https://www.google-analytics.com/analytics.js','ga');

var ecolex_code = '{{ settings.ECOLEX_CODE }}',
informea_code = '{{ settings.INFORMEA_CODE }}',
faolex_code = '{{ settings.FAOLEX_CODE }}',
faolex_code_2 = '{{ settings.FAOLEX_CODE_2 }}';

ga('create', ecolex_code, 'auto');
ga('send', 'pageview');

ga('create', informea_code, 'auto', {'name': 'informea'});
ga('create', faolex_code, 'auto', {'name': 'faolex'});
ga('create', faolex_code_2, 'auto', {'name': 'allSites'});

document.source = "ecolex"
if (document.informea_url) {
document.referrer = document.location.href;
document.source = "informea";
send_hit('informea', document.informea_url)
} else if (document.faolex_url) {
if (!document.referrer && document.referrer.indexOf('informea.org/') == -1) {
document.referrer = document.location.href;
}
document.source = "faolex";
send_hit('faolex', document.faolex_url);
send_hit('allSites', document.faolex_url);
}
document.source = "faolex";
send_hit('faolex', document.faolex_url);
send_hit('allSites', document.faolex_url);
}

function send_hit(tracker_name, url) {
ga(tracker_name + '.set', 'referrer', document.referrer);
ga(tracker_name + '.set', 'hostname', "www.ecolex.org");
ga(tracker_name + '.set', 'location', url);
ga(tracker_name + '.send', 'pageview');
}
function send_hit(tracker_name, url) {
ga(tracker_name + '.set', 'referrer', document.referrer);
ga(tracker_name + '.set', 'hostname', "www.ecolex.org");
ga(tracker_name + '.set', 'location', url);
ga(tracker_name + '.send', 'pageview');
}

function outbound_pdf_link() {
// category, action, label
ga('send', 'event', 'OutboundLink', document.source, this.href);
function outbound_pdf_link() {
// category, action, label
ga('send', 'event', 'OutboundLink', document.source, this.href);

if (document.source == "faolex") {
// Hit faolex
send_hit('faolex', document.faolex_url);
if (document.source == "faolex") {
// Hit faolex
send_hit('faolex', document.faolex_url);
}
}
}

window.addEventListener('load', function () {
// setup handlers
$(".file-link").click(outbound_pdf_link);
});
window.addEventListener('load', function () {
// setup handlers
$(".file-link").click(outbound_pdf_link);
});
}
</script>
{% endif %}
68 changes: 41 additions & 27 deletions ecolex/templates/layout.html
Original file line number Diff line number Diff line change
Expand Up @@ -263,34 +263,48 @@

</script>

<script type="text/javascript">
(function() {
if ($.cookie('ivisited') != "true") {
var setCookie = function () {
$.cookie('ivisited', 'true');
cookieDisclaimer.parentNode.removeChild(cookieDisclaimer);
window.removeEventListener('scroll', setCookie, false);
};
var cookieDisclaimer = document.createElement('DIV');
cookieDisclaimer.classList.add ('cookie-message');
cookieDisclaimer.innerHTML = '<p>In order to understand how people use our site generally, and to create more valuable experiences for you, we may collect data about your use of this site (both directly and through our partners).<br>By using this Website you agree to the use of cookies.</p>' +
'<a class="btn btn-blue" href> OK </a>';
cookieDisclaimer.addEventListener('click', setCookie, false);
window.addEventListener('scroll', setCookie, false);
document.body.appendChild(cookieDisclaimer);
}

<script type="text/javascript">

(function() {

if ($.cookie('ivisited') != "true") {
var setCookie = function () {
$.cookie('ivisited', 'true');
cookieDisclaimer.parentNode.removeChild(cookieDisclaimer);
window.removeEventListener('scroll', setCookie, false);
};
var cookieDisclaimer = document.createElement('DIV');
cookieDisclaimer.classList.add ('cookie-message');
cookieDisclaimer.innerHTML =
'<p>In order to understand how people use our site generally, and to create more valuable experiences for you, we may collect data about your use of this site (both directly and through our partners).<br>By using this Website you agree to the use of cookies.</p>' +
'<a class="btn btn-blue" href> OK </a>'
;
cookieDisclaimer.addEventListener('click', setCookie, false);
window.addEventListener('scroll', setCookie, false);
document.body.appendChild(cookieDisclaimer);
}
$.cookie('ivisited', 'true');
}())

</script>


<script src="{{ STATIC_URL }}{% version 'js/bootstrap-tour.min.js' %}"></script>
if($.cookie('analyticsState') == null) {
var setCookie = function (event) {
if(event.data.okay == true){
$.cookie('analyticsState', 'true'); }
else{
$.cookie('analyticsState', 'false');
}
};

var cookieDisclaimer = $("body").prepend(
'<div class="cookie-message" id="analytics-state">' +
'<p>Due to The General Data Protection Regulation (GDPR), the user is now in control of the data collected. Ecolex uses Google Analytics, a tool designed to collect user data, analyze it and provide statistics that help the development of a better User Experience. Click "Okay" if you want to allow your data to be processed by Google Analytics.</p>' +
'</div>');
var okButton = $('<a class="btn btn-blue analytics-cookie-btn" href>OK</a>');
var cancelButton = $('<a class="btn btn-blue analytics-cookie-btn" href>Cancel</a>');
cancelButton.click({okay: false}, setCookie);
okButton.click({okay: true}, setCookie);
$('#analytics-state').append(cancelButton);
$('#analytics-state').append(okButton);
}
}())

</script>

<script src="{{ STATIC_URL }}{% version 'js/bootstrap-tour.min.js' %}"></script>
{% include 'bits/ga.html' %}
{% include 'tour.html' %}
{% block endscripts %}
Expand Down