Generate a UUIDv4

PHP does not have a native library for UUID generation, so these code examples are more extensive than what would likely be required if another programming language was used. PHP was chosen for this example because it is a widely supported server-side language.

When the following function is called, it generates a random UUID version-4:

<?php

    function guidv4($data)
    {
        $data = $data ?? random_bytes(16);

        $data[6] = chr(ord($data[6]) & 0x0f | 0x40); // set version to 0100
        $data[8] = chr(ord($data[8]) & 0x3f | 0x80); // set bits 6-7 to 10

        return vsprintf('%s%s-%s-%s-%s-%s%s%s', str_split(bin2hex($data), 4));
    }

?>

The following code makes a request to the function above to generate a UUID. It then sets the cookie flags decided upon by your organization. If a cookie has already been generated, then the expiration is extended.

<?php

    if(!isset($_COOKIE['FPID'])) {
        $cookie_value = guidv4(openssl_random_pseudo_bytes(16));
        $arr_cookie_options = array (
        'expires' => time() + 60*60*24*30*13,
        'path' => '/',
        'domain' => 'mysiteurl.com',
        'secure' => true,
        'httponly' => true,
        'samesite' => 'lax'
        );
        setcookie($cookie_name, $cookie_value, $arr_cookie_options);
        $_COOKIE[$cookie_name] = $cookie_value;
    }
    else {
        $cookie_value = $_COOKIE[$cookie_name];
        $arr_cookie_options = array (
        'expires' => time() + 60*60*24*30*13,
        'path' => '/',
        'domain' => 'mysiteurl.com',
        'secure' => true,
        'httponly' => true,
        'samesite' => 'lax'
        );
        setcookie($cookie_name, $cookie_value, $arr_cookie_options);
    }

?>
NOTE
The cookie which contains the first-party device ID can have any name.

The final step is to use PHP to echo the cookie value to the Identity Map.

{
    "identityMap": {
        "FPID": [
                    {
                        "id": "<? echo $_COOKIE[$cookie_name] ?>",
                        "authenticatedState": "ambiguous",
                        "primary": true
                    }
                ]
        }
}
IMPORTANT
The identity namespace symbol used in the identity map, must be called FPID.
FPID is a reserved identity namespace which is not visible in the interface lists of identity namespaces.

Validate ECID generation

Validate the implementation by confirming that the same ECID is generated from your first-party device ID:

  1. Generate an FPID cookie.
  2. Send a request to Platform Edge Network using Platform Web SDK.
  3. A cookie with the format AMCV_<IMSORGID@AdobeOrg> is generated. This cookie contains the ECID.
  4. Make a note the cookie value that is generated and then delete all cookies for your site except the FPID cookie.
  5. Send another request to Platform Edge Network.
  6. Confirm the value in the AMCV_<IMSORGID@AdobeOrg> cookie is the same ECID value as in the AMCV_ cookie that was deleted. If the cookie value is the same for a given FPID, the seeding process for the ECID was successful.

For more information about this feature, see the documentation.


Top Tips to Maximize Value with Adobe Experience Platform Data Distiller

Online | Session | General Audience

Explore best practices for maximizing the value of Data Distiller, a powerful tool that transforms and enriches data in Adobe Experience...

Wed, Mar 19, 3:30 PM PDT (10:30 PM UTC)

Register

B2B Reimagined: Transforming Go-to-Market Strategies for Profitable Growth

Online | Strategy Keynote | General Audience

B2B brands are facing a digital revolution. Buyers expect hyper-relevant content and self-service, while internally AI is transforming...

Wed, Mar 19, 1:00 PM PDT (8:00 PM UTC)

Register

Connect with Experience League at Summit!

Get front-row access to top sessions, hands-on activities, and networking—wherever you are!

Learn more