Google Apps Script

URL Shortener Service

The URL Shortener service allows you to use the URL Shortener API in Apps Script. This API gives users the ability to manage and report on their goo.gl short links.

Reference

For detailed information on this service, see the reference documentation for the URL Shortener API. Like all advanced services in Apps Script, the URL Shortener service uses the same objects, methods, and parameters as the public API.

Sample code

The sample code below uses version 1 of the API.

Open code in new window

Shorten a URL

This sample generates a new short URL.

function shortenUrl() {
  var url = UrlShortener.Url.insert({
    longUrl: 'http://www.example.com'
  });
  Logger.log('Shortened URL is "%s".', url.id);
}

Get clicks

This sample gets the number of clicks the short URL received in the last week.

function getClicks(shortUrl) {
  var url = UrlShortener.Url.get(shortUrl, {
    projection: 'ANALYTICS_CLICKS'
  });
  Logger.log('The URL received %s clicks this week.', url.analytics.week.shortUrlClicks);
}

Authentication required

You need to be signed in with Google+ to do that.

Signing you in...

Google Developers needs your permission to do that.