How long does a tracking link need to be?
Let’s make it interesting, and say we want to be able to have a unique tracking link for every single atom in the observable universe.
That’s about 1080 unique links.
One hundred novemdecillion exa-links.
100,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000
If we have that many customers we can afford to buy an expensive domain name and dedicate it to click tracking. Let’s use “z.zz” as our example domain – that’s not implausible, there are domains that short in use by individuals.
So our URL is going to look something like this:
https://z.zz/<something goes here>
Code language: HTML, XML (xml)
That’s 13 characters, plus the “something goes here” bit.
We need to encode 1080 different values. If we take the logarithm of that to base two it’s a shade over 265, so we can encode it in 266 bits of data.
We need to convert those 266 bits of data to a text string.
One of the regular ways of doing that is to use base64 encoding. We use that a lot in email already, to convert binary files to text so we can attach them to an email. Base64 uses a list of 64 different characters (A-Z, a-z, 0-9 and a couple more) to encode things, hence the name. 64 is 26 meaning we can encode 6 bits in each character, so with 44 characters we can encode 268 bits of information, which is more than enough. Adding in the 13 characters for the https bit gives us 57 characters in total, for a tracking link for every atom.
We can do better, though. If we read the spec for URLs carefully we find 21 punctuation characters we can use in the path of a URL. Adding A-Z, a-z and 0-9 gives us 93 characters. log2 of 93 is a little over 6.53, so we can encode 6.53 bits in each (ascii) character. 266 divided by 6.53 is about 40.5, so we need about 41 characters to encode every atom using Bas93 encoding. Adding in the 13 characters for the https bit gives us 54 characters.
So if you need to encode a click tracking link for every atom in the observable universe you can use a 54 character long URL that looks something like this:
https://z.zz/u,Oz0Xrp0_Xrz=0rX2IE?Ti62LF2)@a];tyu*qkhB
Code language: JavaScript (javascript)
Fits on a single line without wrapping easily.
If you don’t have quite 1080 unique links across all your customers then you can make them a little shorter.
If you’re actually doing this you might want to use a slightly smaller set of characters. Something like Base85 with an alphabet that avoids “#” and “/” might be better, but you have a lot of encodings to choose from.