Skip to content

Commit

Permalink
switch to msft cookie consent (#1030)
Browse files Browse the repository at this point in the history
  • Loading branch information
missusmy authored and jonels-msft committed Mar 12, 2022
1 parent 3b252eb commit 80de019
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 71 deletions.
7 changes: 7 additions & 0 deletions _static/css/citus.css
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,13 @@ footer span.commit code {
color: #404040 !important;
}

footer a:not(:hover, :focus, .btn) {
color: #1e873d!important;
}
footer a:hover:not(.btn), footer a:focus:not(.btn) {
color: #2cc95c!important;
}

/* Cookie consent */

#consentBox {
Expand Down
124 changes: 53 additions & 71 deletions _templates/page.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,27 +6,6 @@
#}

{% block extrahead %}
{# track only after cookie consent is obtained #}
<script>
/*
Global variable shared with cookie consent dialog code.
This is to use its value uniformly throughout the page.
*/
window.g_cookieConsentId = 'CitusCookieConsentCorner';

if (document.cookie.indexOf(window.g_cookieConsentId) == -1) {
window.YETT_BLACKLIST = [
/munchkin\.marketo\.net/,
/sjs\.bizographics\.com/,
/doubleclick\.net/,
/cdn\.heapanalytics\.com/,
];
} else {
console.log("Cookies already accepted");
window.YETT_BLACKLIST = [ ];
}
</script>
<script src='https://unpkg.com/yett'></script>

{{ super() }}

Expand Down Expand Up @@ -64,6 +43,10 @@
{% endif %}
{% endblock %}

{% block header %}
<div id="cookie-banner"></div>
{% endblock %}

{% block sidebartitle %}
<a class="skiplink" href="#maincontent">Skip to main content ></a>
<a href="https://citusdata.com" class="homepage">
Expand All @@ -78,68 +61,67 @@

{{ super() }}

<div class="new" id="consentBox">
<div class="consent-text">
<p>This site uses cookies for analytics, personalized content and ads. By continuing to browse this site, you agree to this use. <a href="https://www.citusdata.com/privacy#cookies" id="cookiesLink">Learn&nbsp;more</a>.</p>
</div>
<div class="consent-button">
<button class="btn" id="closeConsent">CLOSE</button>
</div>
</div>

{% endblock %}

{% block footer %}
{{ super() }}

{# Heap Analytics #}
<script type="text/javascript">
window.heap=window.heap||[],heap.load=function(e,t){window.heap.appid=e,window.heap.config=t=t||{};var r=t.forceSSL||"https:"===document.location.protocol,a=document.createElement("script");a.type="text/javascript",a.async=!0,a.src=(r?"https:":"http:")+"//cdn.heapanalytics.com/js/heap-"+e+".js";var n=document.getElementsByTagName("script")[0];n.parentNode.insertBefore(a,n);for(var o=function(e){return function(){heap.push([e].concat(Array.prototype.slice.call(arguments,0)))}},p=["addEventProperties","addUserProperties","clearEventProperties","identify","removeEventProperty","setEventProperties","track","unsetEventProperty"],c=0;c<p.length;c++)heap[p[c]]=o(p[c])};
heap.load("4002524638");
<script>
var cookieBanner = document.createElement('div');
cookieBanner.id = 'cookie-banner';
document.body.prepend(cookieBanner);
</script>

{# cookie consent dialog #}

<script src='https://cdnjs.cloudflare.com/ajax/libs/jquery-cookie/1.4.1/jquery.cookie.min.js'></script>
{# msft standard cookie script #}
<script src='https://wcpstatic.microsoft.com/mscc/lib/v2/wcp-consent.js'></script>

{# cookie consent script #}
<script type="text/javascript">
$(document).ready(function() {
/* Uses global window.g_cookieConsentId defined in the <head> */

var consentValue = 'Consented';

var clickConsent = function () {
if ($("#consentBox").is(":visible")) {
if (typeof(window.yett) == 'object' &&
typeof(window.yett.unblock) == 'function') {
window.yett.unblock();
} else {
console.log("clickConsent: Unable to access window.yett.unblock()");
function loadHeap() {
window.heap=window.heap||[],heap.load=function(e,t){window.heap.appid=e,window.heap.config=t=t||{};var r=t.forceSSL||"https:"===document.location.protocol,a=document.createElement("script");a.type="text/javascript",a.async=!0,a.src=(r?"https:":"http:")+"//cdn.heapanalytics.com/js/heap-"+e+".js";var n=document.getElementsByTagName("script")[0];n.parentNode.insertBefore(a,n);for(var o=function(e){return function(){heap.push([e].concat(Array.prototype.slice.call(arguments,0)))}},p=["addEventProperties","addUserProperties","clearEventProperties","identify","removeEventProperty","setEventProperties","track","unsetEventProperty"],c=0;c<p.length;c++)heap[p[c]]=o(p[c])};
heap.load("4002524638");
console.log("loading tracking scripts");
}
function onConsentChanged(categoryPreferences) {
ga('send', 'event', 'cookie consent', 'changed', window.location.href + "(" + categoryPreferences + ")");
console.log("onConsentChanged", categoryPreferences);
if (categoryPreferences.Analytics) {
loadHeap();
}
}
function manageConsent() {
if(siteConsent.isConsentRequired){
siteConsent.manageConsent();
}
}
window.WcpConsent && WcpConsent.init("en-US", "cookie-banner", function (err, _siteConsent) {
if (!err) {
siteConsent = _siteConsent;
console.log(siteConsent);
if (_siteConsent.isConsentRequired == false) {
loadHeap();
var mngLink = document.createElement('span'),
userConsent = siteConsent.getConsent();
mngLink.innerHTML = '<a href="https://privacy.microsoft.com/privacystatement" target="_blank" rel="noopener">Privacy Statement</a><br><br>';
document.querySelector("footer div[role=contentinfo]").prepend(mngLink);
}
else {
var mngLink = document.createElement('span'),
userConsent = siteConsent.getConsent();
mngLink.innerHTML = '<a href="https://privacy.microsoft.com/privacystatement" target="_blank" rel="noopener">Privacy</a> | <a href="javascript:void(0)" id="mng-cookies">Manage Cookies</a><br><br>';
document.querySelector("footer div[role=contentinfo]").prepend(mngLink);
if (userConsent.Analytics == true) {
loadHeap();
}
// "slideUp" means "hide," it is not a direction of movement
$("#consentBox").slideUp("linear");
$.cookie(window.g_cookieConsentId, consentValue, {
expires: 365,
path: '/'
var clickMng = document.querySelector('#mng-cookies');
clickMng.addEventListener('click', function (event) {
manageConsent();
});
if (typeof(ga) == 'function') {
ga('set', 'allowAdFeatures', true);
ga('send', 'event', 'cookie consent', 'accept', window.location.href);
} else {
console.log("clickConsent: Unable to access ga()");
}
}
};

// continuing to interact with the page consents to cookies
$("a:not(#cookiesLink), button, iframe, input, [data-toggle*='wy-nav-top'], [data-toggle*='rst-current-version']").on(
"click", clickConsent
);

if ($.cookie(window.g_cookieConsentId) != consentValue) {
// "slideDown" means "show," it's not a direction of movement
$("#consentBox").slideDown("linear");
} else {
console.log("Error initializing WcpConsent: "+ err);
}
});
}, onConsentChanged, WcpConsent.themes.dark);
window.consentCheckRequired = true;
</script>
{% endblock %}

0 comments on commit 80de019

Please sign in to comment.