Tutorial

Solution Recipe | Tree Planting with Klaviyo

  • 19 May 2023
  • 5 replies
  • 174 views
Solution Recipe | Tree Planting with Klaviyo
Userlevel 7
Badge +36

Hi Developer Group!

 

Please enjoy this installment of our Solution Recipe series, brought to you by our very own Senior Solution Architect, Olaf Dunn!

 

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 use Klaviyo flows to increase customer loyalty, aid your sustainability efforts, and promote conscious consumerism.

 

LEVEL OF SOPHISTICATION: Easy

 

Introduction

 

For Earth Day 2023, we wanted to highlight how Klaviyo flows can be used to aid sustainability efforts and promote conscious consumerism through tree planting efforts — all while boosting retention & engagement rates.

 

A flow is a sequence of automated actions (which can include email and SMS messages) that is triggered when a person performs a specific action. For example - when someone joins a list, is added to a segment, makes a purchase, or abandons their cart.

 

Any data syncing to your Klaviyo account can be used to trigger and target automated flows.

 

For this solution, we will be focusing on the webhook action within a flow. Webhooks allow you to pass information to other applications, tools, and services.

 

In this case, the webhook action will send a request to plant a tree using a tree planting service.

 

While there are many API-based tree planting services that you can use (or are maybe already using), this article will focus on integrating with Treeapp.

 

Treeapp has built a Klaviyo integration that sends the positive impact of the profile back into Klaviyo for use within segmentation, loyalty and personalization.

 

As a summary, this solution will allow you to:

  1. Plant trees
  2. Encourage people to be aware of how shopping with your brand is helping to plant trees.
  3. Create loyalty tiers based on how many trees the customer has planted.
  4. Personalize Year in Review emails — Adding information like positive impact, trees planted and CO2 captured.

 

Why Plant Trees?

 

Tree planting is important for retailers for several reasons.

 

Firstly, planting trees absorbs carbon dioxide which can help brands contribute to their overall sustainability efforts.

 

Secondly, trees provide valuable ecosystem benefits, such as purifying air and water, mitigating soil erosion, and supporting biodiversity - all of which can enhance the environmental and social well-being of the communities where retailers operate.

 

Thirdly, tree planting can be a way for retailers to engage with their customers and employees in environmental stewardship, and foster a sense of community, involvement, and brand loyalty.

 

Finally, supporting tree planting initiatives can align retailers with the growing trend of conscious consumerism, where customers prefer to support businesses that prioritize environmental and social responsibility.

 

Ingredients

  • thetreeapp.org account.
  • 1 Klaviyo flow containing a webhook action.
  • A desire to address the impact of your business and promote a more sustainable choice to your consumers.

 

How it works

 

There are two parts to this integration.

  1. Planting trees via a Klaviyo flow
    Trees can be planted using a Klaviyo webhook action. This action will send a POST request to the Treeapp API to plant a tree on behalf of the profile using the /klaviyo/usage-record endpoint.

    This plant-tree request will include the Klaviyo ID of the profile along with the number of trees that are requested to be planted.
     
  2. Treeapp updates Klaviyo every time a profile plants a tree with a Treeapp Impact Update event.
    Once Treeapp receives and successfully processes the Plant Tree request, an event is sent to Klaviyo acknowledging this update.


This event contains the following details:

"trees_paid": <trees-paid>
"trees_unpaid": <trees-unpaid>,
"trees_total": <trees-total>,
"carbon_credits_paid": <carbon-credits-paid>
"carbon_credits_unpaid": <carbon-credits-unpaid>,
"carbon_credits_total": <carbon-credits-total>,
"carbon_dioxide_absorbed_paid": <carbon-dioxide-absorbed-paid>
"carbon_dioxide_absorbed_unpaid": <carbon-dioxide-absorbed-unpaid>,
"carbon_dioxide_absorbed_total": <carbon-dioxide-absorbed-total>,
"land_restored_paid": <land-restored-paid>,
"land_restored_unpaid": <land-restored-unpaid>,
"land_restored_total": <land-restored-total>,
"workdays_created_paid": <workdays-created-paid>,
"workdays_created_unpaid": <workdays-created-unpaid>,
"workdays_created_total": <workdays-created-total>

These values are sent as ‘top-level’ events so they can be used for segmentation, filtering, and conditional logic.

 

In addition, these values are also stored as custom profile properties, and can be used for segmentation, conditional logic, and within campaigns and flows (outside of those triggered by the event).

 

These instructions are specific to the Treeapp integration, but the Tree Planting flow can be used with any tree planting API service that supports HTTP POST requests.
 

The Treeapp integration unlocks additional functionality to store the positive impact within the profile for segmentation purposes.
 

Enable the Klaviyo Integration
 

Generate a Treeapp API Key

To obtain an API key:

  1. Go to https://www.thetreeapp.org/business/
  2. Sign up for a Treeapp business account
  3. Go to the settings page, click “Add a new API key” and enter your payment information and then click “Save”
  4. There you go! Now you should see an API key under the API Keys section which you’ll need to copy later
     

Add the Klaviyo integration to Treeapp

Treeapp has built a Klaviyo integration that will update Klaviyo profiles with live positive impact values whenever a profile triggers a Plant Tree action.
 

The Treeapp integration needs to be enabled by making an API call. This can be done via the following CURL request, replacing the keys with the relevant Treeapp API key and Klaviyo Public key (note the \ ends will need to be ^ for Windows devices), click here to learn more:
 

curl --location 'https://api.thetreeapp.org/v1/klaviyo/integrations' \
--header 'X-Treeapp-Api-Key: <your-treeapp-api-key>' \
--header 'Content-Type: application/json' \
--data '{ "secret": "<your-klaviyo-public-api-key>" }'

 

Plant a Tree Flow

 

Once you have the API key, all you need to do now is:
 

a) Create a Klaviyo Flow where you would like to plant a tree

For example, if you would like to plant a tree for every purchase, create a flow with the Placed Order trigger:
 


b) Set the conditions under which a tree will be planted

For example, plant if the order amount is greater than £20.


c) Create a Webhook action

Drop in the webhook action into the flow.


Webhooks allow your application to pass information to or “call” other applications, tools, and servers via HTTP request.
 

Webhooks send information about an event that has occurred (e.g. an order placed, a new customer subscribed, etc). Webhooks can tell your system that an event has happened or to notify you of that event.

The webhook activity in a Klaviyo flow



Add the Treeapp API endpoint:
https://api.thetreeapp.org/v1/klaviyo/usage-records
 

Add the following header:
X-Treeapp-Api-Key: <API_KEY_HERE>
 

Update the webhook body as follows:

{
"quantity": 1,
"profile_id": "{{person.KlaviyoID}}"
}


In this example, we are planting 1 tree per order, but with some simple Django logic, this can be adjusted to support a fraction of the order value.
 

For example, to plant a tree for every £20 spent, plant 1 tree. The following Django will take the $value from the Klaviyo event, divide by 20, round the value down, and convert to an integer:

{
"quantity": {{ event|lookup:'$value'|divide:20|round_down|floatformat:"0"}},
"profile_id": "{{person.KlaviyoID}}"
}


The configuration should look similar to this:


Save your flow
The flow is now ready for use. Save it and make it live!


Incentivise Tree Planting Behaviour

Many retailers say that they plant a tree for every purchase, but people are eager to know how many trees they have contributed to planting personally. With the Treeapp integration, the positive impact is sent to Klaviyo in real time as an event and as custom profile properties.
 

Here are a couple of suggested solutions on how you can promote your consumers’ ethical shopping choice


1. Trees-Planted Loyalty Tier Segmentation
 

Using Segmentation, you can quickly identify which profiles have made the most positive impact on your tree-planting efforts. These segments can then be used for loyalty flows and campaigns.

 

In this example, we can see how to create a segment of profiles the reach various tree-planting statuses and reward them for their positive impact.
 

  • VIP Tree Planters Segment
    Your VIPs are considered those who have made the most positive impact on your tree planting efforts. In this example, we’re defining VIP as those who have contributed to planting at least 50 trees.

    As a reward, you could offer VIPs with a 20% discount on their next purchase.

    To configure this segment, you can use the following definition:

    Properties about someone: trees_total is greater than 50 (number)
    • Flow

      The reward flow can then be configured to use this segment as a trigger condition. Whenever someone reaches the threshold to join a VIP Tree Planters segment, the flow will then be triggered. The Flow will have the following trigger:
      Triggered upon joining VIP Tree Planters segment
       

  • Gold Tree Planters Segment

    Your Gold Tree Planters are those who have made a significant positive impact in planting trees, but have not yet reached your VIP status. Using a flow triggered by this segment, you could remind the profile the positive impact that they have contributed to, and that they are close to reaching VIP status with its rewards/perks that they can receive for doing so.
     

    • Segment

      To configure this segment, you can use the following definition:
      Properties about someone: trees_total is greater than 20 (number)
      AND
      Properties about someone: trees_total is less than 50(number)

       

    • Flow

      The reward flow can then be configured to use this segment as a trigger condition. Whenever someone reaches the threshold to join a Gold Tree Planters segment, the flow will then be triggered. The Flow will have the following trigger:
      Triggered upon joining Gold Tree Planters segment

 

2. My Positive Impact — Year In Review Email Flow
 

Year in Review emails allow you to send your customers a highlight of the positive impact that they have made.

These recurring emails are very simple to configure within Klaviyo, and can be triggered on an annual (or monthly) basis based upon when they were created (or other custom profile property).
 

To get started, create a flow with a Date trigger condition, and set this to annual:


