Tutorial

How to Add Dynamic and Static Coupons to Emails

  • 21 September 2020
  • 18 replies
  • 9952 views

Userlevel 4
Badge +5

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

 

 


18 replies

Userlevel 7
Badge +57

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).
Userlevel 6
Badge +9

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

Badge +1

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!

 

Userlevel 6
Badge +9

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!

Badge +3

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

Userlevel 7
Badge +60

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

Badge +5

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?

 

Userlevel 7
Badge +60

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

Badge +5

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

Userlevel 7
Badge +60

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

Badge

@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

Userlevel 7
Badge +60

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

Userlevel 1
Badge +2

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?

Userlevel 7
Badge +60

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

Userlevel 1
Badge +2

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?

Userlevel 7
Badge +60

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

Userlevel 1
Badge +2

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

Userlevel 7
Badge +60

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

Reply