Page cover

On-Premise CAID

The CAID cookie is a crucial element in tracking visitors to your site.

Used by Commanders Act, it identifies and tracks a visitor's path through different browsing sessions. Its construction is essential, especially in the context of restrictions imposed by privacy and security policies such as ITP (Intelligent Tracking Prevention). You must build it yourself in the case of "First Party" tracking via CNAME or A-Record, but it is not necessary if you use a proxy. In this documentation, you'll find all the information you need to build an ITP.

  1. Cookie name :

  • Name: "CAID" (in uppercase).

  1. Cookie structure recommendation :

  • Contains 20 random digits.

  • Preceded by the year the cookie was created.

  1. Service life :

  • Expiry date: 13 months after creation by default (GDPR)

You can adjust the cookie duration according to the legal restrictions of the region where the site is visited.

  1. Creation and Registration :

  • Created by the company's server.

  • Deposited on the main domain and all associated sub-domains. (.mydomain.com)

  1. Accessibility :

  • Secure = true

  • httpOnly = true

Ex. CAID = 2024013114175312331154022

PHP Example

<?php
 
$cookie_name = "CAID";
$year = date("Y");
$random_numbers = substr(str_shuffle(str_repeat("0123456789", 20)), 0, 20);
$cookie_value = $year . $random_numbers;
$expiration = time() + 13 * 30 * 24 * 60 * 60; // 13 mois
$path = "/"; // Disponible sur tout le domaine
 
// Utilisation d'un tableau pour les options du cookie
$cookie_options = [
    "expires" => $expiration,
    "path" => $path,
    "secure" => true, // Activation du flag secure
];
 
setcookie($cookie_name, $cookie_value, $cookie_options);

?>

Node.js Example (package ‘express‘)

const express = require('express’);
const app = express();

function generateRandomNumbers() { 
return Array.from({ length: 20 }, () => Math.floor(Math.random() * 10)).join(‘’); 
} 

app.get('/', (req, res) => { 
   const year = new Date().getFullYear(); 
   const randomNumbers = generateRandomNumbers(); 
   res.cookie('CAID', year + randomNumbers, { maxAge: 13 * 30 * 24 * 60 * 60 * 1000, // 13 mois en millisecondes
      path: '/’, 
      httpOnly: true // Sécurité renforcée 
   }); 
   res.send('Cookie set'); }); 

app.listen(3000, () => { 
   console.log('Server is running on port 3000’); 
});

Python Example (avec Flask)

from flask import Flask, make_response 
from datetime import datetime, timedelta 
import random 
app = Flask(__name__) 
def generate_random_numbers(): 
	return ''.join([str(random.randint(0, 9)) for _ in range(20)]) 
@app.route('/’) 
def set_cookie(): 
	resp = make_response("Setting cookie") 
	expire_date = datetime.now() + timedelta(days=13*30) 
	year = datetime.now().year 
	random_numbers = generate_random_numbers() 
	resp.set_cookie('CAID', f'{year}{random_numbers}', expires=expire_date) 
	return resp 
if __name__ == "__main__": 
	app.run(port=5000)

Ruby Example

require 'sinatra’ 
require 'securerandom’ 

get '/' do 
random_numbers = SecureRandom.random_number(10**20).to_s.rjust(20, '0’) 
year = Time.now.year 
response.set_cookie('CAID', { value: "#{year}#{random_numbers}", expires: Time.now + (13 * 30 * 24 * 60 * 60), path: '/' }) "Cookie set" 
end

Last updated