Skip to main content
Julie Hayes
Klaviyo Alum
September 21, 2020
Tutorial

How to Add Dynamic and Static Coupons to Emails

  • September 21, 2020
  • 18 replies
  • 18072 views

TL;DR: There are two coupon types in Klaviyo emails: static (same code for everyone) and dynamic (unique code per person). Static codes go directly into a text block. Dynamic codes require setting up a coupon in Klaviyo first, then inserting via a Coupon block or the {% coupon_code 'CouponName' %} tag.

Depending on the type of message you're sending, there are two different ways to add a link to an email in order to automatically include a coupon to the recipients cart. For a dynamic coupon, such as in an abandoned cart flow, the structure of your link will look like this:

https://www.mysite.com/STOREFRONT_ID/checkouts/{{ event.extra.token }}?discount={% coupon_code 'NAME_OF_YOUR_COUPON' %}

If you're using a static coupon, then instead of appearing like

{% coupon_code 'NAME_OF_YOUR_COUPON' %}

it will just be:

?discount=NAME_OF_YOUR_COUPON.

Head to this article on Add a Link that Automatically Applies a Unique Coupon Code at Checkout for more information.

For any other flow or campaign message, you will need to point to your website, add the coupon and redirect all within the same link. That would look like this:

mysite.com/discount/{% coupon_code 'your_code' %}?redirect=/new-path

Again, if you're not using a dynamic code, you can replace that tag with just your static coupon's name. 

mysite.com/discount/{% coupon_code 'your_code' %}?redirect=/new-path

 

Setting up dynamic/unique coupons by platform

Before you can insert a dynamic coupon, you need codes in Klaviyo:

  • Shopify, Magento, WooCommerce, PrestaShop: Create unique coupons directly in Klaviyo - codes auto-generate for flows. Campaigns require pre-generated codes.
  • Other platforms: Generate codes externally → go to Content → Coupons → Uploaded Coupons → Create Uploaded Coupon → use the three-dot menu → Add Codes (CSV with a "Coupon" column header).

Two ways to insert a dynamic coupon into your email

  1. Coupon block (drag-and-drop): Drag the Coupon block into your email → click + → select your coupon. Only coupons with available, unexpired codes will appear. The code assigns when the email renders. Avoid adding excessive coupon blocks in a single email.
  2. Template tag in a text block: Add {% coupon_code 'CouponName' %} using the exact coupon name as it appears in Klaviyo.

Testing and sending tips

  • In-app preview shows COUPON_NAME-PREVIEW - this is expected. Real codes only generate on live sends or inbox previews.
  • Campaigns: Ensure you have enough codes before scheduling - Klaviyo will block the send if available codes are fewer than recipients.
  • Flows: Klaviyo-generated codes (e.g. Shopify) replenish automatically. Uploaded codes require you to manually keep inventory stocked.
This topic has been closed for replies.

18 replies

retention
Partner - Platinum
2025 Champion
September 21, 2020

Great summary on dynamic coupons for Shopify!  A few things to add that might be helpful:

  • You can use the link for images, buttons, inline links (within a text block).  Pretty much anywhere that you can add a URL.
  • For campaign/flow (not cart abandonment) emails, you can couple this with the Shopify “Add an item/variant to Cart” permalink in the redirect to apply the coupon, and add something to their cart in one go.  See this for more info: https://shopify.dev/tutorials/build-a-sales-channel-with-cart-permalinks
  • And like all Klaviyo Dynamic Coupon Codes, you can use the same specified coupon for subsequent emails and it will “resuse” the same previously generated code (as long as the code has not expired).
Joseph Hsieh // retentioncommerce.com // X: @retention
cassy.lee
Klaviyo Alum
September 22, 2020

@retention Thanks Joseph for the additional tips here, and adding more color to dynamic coupon codes!

katharling
Contributor I
Contributor I
September 22, 2020

Big fan of the dynamic coupon feature! 

A potentially niche but related questions: could I use this feature to generate unique codes that are not associated with a discount? We would like to set it up an auto response email that customers receive when they sign up for our lifetime warranty so that each customer gets a unique warranty code that is required down the line should they ever need to make a warranty claim. Obviously we don’t want there to be a discount linked to this random collection of letters/numbers. Is there another way to have a unique code generated in emails? 

Thanks in advance!

 

cassy.lee
Klaviyo Alum
September 22, 2020

Hi @katharling 

This is a great question, and I love that you offer lifetime warranty on your products. Unfortunately, the built-in Shopify coupon feature would not be the best fit for generating unique codes for warranty, but you could upload unique coupon codes to Klaviyo and reference them in your campaign or flow emails. This isn’t an automatically enabled feature, so if you want to send me a direct message (DM), I can work with you to get this switched on. 

