What kind of measure ?
The first-id can be used for measurement purposes when displaying advertising formats on a page of a website that has a first-id enabled. If you want to retrieve a first-id to insert it into existing tracking, you can use the code below.
The first-id identifier can be passed as a parameter for impression or click accounting. Most tracking URLs have customizable events within which you can pass the first-id and measure up to the conversion if the advertiser also has a first-id and the identifier is passed in the same way on order confirmation pages, for example…
Technical implementation
Le first-id peut être utilisé à des fins de mesure lors de l’affichage de formats publicitaires sur une page d’un site web qui dispose d’un first-id. Si vous souhaitez récupérer un first-id pour l’insérer dans un suivi existant, vous pouvez utiliser le code ci-dessous.
L’identifiant first-id peut être transmis en tant que paramètre pour le comptage des impressions ou des clics. La plupart des URL de suivi comportent des événements personnalisables dans lesquels vous pouvez transmettre le first-id et mesurer jusqu’à la conversion si l’annonceur dispose également d’un first-id et si l’identifiant est transmis de la même manière sur les pages de confirmation de commande, par exemple…
💡 Notez que ce code ne fait que récupérer la valeur du first-id. Si vous souhaitez le passer dans une script existant, il faudra coder cette fonctionnalité.
/**
* Periodically requests the FirstID from the parent page via postMessage,
* and listens for responses to initialize the iframe context.
*/
function askFirstIdToParentIframe() {
let intervalReferenceRequestFirstIdFromParent = null
/**
* Sends a request to the parent window to obtain the FirstID.
* Called repeatedly until the iframe receives a valid response.
*/
const requestFirstIdFromParent = () => {
console.debug(Request FirstID from parent each 100 ms...);
// Send a message to the parent window (window.top).
// The parent page is expected to listen for "requestFirstID".
window.top.postMessage("requestFirstID", "*");
};
// Starts a recurring interval to request the FirstID
// until a valid response is received.
intervalReferenceRequestFirstIdFromParent = setInterval(
requestFirstIdFromParent,
100
);
/**
* Listens for incoming postMessage events (from the parent or other sources).
* Goal: detect the message containing the FirstID and handle it.
*/
window.addEventListener("message", (event) => {
console.debug("[FIRSTID IFRAME] message from parent", event);
// Ignore any message that does not contain a FirstID.
if (!event.data.firstid) {
return;
}
// Once the FirstID is received, stop further interval requests.
clearInterval(intervalReferenceRequestFirstIdFromParent);
console.debug(
[FIRSTID IFRAME] iframe successfully received FirstID ${event.data.firstid},
event
);
// Send an acknowledgment back to the parent window
event.source.postMessage("firstidACK", "*");
// Retrieve or propagate the FirstID through callbacks, events, variables, etc.
// TODO
}, true);
}
