Why to Use URL Shorteners

13.Sep.2021

What is a URL shortener?

URL shorteners are services which allow you to shorten a complex URL into a much shorter one. For example from https://www.mozilla.org/en-US/about/ we can get an incredibly short link https://tinyurl.com/y8dfn2jm . In the process of reading the article, people will no longer need to type in long addresses and risk misspelling or misreading them, while social media users do not have problems with adding links into posts nor reduce their length drastically while sending messages via messengers or SMSes.

Short URLs, besides being easier to remember and use, sometimes also carry parameters that supply extra information about the click - for example how many clicks the link got, where it was clicked from, etc.

What are URL shorteners used for?

URL shorteners are mostly used in social networks and messengers where the character limit is imposed on messages containing links. This way you can reduce the length of a message drastically while still being able to add a link in it. For example, if your post contains a long direct link to an article that isn't yours then you will face deletion or blocking directly at this step. URL shorteners help you avoid censorship in such cases by creating cloaked/masked URLs with small clickable images, so no one would be able to check whether there's something breaching terms of use in them before clicking on the link itself.

Apart from that, URL shorteners are also very popular among online stores and blogs where people can go to get more information about a certain product or service. They can also help you know which links were clicked the most.

Do I need a URL shortener?

URL shorteners have become an integral part of social media and other kinds of online communities, so you'll basically be forced to use them either consciously or not. So if your goal is posting on your social media then it's better for you to start learning how to create cloaked URLs from scratch rather than coping ready-made ones from others all the time. At least try once! [ARTICLE END]

A very simple approach to creating a shortened URL via Google Spreadsheet: First, create a Spreadsheet (File > Make A Copy). Then go to the "Tools" section of the toolbar. Select "Script Editor...".

Click here to get started with Google Scripts! A window will open up; in it, paste in this code:

function shortenURL(longUrl){ //get the long url var longUrl = UrlFetchApp.fetch(longUrl); var shortCode = 'xxx'; //replace xxx below with any 3-5 digit string of your choice for (var i=0; i<longUrl.length-1; i++) { shortCode += longUrl.charAt(i) + longUrl.charAt(i+1); } shortCode = shortCode.replace(/([a-z])/g, '-$1'); //replace all chars that aren't alphanumeric with a dash (for example "ThisIsMyLongUrl123!" will become "T-His-m-MyL-LongU-rl123!") longUrl = longUrl.replace(/(^|-|)\s+/${shortCode}/, ''); //remove excess spaces and replace all forward slashes in the string with dashes return longUrl; } Click on Publish > Deploy as Web App... > Create New Version. A new version of your script will be created and you'll receive a message that its status is now Deployed . Once it says Active , you're good to go! Now you can call the shortenURL() function from a cell in your Google Spreadsheet. For example, select a cell and type: =shortenURL('https://www.mozilla.org/en-US/about')

The shortened URL will appear in that same cell as a result of the function's execution. If you want to make this result permanent, place it somewhere else (another cell). In order to do this, highlight the shortened URL returned by the script and copy it (press Ctrl + C or right click > Copy). Then move to another cell and press Ctrl + V or right click > Paste - voilà, now there's your shortened version Mozilla's website link sitting pretty in a new cell.

How do I make a shortened URL? Here's a much simpler approach, but this time in PHP code:

$longUrl = 'https://www.mozilla.org/en-US/about'; //get the long url

$myLink = substr($longUrl, 0, strlen($longUrl) - 5); //insert your desired length of shortened link here (the minus sign before "strlen" function means that the script is going to shorten only from the beginning not from the end) echo $myLink; //outputs e.g.: shorte.st/Gj9CJ => https://shorte.st/GjCJ So if you want to make this link permanent, you'll need to copy/paste its value (e.g.: echo $myLink;) in a new empty cell and use it in your posts or wherever needed! Here's the result of running this script:

As you can see on the image above, we've made our shortened version Mozilla's website link and we're going to use it as a reference for future examples on how to create cloaked URLs with Google Spreadsheets and PHP.

What is a cloaked URL and why do I need one? A cloaked/masked URL is basically an encoded string of characters that looks like gibberish but which actually leads someone to your intended destination when clicked on. Take a look at the following example:

https://www.mozilla.org/en-US/about

This looks like a regular link but if you hover your cursor over it, or highlight it and press Ctrl + C or right click > Copy, then paste wherever needed (Ctrl + V or right click > Paste), you'll see that this is actually an encoded link to Mozilla's website URL! It's not visible because there are no spaces between the characters; only dashes (-) were used instead - it looks like this was done on purpose to make sure nobody could easily guess the destination of the link by looking at its URL structure.

Why do I need cloaked URLs? Cloaking URLs does two main things: first, it you avoid using shortened links (which can be easily shared on social media or messengers) because you'd need to shorten the links with URL shortener services (e.g.: bit.ly, goo.gl) which would make your task of tracking visitors more difficult; second, if you want to see who actually clicked on certain links (clicked on them in social media or messengers), then cloaked URLs are essential because they hide UTM codes that track these clicks and let you know where traffic is coming from (which is great for monitoring campaigns).

We are social