Skip to main content

    Build custom functions with Code

    Course overview
    Lesson
    2 min read

    Restructure event data for use in segmentation

    Walk through a practical example of how to manipulate and restructure event data for easy use in segmentation and filtering.

    Code functions can be used to save nested event data as custom profile properties. This example highlights how you can save highly personalized event data, like answers to a quiz, as custom profile properties. This is a great use case if you:

    1. Collect data from a third party system.
    2. Want to filter flows based on these data.
    3. Use segments to send personalized messages.

    Make nested data accessible with Code

    Segment conditions and flow filters can only be used with top-level event data. This means that you cannot create segments nor filter flows on any nested data, or data that exists within another variable.

    In this example, we’ll highlight how Nani, a health and wellness brand, used a Code function to make their nested data accessible. You’ll see how Code enables this brand to make better use of their full set of customer data, creating highly-personalized messaging by using valuable information already stored within Klaviyo events.

    Quiz response data:

    Make response data accessible

    Nani recently used a third party to set up a skincare quiz that asks customers about their skin, environment, and current skincare routine. The quiz then provides customized skincare recommendations for each customer. Nani has seen great engagement results after setting up this quiz.

    In Klaviyo, every time a customer completes the quiz, an event is logged on their profile that contains the results of their quiz.

    The problem

    Quiz answers are nested within the event data under a variable called “quiz answers.” This variable contains valuable information about each customer's skin type, preferences, and skincare routine.

    Segments can only be created on top-level data. Nani wants to make segments of customers with different skin types, but cannot access this nested data from the segment builder.

    The function

    Nani created a function triggered by the Completed Quiz event. This function takes each customer’s answers to “What is your skin type?” and “What is your primary skin concern?” and adds them to that customer’s profile. Now, every time a customer takes the quiz, the properties "skin type" and "primary skin concern" are automatically added to their profile.

    The outcome

    Nani can now make segments of customers with different skin types and concerns.

    They recently released a highly-anticipated dry skin serum and were able to send a highly targeted and personalized promotional email to their dry skin segment.

    Restructure event data for use in segmentation