Solution Recipe 16: “Opt-Out Survey” — Capture and record an unsubscribe reason when customers opt-out

Rob Boland
Klaviyo Developer Blog
4 min readJan 3, 2023

Solution Recipes are tutorials to achieve specific objectives in Klaviyo. They can also help you master Klaviyo, learn new third-party technologies, and come up with creative ideas. They are written mainly for developers & technically-advanced users.

  • WHAT YOU’LL LEARN: How to ask your subscribes for an “unsubscribe reason” when they opt-out from your emails
  • WHY IT MATTERS: We often assume customers unsubscribe and opt out of emails simply because they are no longer interested in our brand. However this is not always the case, and the best time to ask someone is when they unsubscribing. This will help you improve your communication strategy and reduce your unsubscribe rate.
  • LEVEL OF SOPHISTICATION: Intermediate

PREREQUISITE:

In order to implement this solution recipe, you will need to be utilizing Klaviyo’s Hosted Pages feature for your accounts unsubscribe page.

Related Read: Solution Recipe 8: How to create a custom multilingual unsubscribe and preference page in Klaviyo

The Hosted Pages feature allows us to customise all of the code on the unsubscribe page. We can add our own HTML, CSS and most importantly for this solution recipe — Javascript.

Ingredients

  • Intermediate HTML and CSS formatting experience
  • A basic knowledge of the Django templating language
  • A working knowledge of the Klaviyo /track API
  • A heaped tablespoon of Javascript

Solution Design

There are a few moving parts to this solution recipe which are illustrated below.

An overview of how we capture the unsubscribe reason in Klaviyo
Overview of how we capture the unsubscribe reason in Klaviyo

At a high level the following steps occur:

  • A user profile receives an email from Klaviyo, opens it and clicks on the “unsubscribe” link.
  • This user is then directed to a custom Klaviyo Hosted Unsubscribe page.
  • The user selects an unsubscribe reason from the form before submitting their unsubscribe request.
  • Upon submitting the unsubscribe request, an AJAX call is made to send an event to Klaviyo’s track API with the reason the user unsubscribed. The unsubscribe is also recorded separately as part of Klaviyo’s Hosted Page logic.

Once the unsubscribe reason events are recorded in Klaviyo, these can then be reported on using custom reports or segments in Klaviyo.

This is what the final unsubscribe page we are going to build will look like.

You are free to modify the look, feel and options as you wish. This is simply a template for you to get started with.

Instructions

Step 1: Enable Hosted Pages in your Klaviyo account

If you have not already, you will need to enable the Hosted Pages feature in your Klaviyo account.

Step 2: Create an unsubscribe page

For this example, we are going to use a standard boilerplate unsubscribe page. You are free to customise the look and feel of this page as you wish.

Step 3: Add your unsubscribe/opt-out survey questions

Now that we have a basic unsubscribe page, we are going to add some radio buttons to allow a user to choose a reason why they are unsubscribing.

Additionally we will also add a field to allow a user to enter an “other” reason or give additional feedback

Step 4: Send events to Klaviyo

The last piece of the puzzle is saving this information in Klaviyo. To do this, we are going to send an eventSubmitted Unsubscribe Reason which will record the unsubscribe reason and also add a profile property with the unsubscribe reason.

The snippet of code below, will capture the details of the form and send an event using Klaviyo’s track API as soon as the person clicks the “unsubscribe” button.

Putting it all together

The full hosted page code is below

Configuring your unsubscribe page

Don’t forget, in order for this unsubscribe page to actually be used in your emails, you will need to update your Klaviyo consent page settings to use the custom hosted pages. Instructions on how to do this can be found here.

Segment/Report on your opt-out survey

Once you have activated this hosted page on your account, you will start to see unsubscribe events.

And the profiles will also have properties added to them as well.

Using this information we can now create segments or reports to get an understanding of why people are unsubscribing

An example of how to build a segment based on unsubscribe reason
An example of how to build a report of unsubscribe reasons

Impact

Now you are able to gather more detailed information as to why users are unsubscribing. This will allow you to better tailor your marketing campaign and strategy to help you reduce your unsubscribe rates and ensure you are sending relevant content to your customers.

--

--