Klaviyo Destination

Segment makes it easy to send your data to Klaviyo (and lots of other destinations). Once you've tracked your data through our open source libraries we'll translate and route your data to Klaviyo in the format they understand. Learn more about how to use Klaviyo with Segment.

Getting Started

When you toggle on Klaviyo in Segment, this is what happens:

  • Our CDN is updated within 5-10 minutes. Then our snippet will start asynchronously loading Klaviyo’s track.js onto your page. This means you should remove Klaviyo’s snippet from your page.
  • Since Klaviyo only records custom events and custom user data, no events or users will appear in Klaviyo until you start using the API outlined below.

Klaviyo is supported on the client-side, server-side and mobile.


Identify

Client-side

When you call identify on analytics.js, we call Klaviyo’s identify with the traits object. We augment the traits object to have traits.$id be the userId since Klaviyo takes the user ID on the traits object itself.

Note: When sending data to Klaviyo via analytics.js, an initial page call is required. By default, this is already added in your Segment snippet.

Server-side

When you call identify from one of our server-side languages, we’ll create/update a Klaviyo person, with the traits you provide in the identify.

If your userId is an email, or you provide an email in traits.email, we’ll send it as the $email property to Klaviyo. Also, you can send us traits.phoneNumber and we’ll transform it to traits.$phone_number per Klaviyo’s fancy (we’ll do the same for all of Klaviyo’s special people properties.)

Adding users to a list

When you call identify using a server side library, you can optionally send list data in order to add that person to a specific List in Klaviyo. We will use their List API.

In order for this to work, you must add the Private Key inside the Klaviyo settings in Segment. You can generate a private key by clicking Account > Settings > API Keys > Create API Key inside Klaviyo.

You can choose to provide a default listId that we can fallback on when adding users to a list. If you’d like to override this default listId, you can also do so by sending it manually via code in destinations.Klaviyo.listId. You can also choose whether you want to force users to confirm the optin to your list. The default settings will be true. However, you can uncheck this option in the Klaviyo settings inside Segment or override it per identify call via code.

Important: You must provide an email in your traits or send email as the userId. Be sure to provide the Private Key in the Klaviyo settings for this to work.

node example:

analytics.identify({
  userId: '019mr8mf4r',
  traits: {
    name: 'Michael Bolton',
    email: 'mbolton@initech.com',
    plan: 'Enterprise',
    friends: 42
  },
  integrations: {
    Klaviyo: {
      listId: 'baV129', // will override whatever it is in the UI setting
      confirmOptin: false // optional
    }
  }
});

Note: Inappropriately setting Klaviyo.confirmOptin to false without explicit permission of the people added can result in your Klaviyo account being suspended and/or terminated by Klaviyo.

Track

When you call track on analytics.js, we call Klaviyo’s track with the exact same parameters.

We’ll key the user using the userId, but we’ll also provide the Klaviyo $email customer_property if your userId is an email, or you provide email as one of your event properties.

Ecommerce

Completed Order

Klaviyo supports the Order Completed event that is outlined in our specs. If you send us a Order Completed event, we will send Klaviyo a Placed Order event and a Ordered Product event for each item listed in the properties.products array. We will also attach customer_properties with the userId set as $id for each of those Klaviyo events.

While it is not included in our spec for a Order Completed event, you can optionally include a productUrl and or imageUrl as a property of an item inside the products array. We will pass those along to Klaviyo as Product URL and Image URL respectively.

Each auto-generated Ordered Product event requires a unique $event_id, which Segment automatically generates based on a combination of the orderId of the parent Completed Order event, and the productId, id or sku of the product itself (in this order). In other words, you must pass either a productId, id or sku to Segment, or Klaviyo will reject your Ordered Product events.

An example Order Completed event may look like this using the node.js library:

analytics.track({
  userId: '019mr8mf4r',
  event: 'Completed Order',
  properties: {
    orderId: '50314b8e9bcf000000000000',
    total: 30,
    revenue: 25,
    shipping: 3,
    tax: 2,
    discount: 2.5,
    coupon: 'hasbros',
    currency: 'USD',
    repeat: true,
    products: [
      {
        id: '507f1f77bcf86cd799439011',
        sku: '45790-32',
        name: 'Monopoly: 3rd Edition',
        price: 19,
        quantity: 1,
        category: 'Games',
        productUrl: 'http://www.example.com/path/to/product',
        imageUrl: 'http://www.example.com/path/to/product/image.png',
      },
      {
        id: '505bd76785ebb509fc183733',
        sku: '46493-32',
        name: 'Uno Card Game',
        price: 3,
        quantity: 2,
        category: 'Games'
      }
    ]
  }
});

Supported Sources and Connection Modes

WebMobileServer
📱 Device-based
☁️ Cloud-based

To learn more about about Connection Modes and what dictates which we support, see here.

Settings

Segment lets you change these destination settings via your Segment dashboard without having to touch any code.

Enforce Email as Primary Identifier

If this option is enabled, we will never set $id field to your userId when you call .identify() or .track(). Instead, we will only set a custom attribute id and only set $email as the primary identifier with your traits.email or properties.email. You should be careful when enabling this option and understand its full implications. This should only be enabled if you are experiencing an issue with duplicate profiles being created inside Klaviyo.

List ID

Insert the ID of the default list that you’d like to subscribe users to when you call .identify().

Enter your Private Key

Note: this is required to use the List API. You can find this by going to Klaviyo’s UI and clicking Account > Settings > API Keys > Create API Key

Fallback on Anonymous ID

Enable this option to fallback on anonymousId if userId is not available when sending server side events. Note that this option may result in superfluous user profiles in Klaviyo and is generally not recommend. If this option is unchecked, we will only accept server side events that includes the userId.

Send Placed Order Events as Order Completed

Enable this setting if you’d like to send Order Completed events as is rather than changing the event name to Placed Order on the server side (client side always sends Order Completed). It is recommended that you keep this setting enabled so that both client and server side Klaviyo integration sends the same event for Order Completed. Klaviyo does not treat the event names differently in their backend feature wise. This option was introduced to bridge the existing disparity between our client and server side integration regarding how this event name is sent without forcibly breaking the current behavior.

API Key

Your API key

Confirm Optin

This flag determines whether someone is sent an email with a confirmation link before they are added to the list. Defaults to true (checked). This should only be set to false or unchecked if you have already received explicit permission from that person to add them to this list.


If you have any questions or see anywhere we can improve our documentation, please let us know or kick off a conversation in the Segment Community!