# Akamai
# Gate integration
We're going to use Akamai to :
- Redirect directly to the First-id system. The redirection will be performed if :
- the cookie indicating that the user has given consent is present
- a cookie containing the First-id identifier is not already present
- FACULTATIVE : You have the user's SHA256 hashed email in a cookie
- Set the cookie with the First-id ID obtained during redirection.
- Redirect the user to the original page, removing the query param
firstIdfrom the URL, while keeping the other initial query params, as well as the hash fragments (#) of the URL.
Terminology
In the following implementation example, we consider that :
- The cookie containing the user's consent is called :
YOUR_CONSENT_COOKIE. - The mere presence of this cookie indicates the user's acceptance of the CMP; we do not check its value.
- The cookie containing the identifier generated by the First-id system is called :
firstid.
Here's a sequence diagram assuming that the consent cookie is set on your domain :
On Akamai, go to your account on the property corresponding to your website.
Click on the version currently deployed in the Manage Versions and Activations panel.

Click on the Edit a new version button.

We'll have to deal with 2 cases :
- The user has a
YOUR_CONSENT_COOKIEcookie and no cookie containing the First-id identifier. - The user has just been redirected by the First-id system and we need to clean up the URL and redirect him to his original page.
To do this, we'll need to define 4 variables.
In the Property Variables block, click on the "Add Variable" button at the end of the line.

These 4 variables are as follows:
REDIRECT_URI_URL_ENCODE: This will contain the redirection URI to which we want to redirect the end user at the end of the process, encoded in urlEncode. This is the current page at the start of the process.FIRSTID: Contains the unique First-id identifier received following redirection from the First-id system.REDIRECT_HOST_URL_ENCODE: Contains the host to which we wish to redirect the end user at the end of the process, encoded in urlEncode. This is the host of the current page at the start of the process.REDIRECT_URI: Contains the decoded redirection URI.
Variable naming
These variable names are completely arbitrary, and you are free to choose others. Just keep the following steps consistent.
URL encoding
The redirectHost and redirectUri parameters must be encoded in urlEncode to be correctly interpreted.
In the Property Configuration Settings section, we'll need to create two rules.
Click on the Add Rule button.

Choose Blank Rule Template and name the First-id - Get ID.

Click on Insert Rule.
We have three criteria to define that must be met for this rule to be triggered:
- The user has a
YOUR_CONSENT_COOKIEcookie - AND the user has no
firstidcookie - Caller's user-agent is not a Bot
Cookie First-id terminology
In the following, we'll refer to a "First-id" cookie to avoid the term "cookie containing the identifier generated by the First-id system". But this cookie is by no means a third-party cookie. It is deposited on your main domain as a Secure first party cookie (see Cookie deposit).
HTTPOnly
To retrieve the firstid cookie in client-side JavaScript, we do not recommend setting the httpOnly attribute.
Select Match All in the selector next to the Criteria title and click on the Add Match button to add the first criterion.

Configure the criterion as follows :

Click the Add Match button again to add the second criterion and configure it as follows :

Click the Add Match button again to add the third criterion, and configure it as follows :

This is the list of crawlers in the example. Each line corresponds to a filtering rule in Regex form, applied to the HTTP User-Agent header :
- "bot"
- "google"
- "facebook"
- "crawl"
- "yahoo"
- "bing"
- "curl"
- "parse.ly"
- "amp-validator"
- "amphtml-validator"
- "validator.amp.dev"
- "seoPrisma"
- "iframely"
- "SpeedCurve"
- "Convert NL Grabber"
- "NL-Factory Grabber"
- "outbrain"
- "Bot"
- "Google"
- "Slurp"
- "ia_archiver"
- "Screaming Frog SEO Spider"
- "grapeshot"
- "ias_crawler"
- "proximic"
- "Qwantify"
- "Pinterest"
- "360Spider"
- "Flipboard"
- "weborama-fetcher"
- "upday"
- "babbar.tech"
- "TTD-Content"
- "Chrome-Lighthouse"
Bot Crawler
To avoid any SEO problems, we advise you to apply this criterion to avoid sending 302s to bots crawling your site. The list of bots present is not exhaustive, and we advise you to update it regularly.
Let's move on to the Behaviors. We'll need to :
- Assign the current URI to our
PMUSER_REDIRECT_URI_URL_ENCODEvariable, encoding it as urlEncode - Assign the current host to our
PMUSER_REDIRECT_HOST_URL_ENCODEvariable, encoding it in urlEncode. - Redirect to the First-id system
Click on the Add Behavior button.

In the modal that opens, select Set Variable you can also use the search engine.

Click on the orange Insert Behavior button at the bottom right of the modal.
Configure the behavior as follows :

Akamai Variables
Note the use of the expression builtin.AK_URL, in fact AK_URL is one of the many variables provided by Akamai. You can find the full list in the Akamai documentation (opens new window)
Add a new behavior of type Set Variable and configure it as follows :

Now that we've finished with the variables, we can move on to the redirection to the First-id system. To do this, add a behavior of type Redirect Plus :

Here are the return addresses :
- Production :
https://gate.first-id.fr?redirectHost={{user.PMUSER_REDIRECT_HOST_URL_ENCODE}}&redirectUri={{user.PMUSER_REDIRECT_URI_URL_ENCODE}} - Preproduction :
https://gate.preprod.first-id.fr?redirectHost={{user.PMUSER_REDIRECT_HOST_URL_ENCODE}}&redirectUri={{user.PMUSER_REDIRECT_URI_URL_ENCODE}}
The configuration of this first rule is complete 🎉.
Now let's move on to configuring the second rule. Click on the save button before going on to configure the second rule.
Click on the Add Rule button in the left-hand panel.
Choose Blank Rule Template and name it First-id - set cookie and redirect.
Click on Insert Rule.
We have two criteria to define that must be met for this rule to be triggered :
- The user has a
YOUR_CONSENT_COOKIEcookie. - AND the request contains a query param
firstIdwe're in the case of a redirection made by the First-id system, which has added this query param.
WARNING
Note that the query param is called firstId in camelCase.
Criteria configuration :

In terms of behaviors, we're going to have 4 of them :
- Store in the
PMUSER_FIRSTIDvariable the identifier generated by the First-id system, which is passed in the query paramfirstIdof the current query. - Assign the redirection URI contained in query param
redirectUrito ourPMUSER_REDIRECT_URIvariable, decoding it the value is encoded in urlEncode. - Set the
firstidcookie with the value of thePMUSER_FIRSTIDvariable. - Redirect the user to the original page by deleting query params
firstIdandredirectUri.
Store First-id identifier in PMUSER_FIRSTID :

Store redirect URI and decode :

Set cookie containing First-id identifier :

RGPD
In the example, we give a lifetime of 180 days to the cookie containing the First-id identifier. This duration is completely arbitrary. Make sure the duration of the cookie is the same as the duration of the consent the user has given you.

Now all you have to do is save and deploy this new version to activate the First-id service on your website 🎉.
# Redirect to gate for syncrhonization of First-id master cookie
Create a new rule named First-id - Refresh ID and configure it as follows :
Prerequisites :
- You must have a
PMUSER_EMAIL_HASHEDvariable in your property. This variable will contain the user's hashed email from the cookie.
# Criteria
TIP
The name of the firstid_refresh cookie used in the example can be customized during SDK initialization.
The name of the YOUR_EMAIL_COOKIE cookie used in the example should be replaced by the name of the cookie containing the user's SHA256 hashed email address.

# Behaviors
Extracting the variables we need :


The purpose of this behavior is to delete the cookie requesting refresh. To do this, it sets a firstid_refresh cookie with an expiry date in the past.

This behavior redirects the user to the gate with the following parameters :

Redirection URL :
- Production :
https://gate.first-id.fr?redirectHost={{user.PMUSER_REDIRECT_HOST_URL_ENCODE}}&redirectUri={{user.PMUSER_REDIRECT_URI_URL_ENCODE}}&email={{user.PMUSER_EMAIL_HASHED}} - Preproduction :
https://gate.preprod.first-id.fr?redirectHost={{user.PMUSER_REDIRECT_HOST_URL_ENCODE}}&redirectUri={{user.PMUSER_REDIRECT_URI_URL_ENCODE}}&email={{user.PMUSER_EMAIL_HASHED}}
# Using Health Check
First-id provides you with a Health Check endpoint to verify that the service is online. You can use this Health Check to monitor the correct operation of the First-id service.
To make sure you only redirect your user to First-id if the service is online, you can use an EdgeWorker to perform a Health Check on the First-id service.
EdgeWorker
An EdgeWorker is a JavaScript script that runs on Akamai's content distribution network. It allows you to customize the content and behavior of your website according to rules you define. It uses serverless technology : you don't need to manage the underlying infrastructure, Akamai takes care of that for you.
To do this, you need to create an Edge Worker :

Then click on the "Create EdgeWorker ID " button.
Complete the EdgeWorker creation form :

WARNING
The EdgeWorker name is completely arbitrary, so you can choose any name you like. Information such as "Resource tier" may vary depending on your contract with Akamai.
The use of EdgeWorker may incur an additional cost. If in doubt, contact your Akamai account manager.
Click on the "Create EdgeWorker ID " button.
Your Edge Worker appears in the list :
Click on its ID, here 83169, to access its configuration.
Click on the orange "Create version " button to create a new version of EdgeWorker.
TIP
You can store your EdgeWorker code in a git repository and deploy it via a CI/CD pipeline.
Here we're going to code the Health Check in the online editor. To do this, click on the orange "Open editor " button.
Here's the online editor :

Open the main.js file and copy the following code :
import { httpRequest } from 'http-request';
import { logger } from 'log';
// Check first-id service availabilty if health-check down (status_code, body content or timeout)
export async function onClientRequest (request) {
const url = "https://healthcheck-ak.prod.first-id.fr/check-v2";
const options = {};
options.method = "GET";
options.timeout = 500;
try {
const response = await httpRequest(url,options);
const http_status = response.status;
const response_json = await response.json();
const status = response_json.status;
logger.log("http_status: %s", http_status);
logger.log("status: %s", status);
if ( http_status == 200 && status == "OK" ){
request.setVariable('PMUSER_FID_AVAILABLE','1');
logger.log("ok: %s", status);
}
else {
request.setVariable('PMUSER_FID_AVAILABLE','0');
logger.log("ko: %s", status);
}
} catch(error){
logger.log('error: %s', error);
request.setVariable('PMUSER_FID_AVAILABLE','0');
}
}
As a reminder, the URLs for our Health Check services are as follows :
- Production:
https://healthcheck-ak.prod.first-id.fr/check-v2 - Preproduction:
https://healthcheck-ak.preprod.first-id.fr/check-v2
Recommended endpoint: /check-v2 – reads a status updated every minute; more resilient to network latency. The /check endpoint remains available for backward compatibility.
We have created specific URLs for Akamai (hence the -ak suffix in the URLs) because the Edge Worker can only make HTTP requests to URLs exposed by Akamai.
Log
We use the log module to log information from our Health Check.
To access these logs, refer to the Akamai documentation (opens new window).
Learn more about the log module in the Akamai documentation. (opens new window).
Now edit the bundle.json file to modify the EdgeWorker version and give it a description :
{
"edgeworker-version": "1.0",
"description": "Implement First-id Health Check".
}
Click on the orange "Create version " button (at the very bottom of the page) to save your code.
A pop-up window will appear, asking you to confirm the creation of the version. Click on the "Create version " button.
Click on the "Activate version " button to activate this version of EdgeWorker.

A pop-up window appears to select the version to deploy, and the network on which to deploy it. Click on the "Activate version " button to confirm.
Here we're taking version 1.0, which we'll deploy on the staging network to facilitate testing.
The Edge Worker deployed in staging can only be used on your staged properties.

Once we've finished deploying the EdgeWorker, we'll update your property to use it.

Go to your property and create a new version.
In the "Property Variables " section, add a new variable PMUSER_FID_AVAILABLE.
This variable will be updated by the Edge Worker. If the First-id service is available, the variable will be set to 1, otherwise it will be set to 0.
In the Property Configuration Settings section, we need to create a rule via the "+ Rule " button.
Choose Blank Rule Template and name it First-id - Health Check.
Position the rule (by dragging it in the left panel) before the First-id - Get ID rule.

Add the same criteria as the First-id - Get ID rule :
In behaviors, add a behavior of type Edgeworker :

Then configure it as follows :

Select the EdgeWorker you've just created from the Identifier drop-down list.
Modify the First-id - Get ID rule to redirect the user to First-id only if the service is online. To do this, add a condition in the "Criteria " section :

Click on the orange "Save " button at bottom right to save your property, then deploy this new version. (In the example we've deployed the EdgeWorker only on the staging network).
You've now set up a Health Check to verify that the First-id service is online before redirecting the user to our service. 🎉
Important note
Variable values in your property are "scoped" for each query. This means that if you update the value of a variable during a query (which you do with the Edge Worker), this value will not be available in subsequent queries. See issue on Github (opens new window)
So for each visitor who meets the conditions for triggering the First-id - Get ID rule, the Edge Worker will perform a Health Check to verify that the First-id service is online.
Preserve User Referrer
To preserve the referrer of my user, I must take several actions described here.
Excluding Redirections
Warning, you should not perform redirections for the following file types:
jpe?g|gif|png|json|js|woff2?|map|css|svg|ico|bmp|xml|ttf|txt
Please add a filter on these file types in your configuration.