How to Add a Twilio Function as a Segment Destination

When using Segment, a destination receives data from Segment. Destinations differ from Segment sources (such as a website or a mobile application) which send data to Segment. One source can have multiple destinations! For more information on sources,…


This content originally appeared on Twilio Blog and was authored by Lizzie Siegle

When using Segment, a destination receives data from Segment. Destinations differ from Segment sources (such as a website or a mobile application) which send data to Segment. One source can have multiple destinations! For more information on sources, check out this blog post here.

Destinations let you edit or annotate your Segment events so you can send the data to any external tool or API without worrying about setting up or maintaining any infrastructure.

Many destinations can accept data from each type of source, but some are only compatible with specific source types (ie. web or server only). You can see which source types a specific destination can accept data from in the documentation for that destination.

To learn more about destinations, check out the Segment documentation here.

Prerequisites

To follow along with this post, you need these things:

Add a Twilio Function as a Segment Destination

You can make a Twilio Serverless Function to receive data from Segment in the Functions and Assets section of the Twilio Console or via the Twilio CLI. Name your Function file segment.js.

In your Segment Workspace beneath the blue Copy Snippet button, click the blue Add Destination button.

destinations

Search the Destinations Catalog for webhook and select Webhooks.

search destinations catalog for webhooks and select webhooks

Then click the blue Configure Webhooks button.

destination catalog: configure webhooks

Select a data source to be your website and now to setup the webhook, we give it a Destination name, followed by clicking Save.

connectpersonalsitetowebhook

Then select Webhooks (max 5) and enable the toggle next to Setup Guide.

connection settings: webhooks (max 5)

Put in your Function URL ending in /segment and set a header to be something like you see below.

edit settings

Click the blue Save button and you have your Twilio Function set as a destination in Segment!

If you set a header in a Segment source, the JavaScript code to access it in a Twilio Function would be

event.request.headers.{header};

The JavaScript to access a button click action with in your Twilio Function

event.event

Testing your Segment Destination

You can test that your Destination is receiving data from Segment in the Event Tester section of your Destination in the Segment Workspace.

event tester in Workspace

What's Next for Segment Destinations

Other destinations could be Segment destination functions, third-party tools like Customer.io, Leanplum, and Airship, and more.

Stay tuned for more technical Segment tutorials, and let me know online what you're building with Segment!


This content originally appeared on Twilio Blog and was authored by Lizzie Siegle


Print Share Comment Cite Upload Translate Updates
APA

Lizzie Siegle | Sciencx (2022-07-22T03:38:17+00:00) How to Add a Twilio Function as a Segment Destination. Retrieved from https://www.scien.cx/2022/07/22/how-to-add-a-twilio-function-as-a-segment-destination/

MLA
" » How to Add a Twilio Function as a Segment Destination." Lizzie Siegle | Sciencx - Friday July 22, 2022, https://www.scien.cx/2022/07/22/how-to-add-a-twilio-function-as-a-segment-destination/
HARVARD
Lizzie Siegle | Sciencx Friday July 22, 2022 » How to Add a Twilio Function as a Segment Destination., viewed ,<https://www.scien.cx/2022/07/22/how-to-add-a-twilio-function-as-a-segment-destination/>
VANCOUVER
Lizzie Siegle | Sciencx - » How to Add a Twilio Function as a Segment Destination. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2022/07/22/how-to-add-a-twilio-function-as-a-segment-destination/
CHICAGO
" » How to Add a Twilio Function as a Segment Destination." Lizzie Siegle | Sciencx - Accessed . https://www.scien.cx/2022/07/22/how-to-add-a-twilio-function-as-a-segment-destination/
IEEE
" » How to Add a Twilio Function as a Segment Destination." Lizzie Siegle | Sciencx [Online]. Available: https://www.scien.cx/2022/07/22/how-to-add-a-twilio-function-as-a-segment-destination/. [Accessed: ]
rf:citation
» How to Add a Twilio Function as a Segment Destination | Lizzie Siegle | Sciencx | https://www.scien.cx/2022/07/22/how-to-add-a-twilio-function-as-a-segment-destination/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.