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.
Note: We do our best to make sure any code and API references are accurate and current when this is published, but you might need to update code and it’s always a best practice to leverage our latest API versions . If you have questions, feel free to hop over to our Developer Community .
How to use Klaviyo’s hosted pages feature to create customizable, multilingual unsubscribe and preference pages.
The standard Klaviyo subscribe and preference pages provide easy-to-use preset functionality, but for more advanced use cases, styling requirements or multilingual needs, they might not cover 100% of business/marketing cases.
High
Introduction
Klaviyo provides an easy-to-use editor for creating unsubscribe and preference pages to use in your email campaigns. For more advanced use cases it may not always be possible to achieve the level of customisation to fit your needs with these tools.
Klaviyo has a feature called “Hosted Pages” — these are essentially webpages hosted in your Klaviyo account where you can add your own custom HTML, CSS, Javascript and utilise our Django templating syntax to build your own unsubscribe and preference pages.
Challenge
Customers can have business/marketing use cases where our standard preference/unsubscribe pages do not have the required logic or customisation tools necessary to suit their needs. In these scenarios we can utilise the hosted pages feature in Klaviyo.
An example of this could be to dynamically change the language on an unsubscribe/preference page to match the customers preferred language. While Klaviyo supports multiple languages, the language is set on the account level. As such our standard unsubscribe/preference pages can only be displayed in one language per Klaviyo account.
This solution recipe will walk through how to setup a simple unsubscribe and preference page using Klaviyo’s hosted pages feature. Then it will show you how to add in logic to dynamically change the content depending on a users profile property (in this case country).
Ingredients
- Intermediate HTML and CSS formatting experience
- Intermediate level knowledge of the Django templating language
- A pinch of Javascript
Instructions
Step 1: Enable Hosted Pages in your Klaviyo account
You may not have the Hosted Pages feature enabled in your Klaviyo account. In order to enable it, login to your Klaviyo account and navigate to Account > Settings > Domains and Hosting.
Then click on the “Enable Custom Pages” button as per the screenshot below
Note: This setting is only available for an account on a paid plan that has passed account verification .
Once activated, you will see the “Hosted Pages” option appear in your Klaviyo account next to “Preference Pages”.
Step 2A: Create a basic unsubscribe page template
The first step is create an unsubscribe page template by creating a new page and giving it a name of your choice.
Klaviyo will then generate a blank HTML boilerplate template for this page like below:
When this hosted page is used as an unsubscribe link in an email, Klaviyo will automatically add some query parameters that will enable the hosted page to identify the user profile who clicked the link.
This will allow us to fetch and display information for the users profile automatically on the page.
In this example, we will add some HTML and Django syntax that will display the current users name and email address in a form.
Note: I’ve imported the Bootstrap CSS framework for demonstration purposes, but you are free to use your own CSS.
Step 2B: Add the logic to unsubscribe a profile
Now that we have the basic unsubscribe page populating the users details, we need to add some additional hidden fields so that Klaviyo knows what to do when the user submits this form.
In this example, we want Klaviyo to unsubscribe the user when the form is submitted.
In order to do this, we need to add some hidden fields to the form. For unsubscribing they are:
<!-- this hidden field tells Klaviyo what to do when the form is submitted -->
<input type="hidden" name="$unsubscribe" value="true" />
<!-- this hidden field tells Klaviyo where to redirect the user after they unsubscribe (optional) -->
<input type="hidden" name="$unsubscribed_url" value="http://example.com/unsubscribed" /> And that’s it! You now have a simple HTML page that will fetch a profile’s details and then unsubscribe them when they submit the form.
The full HTML for this example is below: