Automatic Shopify discount codes in Klaviyo.

Klaviyo integrations
Author:
Omar Lovert
published on:
,
| updated on:
27
February
,
2025

Overview

Note that this feature is only available for Klaviyo abandoned cart emails in combination with Shopify.

Adding a link that automatically applies a unique coupon code to a customer's cart at the checkout page makes it incredibly easy for a customer to click through and place an order. It's also possible to create a link that applies a coupon code to a customer's cart, but this method takes the shopper directly to the checkout page.

What's more, this works on all devices (cross-device) - this means that if a customer leaves a shopping cart on a desktop but receives your email on their mobile and clicks through here, their cart is also up to date here.

Create a unique coupon code

Before you can apply the code to a URL, you must create your coupon code under the tab Coupons. To do this, follow the instructions in this article.

Note that when you preview the email, you won't see a live coupon in the email. Instead, you'll see “Name_of_you_coupon-preview.” You must actually activate the flow to view a live code.

Add the discount URL to a template

When creating the URL, you must use the following format:

https://www.mijnwebsite.nl/STOREFRONT_ID/checkouts/ {{event.extra.token}}? discount= {% coupon_code 'NAME_OF_THE_COUPON'%}

This token reconstructs the checkout and is unique in every Started Checkout event in Klaviyo. You must replace “mywebsite” with your Shopify website URL, “STOREFRONT_ID” with your unique storefront ID, and “NAME_OF_THE_COUPON” with the coupon name (must match the name exactly - capitalization is important).

You can find your storefront ID by clicking on the event data for a Started Checkout event and grabbing the first part of a checkout_url.

First, navigate to your Analytics tab and select Checkout Started. Click here on the timestamp for one of the events.

2018-10-29_11-06-09.png

This opens the metadata associated with this event. After your website URL, you'll see the storefront ID associated with your account.

2018-10-29_11-07-20.png

After creating the token, you can insert it into your abandoned cart email template.

How to add a link that applies a discount code to a Shopify cart

By offering a discount to customers who decide to go back to your website and complete a purchase, you'll make it easier for them to apply the discount when they arrive there to take advantage of the discount and thus be able to complete their purchase quickly.

Create a discount code

In Shopify, first create a discount code or a monetary discount code based on the type of promotion you want to offer.

The code you create must be inserted as a parameter in a link or button in your emails. Once you've created this code, keep it handy as you continue to update your email template.

Follow the instructions in this article if you want to use dynamic code.

Apply a discount code and link to the checkout page

To achieve this functionality, you must add a parameter to a link or button. When your customer clicks the button, they are directed to the link and the discount is automatically applied to their next cart.

You can only add one discount code per email. You can use the same code in multiple places, but you can't use multiple codes.

You can add a discount to the checkout link in your email template.

Add a discount to the checkout link

To add a coupon code to a button, you can add a link that redirects back to your home page and automatically applies the discount to your customer's cart. We'll give you two options to achieve this with static coupon codes, and one option for a dynamic coupon code:

  1. For a static coupon code, format your link as follows:
    mysite.com/discount/couponname
    Replace here:
  • mysite.com with your website
  • CouponName with the static coupon name
  1. You can also format your link for a static coupon code like this:
    mysite.com/? discount=your_code
    Replace here
  • mysite.com through your website
  • your_code with your coupon code
  1. For a dynamic coupon code, add the following tag at the end of your website link:
    {{event.extra.checkout_url}} /&discount= {% coupon_code 'couponName'%}

If you your_code If you see, replace it with the discount code you created in Shopify. Here's an example of a link with a discount code added at the end:

mceclip0.png

Apply a discount code and link to another page on your site

In some cases, you may want to apply a discount code to a shopping session, but not directly link the customer back to their cart. Instead, you may want to send them to your home page or another page. In this case, the URL structure you would use is:

Replace here:

  • mysite.com through your website
  • your_code with your coupon code
  • new-path with the desired URL extension. For example, if you want to link someone to a specific page, do you use? redirect=/collections/mycollection

Apply a static discount code and link to another page on your site

You may want to apply a static discount code to a shopping session, but not directly link the customer back to their cart. Instead, you may want to send them to your home page or another page. In this case, the URL structure you would use is:

mysite.com/discount/couponname? redirect=/new-path

Replace here:

  • mysite.com through your website
  • CouponName with the static coupon name
  • new-path with the desired URL extension. For example, if you want to direct someone to a specific page, use

 

Troubleshooting

If you test this and see that the updated link doesn't apply your discount code correctly, you'll probably need to change the added parameter to start with “&” instead of “?”

Change your parameter to the one above and it should work - if not, please contact Klaviyo's Success Team.


Polaris Growth

Meer weten?

Neem contact op