How to make AMP HTML cookies UUID version 4 compliant

274 views Asked by At

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?

1

There are 1 answers

0
Matt Welke On

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):

Another question: Does a lower entropy session id work here? (e.g. 0-10000)

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.