Lob's website experience is not optimized for Internet Explorer.
Please choose another browser.

Arrow Up to go to top of page
Hero Image for Lob Deep Dives Blog PostSegment & Lob: From Data to Direct Mail
Tutorials
August 9, 2023

Segment & Lob: From Data to Direct Mail

Share this post

Overview

Twilio Segment is a customer data platform (CDP) that captures and stores all first-party customer data regarding your product or service in a centralized place. More specifically, Segment collects events from your interfaces (websites, web apps, etc.), and from that information, helps you create more personalized customer experiences across various channels.

Lob API integrations enable connections between Lob's direct mail automation platform and popular CRMs, CDPs, or marketing automation tools. This allows you to trigger mailpieces within workflows inside these platforms.

We will plug Lob into our Segment flow by making a custom destination function. Destinations are business tools or apps to which you can send the data you collect in Segment. Depending on which mailpiece you want to send (postcard, letter, etc.), building a destination function that sends it merely involves reading data and calling Lob’s API. These steps are outlined below.

Getting Started

  • Make sure you have a Lob account with your API keys. It is highly recommended that you use your (secret) test API key first.
  • Have a creative file ready to use (hosted PDF file or HTML template)
  • Have your Segment account ready

Connect Segment to Lob using Destination Functions

1. In the sidebar, navigate to “Connections” -> “Catalog,” and then click the Functions tab:

Segment & Lob: From Data to Direct Mail  image 2

2. Click the “New Function” button:

Segment & Lob: From Data to Direct Mail  image 3

3. Under “Select Function Type,” click “Destination,” and then click “Build”:

Segment & Lob: From Data to Direct Mail  image 4

4. Enter your Javascript code in the editor on the left, and test your function on the right; refer to the following section on form factors for details. Click “Configure” when done:

Segment & Lob: From Data to Direct Mail  image 5

5. Give the function a name (required), description, and logo, and click “Create Function” to save:

Segment & Lob: From Data to Direct Mail  image 6

Segment Events by Mail Format

The following are sample functions to send a Lob mailpiece from a given Segment event, organized by mailpiece. Segment provides six different event types that destination functions can operate on:

  • Identify: who is the customer?
  • Track: what are they doing?
  • Page: what web page are they on?
  • Screen: what app screen are they on?
  • Group: what account or organization are they part of?
  • Alias: what was their past identity?

The following sample code translates Track events into Lob mailpieces by defining an onTrack function. (For other functionalities, just define a similarly named function, e.g., onPage for Page events.)

Remember to test your mail sent through Segment by using your test API key first. Once you do, plug in your live key, and enjoy sending intelligent, automated mail pieces with Lob and Segment!

Conclusion

Given how useful Segment is for integrating multiple different interfaces for collecting and operating on customer data, this tutorial gives us the ability to add Lob as one of many possible powerful tools for accomplishing data-driven, instantaneous operations on that data. Luckily, plugging Lob into Segment is as easy as making a destination function and using it in your workflows.

Resources

Here are two other resources that might help with crafting your workflow:

Continue Reading