You can read more about Uploading Unique Coupon Codes here. A key thing to note is that you’ll need to generate the list of warranty codes ahead of time, upload them via the enabled feature mentioned above, and manage the number of available codes on your own or through your point of sale software. 

Hope this was helpful and thanks again for being a part of our community!

Contributor II
January 20, 2022

Hello,

I have a questions on the coupon code functionality.
I’m setting up a Welcome Email, which will contain a coupon code for new subscribers.
The coupon codes have a single usage and I will import them in the “Coupons” section of Klaviyo.
Afterwards I will insert in my email the variable {% coupon_code 'CouponName'%} in order to insert the coupon in the mail.
Since the coupon codes might finish at some point I would like to insert a fallback value with a coupon name that has unlimited usage in order to be sure that the Welcome mail always goes out with a valid coupon. Is there a way to insert this fallback value?
I’ve tried using this: {% coupon_code 'CouponName' % | default:'CODENAME'} but I receive an error message so I guess it’s not the correct way.


Hope someone can help me out!
Thanks in advance

Aline

David To
Klaviyo Employee
Klaviyo Employee
January 20, 2022

Hey @Aline,

Great question! At present there would not be a way to apply a fallback coupon code as part of your dynamic coupon code syntax. The |default:'' filter is applicable only to properties such as first name or last name. Whereas coupon codes are seen more so similar to an event. 

If you were using either the Shopify or Magento integrations, you wouldn’t actually have to upload your coupons or use a fallback coupon. With these integrations, unique coupons will be generated automatically so you wouldn’t have to worry about running out of viable coupons!

In the event you were using WooCommerce or BigCommerce, since there wouldn’t be a method to use a fallback coupon, I would suggest either setting up a routine to upload your coupons or use a static coupon. 

You can learn more about using coupons within Klaviyo from the following Help Center articles based on which integration you are using:

 

I hope this helps!

David

Contributor I
March 28, 2022

Hey i tried to add Link that Applies a Unique Coupon Code at Checkout for Shopify in order to take people to the checkout page with an already applied discount code. So i generated the link following the instructions in Help section and changed my site with my website url, i put the storefront ID as well and insert the exact coupon name  https://www.mysite.com/STOREFRONT_ID/checkouts/{{ event.extra.token }}?discount={% coupon_code 'NAME_OF_YOUR_COUPON' %} and i pasted the link into a CTA button in a Abandoned Checkout email Flow but it didnt work and bring me to a page that says cannot find the page. What am i missing and how to do it correctly?

 

David To
Klaviyo Employee
Klaviyo Employee
March 28, 2022

Hey @Velin Petrov,

Are you by chance formulating that dynamic URL somewhere else rather than replacing those website URL, storefront ID, and coupon code fields from the base URL within the link URL field of the button? If so, then I suspect when copying the finalized URL back into the link URL field, some additional formatting or encoding may be happening which would break the URL. Oftentimes it’s best practice so paste in the base code of https://www.mysite.com/STOREFRONT_ID/checkouts/{{ event.extra.token }}?discount={% coupon_code 'NAME_OF_YOUR_COUPON' %} to your link URL field and manually replace the website URL, storefront ID, and coupon code values. 

You’ll know your URL creation is successful when you preview the email and you’re brought back to the checkout page of the user you’re previewing as with the discount field displaying as NAME_OF_YOUR_COUPON-PREVIEW with an error that states “Enter a valid discount code” like the example below:

Keep in mind you’ll also want to preview as a user who hasn’t fully completed their purchase. Since previewing will provide all users and events who have triggered the Started Checkout event, when previewing as someone who has already completed their order, their checkout page would not longer be successful. 

If you’re still having trouble, I would suggest reaching out to our colleagues on the Support team to investigate further to see what the issue may be. If you do find a solution, please feel free to share back in this thread so other Community members can learn of your solution as well!

David

Contributor I
March 29, 2022

Thank you so much @David To. I did exactly what you said i pasted the base code in the URL field and than manually entered the info. After that i previewed it with a customer than i know 100% didnt complete the purchase and the link took me straight to the checkout page with a text on top of the promo code field that says ‘discount code isn’t valid for the items in your cart’. I assume tha means it is successful and i can launch it right? 

Velin

David To
Klaviyo Employee
Klaviyo Employee
March 29, 2022

Hey @Velin Petrov,

Sounds like you’re on the right track and my initial assumption of some additional formatting or encoding being present was the issue.

I would just make sure that for the coupon field, in addition to the “Enter a valid discount code” error that the coupon field reads “NAME_OF_YOUR_COUPON-PREVIEW”. What you’re really looking for is the “-PREVIEW” message proceeding the name of your coupon. This would mean that the dynamic coupon variable was understood correctly. Because this is only a preview, a live coupon wouldn’t be generated, but the “-PREVIEW” message would indicate that it’s being understood correctly. 

David