How to Send Personalized SMS Using Twilio Segment & Twilio
Time to read:
How to Send Personalized SMS Using Twilio Segment & Twilio
SMS is one of the most powerful engagement channels in a developer’s toolkit. Yet for consumers, it’s also one of the easiest to ignore.
Every day, thousands of spammy, poorly targeted messages are blasted out to consumers using legacy communications technology. These tools can’t reference basic user attributes like name, location, and activity right, let alone add the required personalization drive open rates and engagement.


Thankfully, the technology today is WAY more sophisticated than it used to be, so this type of attritional marketing doesn’t have to be the norm.
Customer data platforms like Twilio Segment helps you collect clean, accurate customer data to build upon. You can understand who your users are, what geo they’re in, what actions (if any) they’ve taken with your brand, and what their preferences are.
What’s more, it’s easy to have all that data stitched together in one profile. By using and combining these data points, you can create SMS marketing campaigns hyper-personalized to the behavior of the recipient, and therefore more likely to be effective.
In this tutorial, we’ll walk through how to use Twilio Segment and Twilio Programmable Messaging to send a personalized SMS campaign.
Step 1: Connect your customer data with Twilio Segment
Let’s say you’re an e-commerce business and would like to send personalized SMS messages based on a user’s prior website activity.
This is where Twilio Segment comes in. By instrumenting Twilio Segment on your website, you can implement event tracking to understand your website visitor’s behavior, whether that’s clicking on promotions, viewing products, completing an order, etc.
To do this, simply sign up or log in to your Twilio Segment account.
Next, create a Source to collect data on your e-commerce website. A Source is where actions taken by customers such as Product Viewed and Order Completed are collected as “events” and sent to Twilio Segment. Since you’re tracking website behavior, you’ll want to start with a Javascript source. Click Add Source and give the source a name e.g twilio-segment-store.com
Once you’ve connected your source, you’ll want to install the Twilio Segment snippet on your website. This snippet means that your website can easily call the Twilio Segment APIs when a visitor takes a certain action. Simply copy and paste the snippet from the JavaScript Source overview page into the <head> tag of your site.


👉 Check out these docs to learn more about setting up your source.
After you set up your Source, you’ll begin to implement events. Events are actions such as page views or button clicks performed by your users on your website. A good comprehensive list of what e-commerce events you can track can be found in our e-commerce spec.


If you want to check if your data is flowing correctly, head on over to the Debugger to see the data flowing in real-time.


Step 2: Deliver your personalized SMS with Twilio
Once you’ve set up event tracking with Twilio Segment, it’s time to connect to Twilio's APIs to send your personalized SMS notification
In order to do so, we have to create a “destination” for Twilio. Destinations are where you want your route customer data to once it’s been collected.


Twilio Segment’s official Twilio destination is in the works, so in the meantime, we can use Twilio Segment Functions to build a seamless integration.
Functions is a hosted service offered by Twilio Segment that allows you to build a custom source to ingest data from anywhere into Twilio Segment or build a custom destination to send data you're collecting on Twilio Segment into any third-party API endpoint by just writing a few lines of JavaScript.


For the purpose of this tutorial, let’s use the Twilio function template, which makes it even easier for you to get started.


This template does four things:
- Listens to each and every event that's coming from Twilio Segment.
- Infers the item purchased by looking at the Order Completed properties.
- Stitches together a personalized SMS message.
- Calls the Twilio API endpoint to send the SMS notification to customers.
💡 Bonus tip: If you’d like to use the code we are using in this recipe, check it out here.
We can test this out in practice by using a sample event.
On the right-hand side of the screen, click Use Sample Event. Then, select the data source you set up for your e-commerce website, and the specific event that you’d like to trigger the message such as Order Completed. Click Save Event. This will bring you back to the Functions homepage, where you can see the event and associated properties in the Payload section of the screen.


Simply add your Twilio account ID, auth token, from and to numbers to the right-hand side of your screen, as well as your Event Name that will trigger the message (in this case Order Completed).


It’s time to deploy!
Hit Run and you’ll see a success message appear confirming that the API call is being made to Twilio and that an SMS is being made. You can log in to the Twilio Console to confirm the SMS has been sent.


Wrapping up
As a recap, here’s what we’ve done in this recipe:
Created a Twilio Segment source and implemented event tracking to understand user behavior on our website.
Connected the Twilio Segment source with Twilio via Functions.
Triggered personalized SMS via Twilio Programmable SMS.
You’re ready to enjoy all the benefits that come from personalized SMS – better open rates, increase engagement, and a better customer experience.
Want to implement personalized SMS for your own business? Get in touch with a member of the team or start building today.
Ready to see what Twilio Segment can do for you?


The Customer Data Platform Report 2025
Drawing on anonymized insights from thousands of Twilio customers, the Customer Data Platform report explores how companies are using CDPs to unlock the power of their data.
Related Posts
Related Resources
Twilio Docs
From APIs to SDKs to sample apps
API reference documentation, SDKs, helper libraries, quickstarts, and tutorials for your language and platform.
Resource Center
The latest ebooks, industry reports, and webinars
Learn from customer engagement experts to improve your own communication.
Ahoy
Twilio's developer community hub
Best practices, code samples, and inspiration to build communications and digital engagement experiences.