Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URLs added here will be added as <link>s in order, and before the CSS in the editor. You can use the CSS from another Pen by using its URL and the proper URL extension.

+ add another resource

JavaScript

Babel includes JSX processing.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Auto Save

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <div class="tracking-optout">
  <label class="tracking-optout__label" style="display:none">
    <input type="checkbox" class="tracking-optout__input">
    <span class="tracking-optout__status tracking-optout__status--active" style="display:none">
      Currently your visit to this website <strong>is being anonymously tracked</strong> by our Web Analytics Tool. Uncheck this box to stop being tracked.
    </span>
    <span class="tracking-optout__status tracking-optout__status--inactive" style="display:none">
      Currently your visit to this website <strong>is not being tracked</strong> by our Web Analytics Tool. Check this box to activate anonymous tracking and help us improve our website.
    </span>
  </label>
  <span class="tracking-optout__dnt" style="display:none">
    You have activated the <em>Do Not Track</em> option in your browser settings. This setting is being respected by our Web Analytics Tool on our website. There’s no need for you to opt-out of this website’s data tracking.
  </span>
  <span class="tracking-optout__oldie" style="display:none">
    Your browser appears to be too old to support this feature. For more privacy control please update your browser.
  </span>
  <noscript>
    It appears you have deactived Javascript in your browser. This feature is only available with Javascript turned on. If you don’t want your data to be collected, you can still turn on <em>Do Not Track</em> in your browser which is a general setting and is being respected by our tracking installation.
  </noscript>
</div>
              
            
!

CSS

              
                body {
  padding: 50px;
  max-width: 30em;
  margin: auto;
}

.tracking-optout__label {
  display: flex;
  align-items: baseline;
}

.tracking-optout__input {
  margin-right: 0.5em;
}

              
            
!

JS

              
                /**
 * Set the options for trackingOptout:
 * `doNotTrackRespected`: Set whether you have your installation respect the browser’s DoNotTrack option
 * `storageKey`: Set the name of the key where the current status get's saved
 * `enabledPerDefault`: Set this to true if you want the tracking enabled per default
 */
const OPTIONS = {
  doNotTrackRespected: true,
  storageKey: "trackingEnabled",
  enabledPerDefault: true
};

function isMSExternal(external) {
  return "msTrackingProtectionEnabled" in external;
}

/**
 * get the browser’s DoNotTrack setting
 * @var DO_NOT_TRACK boolean
 */
const DO_NOT_TRACK = (() => {
  const dnt =
    window.doNotTrack || navigator.doNotTrack || navigator.msDoNotTrack;
  if (dnt === "1" || dnt === "yes") {
    return true;
  }
  // All versions of IE
  if (window.external && isMSExternal(window.external)) {
    return window.external.msTrackingProtectionEnabled();
  }
  return false;
})();

/**
 * Return the string for select elements
 * @param {string} element
 * @param {string} modifier
 */
function selector(element, modifier) {
  return (
    ".tracking-optout" +
    (element ? `__${element}` : "") +
    (modifier ? `--${modifier}` : "")
  );
}

/**
 * Return an array from nodes
 * @param selector
 * @param context
 */
function nodeArray(selector) {
  return [].slice.call(document.querySelectorAll(selector));
}

/**
 * Save all checkboxes in an array
 */
const CHECKBOXES = nodeArray(selector("input"));

/**
 * Set visibility of elements
 * @param {string} selector
 * @param {boolean} show
 */
function visibility(selector, show) {
  nodeArray(selector).forEach((element) => {
    element.style.display = show ? null : "none";
  });
}

/**
 * Remove elements from the dom
 * @param {string} selector
 */
function remove(selector) {
  nodeArray(selector).forEach((element) => {
    element.parentNode.removeChild(element);
  });
}

/**
 * Hide elements
 * @param {string} selector
 */
function hide(selector) {
  visibility(selector, false);
}

/**
 * Show elements
 * @param {string} selector
 */
function show(selector) {
  visibility(selector, true);
}

/**
 * Display the current status of the tracking (enabled or not)
 * @param {bool} enable
 */
function displayStatus(enable) {
  CHECKBOXES.forEach((checkbox) => {
    checkbox.checked = enable;
  });
  trackingOptout.enabled = enable;
  hide(selector("status"));
  show(selector("status", enable ? "active" : "inactive"));
}

/**
 * Set Status
 * @param {bool} enable
 */
function setStatus(enable) {
  localStorage.setItem(OPTIONS.storageKey, enable ? "true" : "false");
  displayStatus(!!enable);
  return !!enable;
}

/**
 * Toggle the status
 */
function toggleStatus() {
  const status = !trackingOptout.enabled;
  setStatus(status);
  return status;
}

/**
 * Log if do not track is active and toggle or set is called
 */
function forbidden() {
  console.log("Do not track is enabled, so no tracking where enabled");
  return false;
}

const trackingOptout = {
  doNotTrack: DO_NOT_TRACK,
  enabled: null,
  toggle: toggleStatus,
  set: setStatus
};

(() => {
  const OLDIE = selector("oldie");
  const DNT = selector("dnt");
  const LABEL = selector("label");

  if (DO_NOT_TRACK && OPTIONS.doNotTrackRespected) {
    remove(OLDIE);
    show(DNT);
    trackingOptout.enabled = false;
    trackingOptout.set = forbidden;
    trackingOptout.toggle = forbidden;
    return;
  }
  remove(DNT);
  if (typeof Storage !== "undefined") {
    remove(OLDIE);
    const SAVED_STATUS = localStorage.getItem(OPTIONS.storageKey);
    if (SAVED_STATUS === null) {
      // Set default value
      setStatus(OPTIONS.enabledPerDefault);
    } else {
      displayStatus(SAVED_STATUS === "true");
    }
    CHECKBOXES.forEach((input) => {
      input.addEventListener("change", toggleStatus);
    });
    show(LABEL);
    return;
  }
  remove(LABEL);
  show(OLDIE);
})();

window.trackingOptout = trackingOptout;

              
            
!
999px

Console