Implementing Privacy Management

  1. Adding the BlueConic script to your website
    The first step of implementing BlueConic Privacy Management is to add the BlueConic script to all pages of your website.

  2. Configuring the Privacy Management Dialogs in BlueConic

    Read Privacy Management in BlueConic to get started with configuring.

  3. Adapting your website to the objectives
    The visitor can consent or refuse objectives. Relevant information is stored in these profile properties:

    • Privacy legislation: The legislation that applies to the visitor ("GDPR" or "NONE").
    • Consented objectives: The objectives that the visitor consented to.
    • Refused objectives: The objectives that the visitor refused.


    Below you will find several pieces of example JavaScript code that can be used to adapt your website to the various consented objectives. The code is in no way mandatory to use and only serves as reference implementation.

    Utility function to check visitor consent in BlueConic
    <script>
    /**
     * @param {String|Array} objectiveId One objective id, or an array of objective ids
     * @return {Promise} A promise that resolves with an argument of true if the visitor
     * has consented to all of the specified objectives, or if the visitor does not fall
     * under a specific privacy legislation. Resolves with an argument of false otherwise.
     */
    window.hasBcConsent = function(objectiveId) {
      return new Promise(function(resolve, reject) {
        var subscribeAndResolveBcConsent = function() {
          window.blueConicClient.event.subscribe(window.blueConicClient.event.onBeforeInteractions, {}, function() {
            if (!objectiveId) {
              reject();
            }
    
            // BlueConic profile is ready to get information from
            var profile = window.blueConicClient.profile.getProfile();
            var isNotNeeded = profile.getPrivacyLegislation() === 'NONE';
            var isConsented = false;
    
            if (typeof objectiveId === "string") {
              isConsented = profile.getConsentedObjectives().indexOf(objectiveId) !== -1;
            } else {
              isConsented = objectiveId.every(id => profile.getConsentedObjectives().indexOf(id) !== -1);
            }
    
            resolve(isNotNeeded || isConsented);
          });
        };
    
        if (typeof window.blueConicClient !== 'undefined' &&
            typeof window.blueConicClient.event !== 'undefined' &&
            typeof window.blueConicClient.event.subscribe !== "undefined") {
          // BlueConic is loaded, subscribe to its onBeforeInteractions event
          subscribeAndResolveBcConsent();
        } else {
          // Wait for BlueConic to load
          window.addEventListener('onBlueConicLoaded', function() {
            // BlueConic is loaded, subscribe to its onBeforeInteractions event
            subscribeAndResolveBcConsent();
          }, false);
        }
      });
    };
    </script>
    


    The utility function above provides a way to check consent:
    <script>
      hasBcConsent('analytics').then(function(allowed) {
        if (allowed) {
          // ...
        }
      });
    </script>
    


    Conditionalizing inline JavaScript code
    <script>
      // Check consent to the objective "analytics" before including the external script
      hasBcConsent('analytics').then(function(allowed) {
        if (allowed) {
          var _gaq = _gaq || [];
          _gaq.push(['_setAccount', 'UA-xxxxxxxx-x']);
          _gaq.push(['_trackPageview']);
          (function() {
            var ga = document.createElement('script');
            ga.type = 'text/javascript';
            ga.async = true;
            ga.src = ('http:' == document.location.protocol ?
              'http://ssl' : 'http://www') + '.google-analytics.com/ga.js';
            var s = document.getElementsByTagName('script')[0];
            s.parentNode.insertBefore(ga, s);
          })();
        }
      });
    </script>


    Conditionalizing asynchronous loading of third-party JavaScript libraries
    <script>
      (function() {
        var injectScript = function(url) {
          var iScript = document.createElement('script');
          iScript.src = url;
          iScript.type = "text/javascript";
          (document.getElementsByTagName('head')[0] ||
            document.getElementsByTagName('body')[0]).appendChild(iScript);
        }
    
        // Check consent to the objectives "analytics" and "remarketing" before including the external script
        hasBcConsent(['analytics', 'remarketing']).then(function(allowed) {
          if (allowed) {
            injectScript('http://external.com/script.js');
          }
        });
      })();
    </script>


    Conditionalizing asynchronous loading of third-party JavaScript libraries with callback functions
    <script>
    (function() {
      var injectScriptSynchronously = function(url, callback) {
        var iscript = document.createElement('script');
        iscript.type = 'text/javascript';
        iscript.async = true;
        iscript.src = url;
    
        if (typeof callback === 'function') {
          iscript.onload = iscript.onreadystatechange = function() {
            if (!this.readyState || this.readyState === "loaded" ||
              this.readyState === "complete") {
              try {
                callback();
              } catch (err) {
              }
            }
          };
        }
        (document.getElementsByTagName('head')[0] ||
             document.getElementsByTagName('body')[0]).appendChild(iscript);
      }
    
      function doCallBack() {
        // callback code, which will be executed after script is loaded
      }
    
      // Check consent to the objective "analytics" before including the external script
      hasBcConsent('analytics').then(function(allowed) {
        if (allowed) {
          injectScriptSynchronously('http://external.com/script.js', doCallBack);
        }
      });
    })();
    </script>
    


    Conditionalizing (multiple) synchronous loading of third-party JavaScript libraries
    <script>
    // Check consent to the objective "analytics" before including the external script
    hasBcConsent('analytics').then(function(allowed) {
      if (allowed) {
        // Inject script 1
        injectScriptSynchronously('http://external1.com/script1.js', function() {
          // Inject script 2 after script 1 is done
          injectScriptSynchronously('http://external1.com/script2.js', function() {
            // Both scripts are done
          });
        });
      }
    });
    </script>