Skip to content

Instantly share code, notes, and snippets.

@luizfaias
Last active October 15, 2019 13:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save luizfaias/e04f45466dd6d45de5e8066f572932f0 to your computer and use it in GitHub Desktop.
Save luizfaias/e04f45466dd6d45de5e8066f572932f0 to your computer and use it in GitHub Desktop.
Zendesk Help Center - cookies consent banner
<meta content="width=device-width, initial-scale=1.0" name="viewport" />
<script>
$(function() {
var cookies_accepted = localStorage.getItem('cookies_accepted');
if (cookies_accepted !== 'true') {
$("#cookie-consent-banner").show();
}
$("#cookie-consent-banner .close").click(function() {
localStorage.setItem("cookies_accepted", true);
$("#cookie-consent-banner").hide();
});
});
</script>
<style>
#cookie-consent-banner {
padding: 10px;
background: hsl(45, 100%, 81%);
z-index: 9999999;
text-align: center;
display: none;
}
#cookie-consent-banner .close {
padding-left: 10px;
}
</style>
<div id="cookie-consent-banner">
<span>Just a heads up: we use cookies, ok?</span>
<a class="close" href="#">X</a>
</div>
@luizfaias
Copy link
Author

I might have missed something here. If you're talking about defining how cookies are used for the Web Widget, you should use the updateSettings API. Here's an example:

<script>
	window.zESettings = {
		cookies: false
	};
	
	$(document).ready(function() {
		var cookies_accepted = localStorage.getItem('cookies_accepted');
		if (cookies_accepted !== 'true')) {
			$("#cookie-consent-banner").show();
		}
		
		$("#cookie-consent-banner .close").click(function() {
			localStorage.setItem("cookies_accepted", true);
			$("#cookie-consent-banner").hide();
			zE('webWidget', 'updateSettings', {
				cookies: true
			});
		});
	});
</script>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment