How do I add an opt out privacy button on my website?

You can link users to the Lucky Orange  privacy page which includes a button to opt out globally from sites using Lucky Orange. Or, if you'd like to do this on your site directly, the Lucky Orange code exposes a few API calls to help with this.

Lucky Orange API Functions:

LO.is_opted_out(); // returns true if they are opted out, or false if tracking
LO.opt_out(); // marks a 1st party cookie to opt out of tracking
LO.opt_in(); // removes the cookie to allow tracking again</strong>

Sample Code:
Here is some sample code to help you create a toggleable Opt Out button. The code waits for Lucky Orange to load and then shows the opt in/out buttons according to the status of the current user. Paste it where you want the button to appear.

<!-- The Opt Out Buttons, start hidden, change words and styling as needed -->
<button id="lo_toggle_opt_out_btn" style="display:none">Opt Out</button>
<button id="lo_toggle_opt_in_btn" style="display:none">Opt In</button>

<script>
/* Lucky Orange Opt in Opt Out code */
(function(){
	// cross browser event listener
	function addEvent(elem, event, fn) {
	    if (elem.addEventListener) {
	        elem.addEventListener(event, fn, false);
	    } else {
	        elem.attachEvent("on" + event, function() {
	            // set the this pointer same as addEventListener when fn is called
	            return(fn.call(elem, window.event));   
	        });
	    }
	}
	function toggle_opt_in_btns()
	{
			if (window.LO && window.LO.is_opted_out())
		 	{
		 		// now opt back in
		 		window.LO.opt_in();
		 	}
		 	else if (window.LO)
		 	{
		 		// now opt out
		 		window.LO.opt_out();
		 	}
		 	// show or hide the right ones
		 	show_hide_opt_in_btns();
	}
	function show_hide_opt_in_btns()	{
		var opt_in_btn = document.getElementById("lo_toggle_opt_in_btn");
    		var opt_out_btn = document.getElementById("lo_toggle_opt_out_btn");
    		if (opt_out_btn && opt_in_btn)
    		{
			if (window.LO && window.LO.is_opted_out())
		 	{
		 		// they are currently opted out so show the opt in button
		 		opt_in_btn.style.display = 'block';
		 		opt_out_btn.style.display = 'none';
		 	}
		 	else
		 	{
		 		// they are currently opted in so show the opt out button
		 		opt_in_btn.style.display = 'none';
		 		opt_out_btn.style.display = 'block';
		 	}
    		}
	}
     window.lo_on_loaded = function(){
     	// this is called when Lucky Orange is loaded on the page
     	try {
     			var opt_in_btn = document.getElementById("lo_toggle_opt_in_btn");
    			var opt_out_btn = document.getElementById("lo_toggle_opt_out_btn");
     			if (opt_out_btn && opt_in_btn)
     			{
	     			// set event listeners for buttons
	     			addEvent(opt_in_btn, "click", toggle_opt_in_btns);
	     			addEvent(opt_out_btn, "click", toggle_opt_in_btns);
	     			// show or hide the correct buttons
	     			show_hide_opt_in_btns();
     			}
     	} catch (e) {}
     }
})();
</script>

Still need help? Contact Us Contact Us