Behavior Tracking > Tracking Opt In and Out

Tracking Opt In and Out

By default, when the OneSpot Tag is installed on your site, we will track a user’s behavior throughout the site. OneSpot provides methods to allow a user to opt out or opt in to being tracked.

In the document head, set a global variable _onSiteQ as shown below, then use _onSiteQ.push(fn) to add functions to the queue for execution when the Onsite script has been loaded, or immediately execute if the script is already loaded.
HTML
<head>
  <script>
    var _onSiteQ = _onSiteQ || [];
  </script>
  <!-- OneSpot script should be included BELOW the _OnSiteQ -->
</head>
Method Parameters Description
window.onespot.tracking.optOut none Call this method within a function pushed to the _onSiteQ (see below) to opt a user out of OneSpot tracking.
window.onespot.tracking.optIn none By default, tracking is turned on for all users. If a user has previously opted out, they can be opted back in. To do so, call this method within a function pushed to the _onSiteQ (see below) to opt a user into OneSpot tracking. Example Usage
Here is an example of how integrate Onespot tracking methods into your own tracking consent flow:
HTML
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <script>
      var _onSiteQ = _onSiteQ || [];
    </script>
    
  <!--START ONESPOT SCRIPT-->
	<link rel="dns-prefetch" href="https://d2vxvnufz8f5c5.cloudfront.net" />
	<script src="https://d2vxvnufz8f5c5.cloudfront.net/4xrt6r.bundle.js" async></script>
<!--END ONESPOT SCRIPT-->

  <!--START ONESPOT CSS-->
  <link rel="stylesheet" type="text/css" href="https://d2vxvnufz8f5c5.cloudfront.net/4xrt6r.css" />
  <!--END ONESPOT CSS-->
  
    <script>
        function myOptOutFn() {
          window.onespot.tracking.optOut();
          console.log("opt out");
        }

        function myOptInFn() {
          window.onespot.tracking.optIn();
          console.log("opt in");
        }
    </script>
</head>
<body>
    <div id="opt-out" onclick="_onSiteQ.push(myOptOutFn)">Opt Out of Tracking</div>
    <div id="opt-in" onclick="_onSiteQ.push(myOptInFn)">Opt Into Tracking</div>
</body>
</html>