Dealing with extended URLs necessitates effective shortening, and Google Docs proves to be a valuable tool for this purpose. While many are familiar with the URL shortening service Goo.gl, it is limited to individual URLs. Google Docs, on the other hand, provides a convenient solution for shortening multiple URLs.
USING GOOGLE DOCS FOR URL SHORTENING
We'll utilize Google Apps Script and incorporate a code snippet to streamline the process of creating shortened URLs using Google Sheet.
Step 1: Open a Google Sheet file you wish to use for generating shortened URLs.
Since the results will appear on the left, it's advisable to place the URL column on the left.
Step 2: Click on the Tools menu and select Script editor...
Step 3: A Script Editor page will appear in a new window. Rename this Script file by clicking on Untitled project, naming it, and pressing Ok to complete.
Step 4: A basic Script file will start as illustrated below.
Step 5: Copy the entire code below and paste it into the Script Editor file.
//When the spreadsheet is opened it adds a menu called 'Shorten URL' and a sub-menu item called 'Shorten'
//Referring to the function below named 'short'
function onOpen() {
SpreadsheetApp.getUi()
.createMenu('Shorten URL')
.addItem('Shorten','short')
.addToUi()
}
//Processes the highlighted range, moving down row by row, and appends a short URL to the column on the left
function short() {
var range = SpreadsheetApp.getActiveRange(), data = range.getValues();
var output = [];
for(var i = 0, iLen = data.length; i < ilen; i++) {
// Generate a shortened URL using the provided data
var shortUrl = UrlShortener.Url.insert({longUrl: data[i][0]});
output.push([shortUrl.id]);
// If you wish to place the short URL in a different column, adjust the '-1' in line 20
// Adjust the offset value: Negative moves to a column on the left; positive moves to a column on the right.
range.offset(0, -1).setValues(output);
}
Your Script file will resemble the image below.
Step 6: Save the file by clicking the disk icon.
Step 7: Now, you need to activate Google URL service. This is a one-time task. Click on Resources in the Script Editor toolbar, then select Advanced Google Services
Step 8: The Advanced Google Services dialog will open. Scroll down until you see URL Shortener API . Turn it on by clicking the toggle switch, then click Ok at the bottom.
Step 9: Back in the Script Editor window, click on Resources , then select Cloud Platform project
Step 10: Click on the green link to proceed.
Step 11: Click Yes, then click Accept to continue.
Step 12: Next, click on APIs & services.
Step 13: A new page will appear; in the Other popular APIs section, choose URL Shortener API.
Step 14: Click on Enable to activate the APIs. It will switch from Enable to Disable, indicating completion.
Note: The above steps need to be done only once and can be applied for future use.
Step 15: Return to your Google Sheet. Select the cells containing the URLs you want to shorten, click Shorten URL on the toolbar, then choose Shorten.
The results will appear below, signaling completion.
Here is a guide on using Google Docs to create shortened URLs with Script Editor in Google Sheets. We hope this article helps you easily generate short URLs using Google Docs. If you encounter any challenges during the process, feel free to comment below, and the technical team at Mytour will assist you.
In addition to Google Docs, you can explore various other websites to facilitate link shortening. Check out the top Link Shortening Websites here.