# Double Opt-In

## Introduction[](#introduction)

This document will guide you through the basics of setting up double opt-in functionality for your users. A double opt-in is a good practice to follow in order to improve your deliverability and/or comply with local laws like CASL in Canada.

## Ingredients[](#ingredients)

*   A `double_optin` attribute to track each person’s status
*   A data-driven segment, either for people without the `double_optin` attribute or for new users depending on your strategy
*   A segment-triggered campaign where we’ll send an email with a link people can click to opt in
*   Another data-driven segment for people who have clicked the opt-in link link

## Method[](#method)

### Create a segment to trigger the campaign[](#create-a-segment-to-trigger-the-campaign)

First and foremost, we’ll need an attribute for each person that tracks whether or not they’ve been through the double-opt in process, and what they’ve chosen. Let’s call this attribute `double_optin`.

Then, we’ll need a [segmentA group of people who match a series of conditions. People enter and exit the segment automatically when they match or stop matching conditions.](/journeys/data-driven-segments/) to trigger the double opt-in campaign. For this example, we’ll use a condition of “`double_optin` does not exist”. You can use a different segment if you want—like a data-driven segment for new users.

[![A data-driven segment with the condition attribute double_optin does not exist](https://docs.customer.io/images/recipe-double-optin-segment-trigger.png)](#d8f5cfb0980f7c808fc082a621a6a1c1-lightbox)

### Start creating your double opt-in campaign[](#start-creating-your-double-opt-in-campaign)

Create a segment-triggered campaign:

1.  Go to **Campaigns**.
2.  Click **Create Campaign**.
3.  Click **Choose trigger**.
4.  Select **Segment change**.
5.  Use the segment you created in the previous step.
    
    [![The first step of the campaign creation where we define the condition as people matching conditions and the condition being that they're in the segment we just created](https://docs.customer.io/images/recipe-double-optin-segment-trigger-1.png)](#0f538da884ad1d403ba5aa81bcd3dc98-lightbox)
    
6.  Drag an email into your workflow. Add your content including a link that your audience can click to confirm that they want to opt-in.

[![The workflow at this stage, with an email action as the first workflow action](https://docs.customer.io/images/recipe-double-optin-campaign-setup-2-workflow-1.png)](#335c9ed3d48b6d67a85095845a86a0b6-lightbox)

 Make sure the double opt-in URL is unique

You can use any URL for the link, as we’ll track the clicks on a link matching a specific URL. Make sure it’s a unique URL either by creating a dedicated page to link to, or by adding a URL variable such as `?double_optin=true` to the URL.

### Create a segment for users who click the link in your email[](#create-a-segment-for-users-who-click-the-link-in-your-email)

Now that we have the email created, we’ll need a second data-driven segment for people that clicked the opt-in link. Create your new segment before you finish setting up your campaign.

[![Our second data-driven segment where we define the condition of the email we just created having been clicked](https://docs.customer.io/images/recipe-double-optin-segment-condition.png)](#59e6e0a0185e86243193b88ea5c7e245-lightbox)

### Finish creating your double opt-in campaign[](#finish-creating-your-double-opt-in-campaign)

Now that we have that second segment, we can complete the setup of our campaign.

We’ll add a **Wait Until** workflow action and use the segment we just created as the condition that we want to wait for. We’ll also add a *maximum wait time* of 1 week before *moving to the next action*. This lets us consider people who haven’t clicked within 7 days of receiving the email as not opted-in.

Thanks to **Wait Until conditions** we can define different flows based on which condition is matched first. If the user enters the segment we created (and therefore has clicked the email), we’ll set the attribute to true. If they haven’t entered the segment after 1 week, we’ll assume they haven’t perform double opt-in and set the attribute to false.

To do that, we’ll add a **Create or Update Person** action in each branch to update the `double_optin` attribute.

[![Our branches with a Create or Update Person workflow actions in each branch](https://docs.customer.io/images/recipe-double-optin-campaign-setup-2-workflow-4.png)](#839e606913845435f46ce0f59d1b57dd-lightbox)

## Overview of the final result[](#overview-of-the-final-result)

Your campaign should look like this! When you’re done, activate your campaign to begin processing double opt-ins.

[![An overview of the whole campaign, from trigger to exit, with our email, wait until, branch, and create or update person actions](https://docs.customer.io/images/recipe-double-optin-overview.png)](#2d51db258acbd16f5773d503efd3a0b7-lightbox)

## Use the double opt-in attribute to filter messages[](#use-the-double-opt-in-attribute-to-filter-messages)

The `double_optin` attribute is a custom attribute on a person’s profile. Customer.io doesn’t automatically check this attribute before sending messages—setting the attribute alone doesn’t prevent messages from going to people who haven’t opted in.

To enforce double opt-in across your messaging, create a **data-driven segment** for people where `double_optin` equals `true`. Then use this segment to control who receives your campaigns and newsletters:

*   **Campaigns**: Add the segment as a filter in your campaign’s **entry criteria** so that only people who completed double opt-in can enter the campaign.
*   **Newsletters**: Set the segment as the **recipient** of your newsletter to make sure you only send to people who opted in.