One can set a custom key name for a AMP HTML cookie by passing it as the first argument to the Client ID analytics variable as in ${clientId(my-custom-cookie)}, where my-custom-cookie is the desired cookie name.
The value of the custom AMP HTML cookie above may be a random base64 encoded string preceded with a amp- prefix as in amp-V0pvjhu7pzZdRKQfDM-QYA.
How can I effectively change the format of the cookie value in order to make it UUID version 4 compliant?
It's actually a design goal of
<amp-analytics>that developers not be able to change the format or entropy of the value of that cookie. I learned of this design goal when reading through their GitHub issues where developers were asking for new tracking options. The AMP developers expressed concern about too much entropy (https://github.com/ampproject/amphtml/issues/29324):The CLIENT_ID becomes the value of that cookie, and its format and entropy are decided by the AMP framework (see https://amp.dev/documentation/guides-and-tutorials/optimize-and-measure/configure-analytics/analytics_basics/?format=websites#user-identification). The framework does allow changing the name of the cookie, as you noticed, which is helpful for integrations. A canonical page using custom JS can look for the cookie and see the value that AMP had set.