Menu

Link Shortening

The Link Shortening feature is only available for use with Messaging Services.

Link Shortening is part of Engagement Suite. Visit the SMS Pricing page and WhatsApp Pricing page for price details..

Link Shortening is a Messaging Services feature that allows you to send messages with shortened links using your own company-branded domain. Twilio also provides click tracking with the Link Shortening feature, so you can track customer engagement with your messages' shortened links.

When Link Shortening is used, Twilio converts long links from a message body and converts them to unique shortened links. The shortened links contain your Link Shortening domain, followed by ten alphanumeric characters.

Link Shortening and click tracking are included in Engagement Suite. For information on Engagement Suite pricing, see the pricing pages for SMS/MMS or WhatsApp.

With Link Shortening, Twilio turns a message that looks like this:

Visit this link to start earning rewards today! https://twilio.com/N6uAirXeREkpV2MW7kpV2MW7...

into a message that looks like this:

Visit this link to start earning rewards today! https://twil.io/j9kj9K3huK9u7

You need to own the domain you use for link shortening (like how Twilio owns twil.io).

Shortened links

Consider the following scenario:

  • You've onboarded your domain and Messaging Service for Link Shortening
  • Your Link Shortening domain is https://example.com
  • You create a Message with a link you want to shorten. The Body contains the following:

    "Thanks for signing up for Acme, Inc. rewards! Click on the link to start saving today! https://twilio.com/kpV2MWAvh1zn4gET1zn4gEFkpVAvh1bAvh1zn4gEF"

At send time, Twilio:

  • Creates a redirect from https://twilio.com/kpV2MWAvh1zn4gET1zn4gEFkpVAvh1bAvh1zn4gEF to https://twil.io/j9K3huK9u7
  • Replaces the long link in the Body of the message.
  • The recipient receives the following message:

    "Thanks for signing up for Acme, Inc. rewards! Click on the link to start saving today! https://twil.io/j9K3huK9u7"

Link expiration

Twilio stores original link/shortened link association information for 90 days. Within those 90 days, clicks on the shortened link are redirected to the original long link.

After 90 days, the link "expires." If a customer clicks on an expired shortened link, they are redirected to a fallback URL and click events are no longer sent to your callback URL.

The fallback URL is configured when you set up Link Shortening.

Track customer engagement with click events

The Link Shortening feature also allows you to receive data whenever a customer clicks on a shortened link. You can this information to measure marketing campaign effectiveness, track individual recipient engagement, and/or implement a customized workflow whenever a shortened link is visited.

For each each "click event", Twilio sends a POST request to your provided endpoint containing details about the event such as:

  • The number or channel address of the recipient (i.e. the To parameter of the original Message)
  • The original long link that was shortened
  • The time the recipient clicked on the link

An example of a click event callback request from Twilio is shown below:

{
  "event_type": "click",
  "sms_sid": "SMxxx",
  "to": "+15554567890",
  "from": "+15557654321",
  "link": "https://www.longlink.com/original_link",
  "click_time": "2022-10-24T17:17:26.529Z",
  "messaging_service_sid": "MGxxx",
  "account_sid": "ACxxx",
  "user_agent": "some_user_agent"
}

The table below describes each property in click event callback requests from Twilio:

Property Description
event_type The type of event. The value is always click for click events.
sms_sid The SID of the Message resource that contained the shortened link.
to The To value of the original Message resource. This is the recipients phone number or channel address (e.g. whatsapp:+15558887474)
from The From number of the Message. This is a phone number or channel address from your Messaging Service's sender pool.
link The original long link. This shortened link redirected to this link.
click_time The ISO 8601 timestamp of when the customer clicked on the shortened link.
messaging_service_sid The SID of the Messaging Service that sent the Message.
account_sid The SID of the Twilio Account that sent the Message.
user_agent The user agent that accessed the link. Example: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7)

You can configure a click event callback URL when you onboard with Link Shortening.

Twilio doesn't send click event information once a link has expired or outside of your Messaging records retention period (see below).

Click event information is also available via Event Stream subscription.

Messaging records and click events

If you've configured a custom retention period for your Messaging records, make sure your retention period is at least 90 days. (By default, the retention period is 400 days.)

Although shortened links are valid for 90 days, click events are not generated beyond your Account's retention period.

To configure your custom retention period, open your Console and go to Develop > Messaging > Settings > General > Message Records Data Access and Backup.

Send a message with a shortened link

Link Shortening only works after you've completed the steps in the onboarding guide. You should read the rest of this page before you begin onboarding.

To send a message with a shortened link, send a POST request to the Messages list URI (like you do for messages without shortened links) with two additional parameters: ShortenUrls and MessagingServiceSid.

  • The ShortenUrls parameter's value must be true.
  • The MessagingServiceSid parameter value must be the SID of the Messaging Service associated with your Link Shortening domain.
  • You must also include the To parameter, which is required for all Messages
  • The link you wish to shorten is included in the Body parameter

Send an SMS with a shortened link

The code sample below shows how to send an SMS message with a shortened link.

  • The POST request contains the required To, ShortenUrls and MessagingServiceSid parameters, and the Body parameter contains a long link (not shortened).
  • The resulting SMS message received by the customer contains a shortened link.

Send a WhatsApp message with a shortened link

The code sample below shows how to send a WhatsApp message with a shortened link. This assumes that you've onboarded your WhatsApp Business Account with Twilio.

  • The POST request contains the required To, ShortenUrls and MessagingServiceSid parameters, and the Body parameter contains a long link (not shortened).
  • The resulting WhatsApp message received by the customer contains a shortened link.

Account-based rate limits

Link Shortening has an Account-based rate limit of 2000 requests per second.

Twilio shortens links at send time. Therefore, Twilio receives a "Link Shortening request" in the following situations:

  • When Twilio receives a POST request to create Message resource with ShortenLinks set to true
  • At the SendTime of a scheduled message with ShortenLinks set to true

If you exceed the rate limit, messages are not sent and a 20429 error code is emitted.

Link Shortening Outages

If there is an error with Link Shortening (e.g. changes to your domain verification or an expired certificate), you can tell Twilio to send messages with the original long links or to not send the messages.

The default behavior is to continue sending messages with the original long links. This may result in multiple message segments, which may incur higher costs. This setting only affects Messages with a ShortenUrls parameter set to true.

You can configure this preference when you set up Link Shortening on your account.

Next steps

Rate this page:

Need some help?

We all do sometimes; code is hard. Get help now from our support team, or lean on the wisdom of the crowd by visiting Twilio's Stack Overflow Collective or browsing the Twilio tag on Stack Overflow.

Thank you for your feedback!

Please select the reason(s) for your feedback. The additional information you provide helps us improve our documentation:

Sending your feedback...
🎉 Thank you for your feedback!
Something went wrong. Please try again.

Thanks for your feedback!

thanks-feedback-gif