It is also highly recommended that you add a trigger condition on the flow to only trigger if they have planted at least 1 tree.
 

Set the trigger condition of the flow as follows:

Properties about someone: trees_total is greater than 0 (number)
 

Next, you can build your email template.
 

Within the template, you will have access to the following profile properties:

  • trees_paid
  • trees_unpaid
  • trees_total
  • carbon_credits_paid
  • carbon_credits_unpaid
  • carbon_credits_total
  • carbon_ dioxide_ absorbed_paid
  • carbon_dioxide_absorbed_unpaid
  • carbon_dioxide_absorbed_total
  • land_restored_paid
  • land_restored_unpaid
  • land_restored_total
  • workdays_created_paid
  • workdays_created_unpaid
  • workdays_created_total
     

To use this values, you can add the following template tags:

You have planted {{ person.trees_total }} trees. This has resulted in {{ person.carbon_dioxide_absorbed_total }} CO2 to be absorbed and {{ person.land_restored_total }} acres of land restored.

3. Positive Impact Reminder Blocks
 

Klaviyo offers a great bit of functionality called universal content blocks. These are blocks that you can build and add logic to that can be quickly dropped into any email flow or campaign.

Here we will build a simple Positive Impact Reminder block that will display the number of trees that the profile has planted, if they are close, how many more they need to plant to achieve VIP status, and if they are VIP a reminder that they have 20% promotion code.
 

Step 1 - create a new template

Pick or build a template that has the branding and styling that you wish to utilize.
 

Step 2 - add a section to the template where you wish to build the universal content block.

By using a section, you can create a universal content block with multiple elements from the Klaviyo Drag and Drop editor:
 


Step 3 - add the content

For each message, add blocks to the section, and configure its content.
 


Step 4 - set the display conditions

For each content block, you should set the Display Options ‘Show/Hide Logic’
 

In these examples, I have set the values of the logic to:
 

Content:
You’re so close! Only {{ 50|floatsub:person.trees_total|floatformat:”0" }} more trees to plant before you become a Tree Planting VIP!

Show/Hide Logic:
person.trees_total > 20 and person.trees_total < 50
 

Content:
You’re one of our top tree planters! Great job!

Show/Hide Logic:
person.trees_total >= 50

Now for the section itself, only display the section to those who have planted at least 1 tree.

Show/Hide Logic:
person.trees_total > 0
 


Step 5 - save the section as a universal content block

When you’re happy with the section, you can save it as a universal content block by clicking on the ⭐️ icon when hovering over the section.
 


Once saved, you can then simply drag this saved block from the Universal tab in the editor window and add to any email template.
 

This is only the beginning!


We hope that these solutions will inspire you to try out your own ideas to promote conscious consumerism.


We’d love to see what you build, so please share your flows with us, and perhaps submit them for an Klaviyo award!


5 replies

Userlevel 2
Badge +4

Hi! Thanks for writing this all down, very useful to have it all in one place.

I’m trying to create a VIP Tree Planter segment but when I choose Properties About Someone, there is no trees_planted Dimension. What am I missing? Any help would be greatly appreciated.

Userlevel 7
Badge +36

Hi @Eleanor Shadow!

So glad to hear you’re giving this a shot!

 

This is likely because there has to be at least one profile with a trees_planted profile property value before you can create a segment with it. This is discussed in this thread here, as well:

 

Best,

Brian

Userlevel 2
Badge +4

Hi @Eleanor Shadow!

So glad to hear you’re giving this a shot!

 

This is likely because there has to be at least one profile with a trees_planted profile property value before you can create a segment with it. This is discussed in this thread here, as well:

 

Best,

Brian


Thanks for getting back to me, @Brian Turcotte ! Apologies for the late reply, I never got a notification for it…

I had a read of the thread you sent, but I’m unsure how to “ alleviate this by setting the form Live and filling the form out yourself with a test profile/email which would allow Klaviyo to recognize this property to create a dimension off of.” - Would I need to wait for someone to place an order high enough in value to trigger the system, so I can finally add the property value?

Userlevel 7
Badge +36

Hi @Eleanor Shadow!

Yes, it’s true that you won’t be able to add the property value to the segment rules until at least one profile in your account has the profile property. However, you don’t necessarily have to wait for someone else to create a high-enough order, as there are other ways to accomplish this.  

 

All you have to do is cookie yourself on your e-commerce store by navigating to your site on a different browser and entering your email somewhere (at a checkout, form, etc.), so that you create a new profile in your Klaviyo account. Then, you can add the trees_planted property to your profile by following the directions here:

 

Best,

Brian

Userlevel 2
Badge +4

Hi again, @Brian Turcotte 

 

Thanks so much! I’ve *finally* managed to create a custom property for the segmentation. Couldn’t have done it without your help.

 

Have a great weekend!

Eleanor

Reply