There's no way to tag or organize links by default. My suggestion is to use Delicious to store the shortened links. Delicious is an example, there are other sites such as pinboard, historious, scuttle where you can categorize links.
This little code makes it possible to create shortened URL's, with the use of Google Apps Script and the URL Shortener API.
Prerequisites
Under resources in the script editor (Tools > Script editor) select the Advanced Google Services and activate the UrlShortener:
![enter image description here](https://i.stack.imgur.com/7f4aM.png)
Then go to the Google Developers Console and select the URL for the API:
![enter image description here](https://i.stack.imgur.com/jyxcs.png)
Enable the API and paste the code in to the script editor. Press the bug button to authenticate the script
Code
function onOpen() {
SpreadsheetApp.getUi()
.createMenu("Shorten")
.addItem("Go !!","rangeShort")
.addToUi()
}
function rangeShort() {
var range = SpreadsheetApp.getActiveRange(), data = range.getValues();
var output = [];
for(var i = 0, iLen = data.length; i < iLen; i++) {
var url = UrlShortener.Url.insert({longUrl: data[i][0]});
output.push([url.id]);
}
range.offset(0,1).setValues(output);
}
Explained
The onOpen() function will create a menu item for you to select, having the name Shorten. Every time you open the file this menu item will be added (if you're in the script editor, select the function from the drop-down menu and press the play button. This will execute that particular function and the item will be added to the menu).
Once the menu is created, it will show the menu item Go !!. Select the cell or range that you want to shorten and the script will create the shortened URL's and add them to the sheet.
Screenshot
before
![enter image description here](https://i.stack.imgur.com/PRlt5.png)
after
![enter image description here](https://i.stack.imgur.com/KzFES.png)
Note
The code makes the assumption that, once you've selected either the cell or range to be shortened, that the result will be added to the right of the selected cell/range (OFFSET(0,1)
).
If you simply want to overwrite the existing URL, then change the code into this: (OFFSET(0,0)
).
Example
I've created an example file for you: Create Shortened URL's
References
- url-shortener
- offset(Integer,Integer)
- onOpen()
Best Answer
With the code below, you're able to insert the analytics information as well.
Code
Explained
Continuing from the answer you used as a guide, a couple of things have changed:
Perform the same action as you would do for creating the urls, but now select the shortened urls and pick the new menu item in the Shorten menu.
You can change
projection: "FULL"
into:"ANALYTICS_CLICKS"
- returns only click counts"ANALYTICS_TOP_STRINGS"
- returns only top string counts (e.g. referrers, countries, etc)or you can change
url.analytics.allTime
into:url.analytics.month
url.analytics.week
url.analytics.day
url.analytics.twoHours
to alter the analytics information.
Screenshot
Library Key
Add the library key, of the cFlatten library, in the Script Editor under Resources > Libraries:![enter image description here](https://i.stack.imgur.com/zGyEO.png)
References