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

Contributor I
July 3, 2022

@Velin Petrov and everybody

I have the solution. I had the same issue so I proved it in different ways, and it works when I change “https” for “http” and taking off “www.”. So try this way:

 

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

 

Let me know if works to you.

 

Rodrigo 

Adseller

David To
Klaviyo Employee
Klaviyo Employee
July 5, 2022

Hey @Adseller,

I know your intentions mean well, however I would strongly advise against using an HTTP protocol - especially for a link taking users back to their checkout page. Unlike HTTP links, HTTPS sites are SSL encrypted for better security. Using HTTPS is essential for sites collecting personal information such as credit card details, etc. 

You can learn more of these difference between these two protocols from CloudFlare’s blog: Why is HTTP not secure? | HTTP vs. HTTPS

David

Lucia937
Active Contributor IV
Active Contributor IV
November 1, 2022

HI @David To I’m having the same issue as people above. I pasted this into the URL field for my button 

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

and manually replaced “mysite” with my sites name and “your_code” with the coupon codes’ name.

It’s an welcome email flow and the coupon code is a dynamic code with an expiration date, generated on Klaviyo-not uploaded. The error message i get when previewing and clicking on the link is “sorry, that page isnt actually there”

when I send that email to one of my email adresses, I can either not even click the link or it shows 404 page not found

I’ve also been trying with literally every other link in any of the related klaviyo articles...

For example with this one 

  1. mysite.com/discount/{% coupon_code 'CouponName' %}

I do end up on my webpage but the code is not applied at checkout….. 

 

The button and link does however work with static coupon codes….(generated on shopify)

Any ideas what I might be doing wrong?

David To
Klaviyo Employee
Klaviyo Employee
November 1, 2022

Hey @Lucia937,

You mentioned you replaced the “mysite” portion of the code with your site’s name and “your_code” with the coupon codes’ name. However, did you go ahead and update the “new-path” portion?

So for example, if you wanted that coupon to apply and redirect users to a general collections page it would be something like mysite.com/discount/{% coupon_code 'your_code' %}?redirect=//collections/all. This would all be dependent on the page you want to redirect users to. 

This is also explained in our How to Add Link that Applies a Coupon Code to a Shopify Cart Help Center article. 

David

Lucia937
Active Contributor IV
Active Contributor IV
November 1, 2022

Hi @David To yes, I did update that part as well. I still get the same error. It’s the same wether I use that link or something shorter like

mysite.com/discount/{% coupon_code 'CouponName' %}

 

I’ve read that article and tried all links that were suggested there, I also read through https://help.klaviyo.com/hc/en-us/articles/115006155388-Unique-Coupon-Codes-for-Shopify 

https://help.klaviyo.com/hc/en-us/articles/360018227032-How-to-Add-a-Link-that-Applies-a-Unique-Coupon-Code-at-Checkout

https://help.klaviyo.com/hc/en-us/articles/115005084727-Getting-started-with-coupon-codes-in-Klaviyo

https://help.klaviyo.com/hc/en-us/articles/115006155388

and tried the troubleshooting suggestions there too

Like I said, I dont have that issue with static coupon codes, could the coupon codes itself be the issue?

David To
Klaviyo Employee
Klaviyo Employee
November 1, 2022

Hey @Lucia937,

That is an odd behavior. Can you explain how you’re testing? 

For example, what happens when you actually manually build the URL while including the discount code that was issued to you in your test rather than clicking on the dynamically created link? 

After navigating to the manually built URL, if you were still getting a 404 error, this seems to indicate something related to how your site is parsing the URL. In a case like this you’ll want to work with your developer to investigate this behavior further. 

If the manually built URL works successfully, then this would point to an issue with your template. In my experience this could be as simple as having latent formatting in the backend if you were copy and pasting.

David

Lucia937
Active Contributor IV
Active Contributor IV
November 2, 2022

Hi @David To 

 

So far I tested it by adding the link in my email template (in the button) and then clicking on preview and test and trying whether the button works and also send the email to one of my email adresses and tried clicking the button there.

By manually building, do you mean typing the URL into the web-browser bar? Because yes, when I do that I still get an error message, actually 400 “bad request” instead of 404

David To
Klaviyo Employee
Klaviyo Employee
November 3, 2022

Hey @Lucia937,

I think one of the issues you may be having could be due to how you’re testing the coupon. Of the two preview options, only the method of sending it to your email address will generate a live coupon code. 

However, this does also mean that you’ll need to have generated enough coupon codes before sending the preview email. Else, you wouldn’t receive a live code, but rather one that is the name of your coupon with the -”PREVIEW” suffix. 

In case you missed it, this was mentioned in several locations in our How to create unique coupon codes for Shopify Help Center article:

When emails are sent out, this variable will be dynamically replaced with a unique discount code for each recipient. When you preview the email directly in Klaviyo, you will not see a unique coupon code populate.

However, if you send a preview email to yourself or a member of your team, a live code will be generated. For this reason, it's important to ensure that you have sufficient codes in your account. Otherwise, you will not see a unique code and you will need to add codes before sending a preview with a live coupon code.

Which, not having a live coupon code as part of your dynamic URL could impact how the link functions. 

After making sure you’re testing with a live coupon, if the error still persists, I would suggest working alongside your developer or speaking with some of our wonderful Support colleagues to see if they can spot something that was missed.

David