This website is printer-friendly. Please Print this article and share it with your friends and family.
Functional cookies';
document.addEventListener("DOMContentLoaded", function(event) {
var allowGA = true;
var gaProperty = 'UA-131640601-3';
var disableStr = 'ga-disable-' + gaProperty;
// checking for opt-out cookie on document and applying to window if set
if (document.cookie.indexOf(disableStr + '=true') > -1) {
window[disableStr] = true;
allowGA = false;
}
$('#cmplz_stats').prop('checked', allowGA);
// user is opting out, setting cookie on document, window and alerting success
function gaOptout() {
document.cookie = disableStr + '=true; expires=Thu, 31 Dec 2099 23:59:59 UTC; path=/';
window[disableStr] = true;
Cookies.remove('_ga', { path: '/', domain: '.ifamericansknew.org'});
Cookies.remove('_gid', { path: '/', domain: '.ifamericansknew.org'});
Cookies.remove('_gat', { path: '/', domain: '.ifamericansknew.org'});
// alert('Google Analytics Tracking is now deactivated!');
}
// Google Analytics as usual from here on
(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');
ga('create', gaProperty, 'auto');
ga('send', 'pageview', {
'anonymizeIp': true
});
// cookiePrefs not set
if (Cookies.get('cookiePrefs') == undefined) {
// add prefs bar to bottom of page
$('body').append(policyStyles).append(policyBar);
console.log('point 1');
// find country
$.get("https://api.hostip.info/country.php", function(response) {
showPrefsBar(response);
})
.fail( function(err) {
console.error('Could not detect country. Defaulting to EU.');
// document.getElementById("EU").classList.add('visible');
showPrefsBar('EU');
})
.done( function() {
setTimeout(function(){ console.log('showing it'); document.getElementById('cc-window').classList.add('show'); }, 1000);
});
////////////////////////////////
// test data //
// showPrefsBar('US');
// setTimeout(function(){ document.getElementById('cc-window').classList.add('show'); }, 1000);
////////////////////////////////
const showPrefsBar = (countryCode) => {
console.log('point 2');
if (countryCode == "US") document.getElementById("US").classList.add('visible');
else {
document.getElementById("EU").classList.add('visible');
Cookies.set('EU_visitor', true, {expires: 365});
}
$('body').on('change', '#cmplz_stats', function() {
allowGA = $('#cmplz_stats').is(':checked');
})
$('body').on('click', '.setPrefs', function(e){
console.log('clicked it');
e.preventDefault();
if ( !allowGA ) gaOptout();
Cookies.set('cookiePrefs', 'set', {expires: 365});
if ( $(window).width() > 667 ) $('#cc-window').animate({'bottom':'-50px'}, 1000);
else {
console.log('mobile');
$('#cc-window .cc-compliance a.cc-save').css('width', '100%');
$('#cc-window').animate({'bottom':'-150px'}, 1000);
}
});
}
}
// cookiePrefs set
else {
}
// set cookies and privacy URLs in footer
if (Cookies.get('EU_visitor')) {
$('#PrivacyFooterLink').attr('href', '/about_us/privacy-eu.html');
$('#CookiesFooterLink').attr('href', '/about_us/cookie-policy-eu.html');
}
});
|