Campaign for new subscribers with Stripe

Use subscription events from Stripe to trigger a campaign welcoming new subscribers to your service.

As a part of this process, you’ll trigger a data campaign when someone signs up for a subscription (a subscription_schedule.created event). You’ll use this incoming data to identify your new subscriber and send an event to trigger a welcome campaign to your new subscriber.

 This process works for other Stripe events

This tutorial is based on subscription events, but you could just as easily adapt it to send dunning emails based on Stripe’s invoice.payment_failed event or other use cases!
sequenceDiagram participant A as Subscriber participant B as Stripe participant C as Customer.io A->>B: Signs up for subscription B->>C: Webhook containing subscription trigger C->>C: Identify person C->>C: Convert webhook to event
that triggers campaign C->>A: Send messages (Welcome to our service!)

Before you begin

You’ll need access to your Stripe account and your Customer.io Site ID and API Key credentials. You can find your Customer.io Site ID and API Key credentials under Data & Integrations > Integrations > Customer.io API.

As a part of this guide, you’ll:

  1. Set up a data campaign using Stripe’s Connect Webhook feature to capture a response from Stripe when someone creates a subscription—represented by the subscription_schedule.created event below.
  2. Set up an event-triggered campaign using the Stripe event to message people about their new subscription.
{
  "id": "sub_sched_1Jydf3JRq3BWBpoSiD8FYI62",
  "object": "subscription_schedule",
  "canceled_at": null,
  "completed_at": null,
  "created": 1637591905,
  "current_phase": null,
  "customer": {
      "id": "customers-id-here",
      "email": "person@example.com"
  },
  "default_settings": {
    "application_fee_percent": null,
    "automatic_tax": {
      "enabled": false
    },
    "billing_cycle_anchor": "automatic",
    "billing_thresholds": null,
    "collection_method": "charge_automatically",
    "default_payment_method": null,
    "invoice_settings": null,
    "transfer_data": null
  },
  "end_behavior": "release",
  "livemode": false,
  "metadata": {},
  "phases": [
    {
      "add_invoice_items": [],
      "application_fee_percent": null,
      "billing_cycle_anchor": null,
      "billing_thresholds": null,
      "collection_method": null,
      "coupon": null,
      "default_payment_method": null,
      "default_tax_rates": [],
      "end_date": 1669646305,
      "invoice_settings": null,
      "items": [
        {
          "billing_thresholds": null,
          "price": "price_1Jyd0G2eZvKYlo2CgSUwG9P3",
          "quantity": 1,
          "tax_rates": []
        }
      ],
      "proration_behavior": "create_prorations",
      "start_date": 163819670
      5,
      "transfer_data": null,
      "trial_end": null
    }
  ],
  "released_at": null,
  "released_subscription": null,
  "status": "not_started",
  "subscription": null
}

 Capture your audience’s email in subscriptions!

The customer value in a Stripe event can be a string containing a person’s ID, or an object containing multiple identifiers (id, email, etc) depending on the information you gather from a person. Capturing a person’s email lets you use Stripe as a single source to identify and message people as a part of this tutorial.

Set up your data campaign

This workflow will identifyThe Customer.io operation that recognizes a person. When you call the method or API to identify a person, Customer.io either adds a person if they don’t exist in your workspace, or otherwise updates/associates data with a person. Activities before a person is identified may be attributed to an anonymous ID. people and convert incoming subscription_status.succeeded events—sent when someone subscribes to your service—to Customer.io events. Later, we’ll use these events to trigger a campaign that messages your new subscribers and assigns them an ID if the don’t already have one.

  1. Go to Campaigns and click Create Campaign.

  2. Select Data arrives via webhook and copy the Webhook URL.

    the data campaign trigger exposes a webhook URL
    the data campaign trigger exposes a webhook URL

  3. In Stripe, go to Developers > Webhooks and click Add endpoint.

    1. Paste your Webhook URL into the Endpoint URL field.
    2. Click Select events, select Supscription Schedule > subscription_schedule.created, and then click Add events. This tells Stripe to trigger your webhook when someone creates a new subscription.
    3. Click Add endpoint.
    4. Turn Test mode on, if it isn’t already, and then Send a test event. This provides Customer.io with some test values that you can reference when creating your campaign.
      Set up your webhook in Stripe
      Set up your webhook in Stripe
  4. Return to Customer.io and make sure that you received test data. If so, click Save & Next.

  5. In the Workflow step, set up your identify request. This makes sure that the person in your Stripe event exists in Customer.io.
    1. Drag Send data into your workflow and click it. Set the Name of the webhook to Identify subscriber.

    2. Click Add Request

    3. In the URL, enter https://{site_id}:{api_key}@track.customer.io/api/v1/customers/{{trigger.data.object.customer.id}}. This identifies your new person by their Stripe id.

    4. For the payload, set attributesA key-value pair that you associate with a person—like their name, the date they were created in your workspace, etc. Use attributes to target people and personalize messages. from your Stripe event. In this example, you must set the email attribute.

       {
           "email": "{{trigger.data.object.customer.email}}"
       }
      
    5. Click Save Changes.

    Set up your identify request from Stripe
    Set up your identify request from Stripe

  6. Drag another Send data block in your workflow and set up your event. This converts your incoming Stripe data to a Customer.io event that will trigger your “New Subscriber” campaign.
    1. Click the Webhook action, set the Name to New subscriber event, and click Add Request.

    2. In the URL, enter https://{site_id}:{api_key}@track.customer.io/api/v1/customers/{{trigger.data.object.customer.id}}/events. This triggers an event for the person you identified by id in previous steps.

    3. For the payload, enter the event name and data that you want to associate with a person in Customer.io. For our purposes, we’re only capturing the start_date.

      {
        "name":"Stripe Subscription Created",
        "data":{
          "rating": "{{trigger.rating}}"
        }
      }
      
    Set up your event from Stripe
    Set up your event from Stripe

  7. Click Save Changes and finish setting up your data campaign. Now you’re ready to set up your campaign to message people who responded to your NPS survey!

your data campaign workflow after you've set up both data events
your data campaign workflow after you've set up both data events

Set up your people campaign

Now you can trigger a campaign to send messages to new subscribers using the Stripe Subscription Created event you set up in your data campaign.

 Tag your campaigns

In this tutorial, you need two campaigns to achieve your goal. If you apply a tag to both your data and people campaigns, you can easily relate your campaigns and find them on the Campaigns page.
  1. Go to Campaigns and click Create Campaign.

  2. Click A person performs an event. Under Define the trigger event, enter stripe-subscription-created and set additional filters. For this case, we only care that they’re creating a subscription, but we might want to limit the campaign Frequency, in case a person has cancelled and restarted their subscription over a short period.

    set up an event trigger based on your data campaign
    set up an event trigger based on your data campaign

  3. In your workflow, add messages. You can access properties from the incoming event using liquidA syntax that supports variables, letting you personalize messages for your audience. For example, if you want to reference a person’s first name, you might use the variable {{customer.first_name}}. in the event object—i.e. {{event.<property>}}.

  4. When you’re finished, click Save & Next, and finish configuring your campaign. Now, when someone subscribes to your service, you can identify them and start them on a campaign!

Copied to clipboard!