Connecting Cludo to your cookie consent functionality

It is possible to add development to have the cookies set by Cludo connect with your general cookie consent formula.

For general information on cookies set by Cludo, read this article.

Technical Overview

At the moment Cludo stores session information in local storage that persists across end-user visits, we will invoke the callback function (canUserBeTracked). That function consists of custom JavaScript by yourself that will make a determination if the current end user can or can not be tracked.

The steps and code example in this section apply to Overlay and Legacy Inline search, which use a cludoSettings object and initialize search with new Cludo(cludoSettings). If you use the Rich Inline Template, use window.cludoConfig instead; see Using cookie consent with the Rich Inline Template below.

Implementation instructions

Update cludoSettings to include the callback function (canUserBeTracked), which will be invoked whenever we are about to track a session. This function is expected to return true or false depending on the end user’s selected preferences stored or maintained by the customer.

Code example

Below you can find an example of a typical cludoSettings object with the addition of the canUserBeTracked callback method. You can use this callback to leverage your own criteria for whether or not the user can be tracked and will return true if yes or false if no.

<script type="text/javascript" src="https://customer.cludo.com/scripts/bundles/search-script.js"></script>
<script>
var CludoSearch;
(function () {
  var cludoSettings = {
    customerId: xx,
    engineId: xx,
    searchUrl: '/xxx/',
    ...
    canUserBeTracked: function() {
      // CUSTOM CONSENT DECISION CODE GOES HERE.
      // Has user consented? return true
      // Has user declined? return false
    }
    ...
  };
  CludoSearch = new Cludo(cludoSettings);
  CludoSearch.init();
})();
</script>

If your search is implemented with the Rich Inline Template, configure cookie consent in window.cludoConfig (not cludoSettings). Add the canUserBeTracked callback under the tracking object:

tracking: {
  canUserBeTracked: function () {
    // CUSTOM CONSENT DECISION CODE GOES HERE.
    // Has user consented? return true
    // Has user declined? return false
  }
}

Code example

<script>
  window.cludoConfig = {
    customerId: CUSTOMER_ID,
    engineId: ENGINE_ID,
    language: "en",
    searchUrl: "/search",
    searchInputSelectors: ["#cludo-search-input"],
    tracking: {
      canUserBeTracked: function () {
        // CUSTOM CONSENT DECISION CODE GOES HERE.
        // Has user consented? return true
        // Has user declined? return false
      }
    }
  };
</script>
<script src="https://customer.cludo.com/scripts/bundles/search-script.min.js" type="text/javascript" defer></script>
<script src="https://customer.cludo.com/templates/rich-inline/v1.0/dist/js/cludo-search-results.js" type="text/javascript" defer></script>

The callback behaves the same as in the classic implementation: return true to allow session tracking in local storage, or false to prevent it. See the Technical breakdown section below for the implications of each return value.

Technical breakdown

The canUserBeTracked callback can return true or false. Below, you can find a brief overview of the implications for returning each.

Return valueOutcome
trueReturning true (user can be tracked) allows CludoJS to set local storage data that enables CludoJS to track session data such that multiple searches, across multiple page views, will be part of the same session. Tracking of sessions allows MyCludo analytics to report on unique searches, whereas if we are unable to track sessions, we can’t necessarily differentiate unique searches.
falseReturning false prevents CludoJS from storing information about the session in local storage. Searches that occur across pages, tabs, or windows will not be associated with each other as one session.

Tags: