Implementation: Tentacles without cookies

In this article you read how you can get smartocto Tentacles to not store cookies. You have the option to feed a partyId and sessionId to smartocto Tentacles, or leave it open.

The smartocto Tentacles-script sets two cookies by default to manage user identification and session tracking on websites. This documentation outlines the default behavior of smartocto Tentacles and provides guidance on customizing cookie settings.

In this article you read about:

- the setting to force the smartocto Tentacles-script to not set cookies

- optional functions to generate values yourself

- how to set the partyId and sessionId

The setting to not set cookies by the Tenacles-script

If there is a need to disable cookie setting by the smartocto Tentacles-script, modify the noCookies property within the tentacles object in the browser window object. By setting noCookies to true, the script will refrain from setting cookies. However, note that backend systems rely on the presence of partyId and sessionId, which should be managed by the website within the tentacles object.

// Disable cookies by setting noCookies to true
  window.tentacles.noCookies = true;

The optional functions to generate values yourself

You can use the optional functions from the code below to generate values.

// Function to generate a unique identifier
  const generateCID = function() {
      return new Date().getTime() + "." + Math.random() * 1000000000;
  }; 

// Function to check if two timestamps are thirty minutes apart
  const isThirtyMinutesApart = function (timestamp1, timestamp2) {
      // Calculate the difference in milliseconds
      const diffInMs = Math.abs(timestamp1 - timestamp2);
      // Convert milliseconds to minutes
      const diffInMinutes = diffInMs / (1000 * 60);
      // Check if the difference is 30 minutes or more
      return diffInMinutes >= 30;
  };

How to set the partyID and sessionID

In the code below you see how to set the values for the partyID and sessionId. Here the functions are used, but you can also use your own generated values.

  // Set partyId if not already set
  if (!window.tentacles.partyId){
    window.tentacles.partyId = generateCID(); // or your own value
  }

  // Set sessionId if not already set, or refresh if 30 minutes have passed
  if (!window.tentacles.sessionId) {
    window.tentacles.sessionId = generateCID(); // or your own value
} else if (window.tentacles.sessionId && isThirtyMinutesApart(new Date().getTime(), window.tentacles.sessionId.split('.')[0])) {
    window.tentacles.sessionId = generateCID(); // or your own value
  }

Example of not setting cookies, and using the functions to generate the ID-values

<script type="text/javascript">

// Function to generate a unique identifier
  const generateCID = function() {
      return new Date().getTime() + "." + Math.random() * 1000000000;
  }; 

// Function to check if two timestamps are thirty minutes apart
  const isThirtyMinutesApart = function (timestamp1, timestamp2) {
      // Calculate the difference in milliseconds
      const diffInMs = Math.abs(timestamp1 - timestamp2);
      // Convert milliseconds to minutes
      const diffInMinutes = diffInMs / (1000 * 60);
      // Check if the difference is 30 minutes or more
      return diffInMinutes >= 30;
  };

  // Ensure the tentacles object exists
  window.tentacles = window.tentacles || {};

  // Disable cookies by setting noCookies to true
  window.tentacles.noCookies = true;

  // Set partyId if not already set
  if (!window.tentacles.partyId){
      window.tentacles.partyId = generateCID();
  }

  // Set sessionId if not already set, or refresh if 30 minutes have passed
  if (!window.tentacles.sessionId) {
      window.tentacles.sessionId = generateCID();
  } else if (window.tentacles.sessionId && isThirtyMinutesApart(new Date().getTime(), window.tentacles.sessionId.split('.')[0])) {
      window.tentacles.sessionId = generateCID();
  }
</script>

 

Important

Please be aware that upon page refresh, the window.tentacles object undergoes reconstruction, resetting its properties, including partyId and sessionId. As demonstrated in the provided example, partyId and sessionId are consistently refreshed. However, in a production environment, it's crucial to store these identifiers according to your specific requirements.

In cases where window.tentacles.noCookies is set to true and neither partyId nor sessionId parameters are defined, the ingestion script will generate these identifiers. However, it won't store them in cookies. Consequently, while visits can still be tracked, the accuracy of unique visitor counts may be compromised.