Skip to content
Guides
Double opt-in

Double opt-in

Setting up double opt-in is a process that allows you to verify the email address of a new subscriber.

Creating an unsubscribed contact

When you trigger an event for a contact, they will automatically be subscribed unless you pass subscribed: false along with the event.

When you trigger the event, Plunk's API will return you a JSON object with the contact's ID. You can use this ID to send them a confirmation email with the transactional email API

await fetch('https://api.useplunk.com/v1/track', {
    method: "POST",
    headers: {
        "Content-Type": "application/json",
        "Authorization": "Bearer API_KEY", // Put your API key here
    },
    body: JSON.stringify({
        "event": "new-project",
        "email": "hello@useplunk.com",
        "subscribed": false,
    }),
});

Confirming opt-in

With an action

You can leverage Plunk's action to confirm the opt-in. For this you will need to create an transactional template that contains a link to Plunk's hosted subscribe page or a custom-built page that will call the Plunk API to subscribe the contact.

Plunk's hosted pages can be found at the following URLs:

  • app.useplunk.com/subscribe/contactID
  • app.useplunk.com/unsubscribe/contactID

When creating a template, you can use the built-in Plunk variables in the editor to automatically fill in the contact's ID.

An image showing how to use Plunk's built-in variables in a link

With a transactional email

Using the contact ID returned from the previous step, you can send a transactional email to the contact. This email will contain a link to the subscription page hosted by Plunk. All contacts have a subscribe and unsubscribe page that can be found at the following URLs:

  • app.useplunk.com/subscribe/contactID
  • app.useplunk.com/unsubscribe/contactID

Once the contact confirms their subscription by clicking the button on the page, they will be toggled to a subscribed contact.

await fetch('https://api.useplunk.com/v1/send', {
    method: "POST",
    headers: {
        "Content-Type": "application/json",
        "Authorization": "Bearer SECRET_KEY", // Put your API key here
    },
    body: JSON.stringify({
        "to": "hello@useplunk.com",
        "subject": "Please confirm your email",
        "body": "<h1>Confirm your email</h1><p>Click <a href='https://app.useplunk.com/subscribe/ID'>here</a> to confirm your email.</p>",
    }),
});
Last updated on January 23, 2023