Skip to main content

    Customize your templates and content

    Course overview
    Lesson
    4 min read

    Apply unique coupon codes to messages dynamically

    Add unique coupon codes to sign-up forms, emails, and text messages to create a sense of urgency and drive more purchases.

    Generate your codes

    In order to distribute discount codes, you’ll first need to generate the codes within your ecommerce platform. When you’re using a static discount code, this process is very simple: create the code within your ecomm platform, and then type the code into the message where you want to display it. Since static codes are the same for everyone, no other steps need to be taken in Klaviyo.

    For unique codes, the code creation process has a few more steps and will vary based on your ecommerce integration. Choose the setup guide that best fits your situation:

    Reward your customers with unique codes

    Klaviyo gives you the flexibility to reward customers with unique coupon codes across many touchpoints. To add a unique coupon code to any of the instances mentioned below, you’ll need to use this template tag:

    {% coupon_code 'CouponName' %}

    Replace CouponName with the exact name of the coupon that you want to pull as it is shown in Klaviyo. This will insert the desired coupon into your text. Let’s explore some examples of where you may choose to apply a unique discount code.

    Form success message

    Reward a customer for interacting with a form without making them leave the site to check their messages. Unique coupon codes can be placed in the success message of a sign-up form as a reward for successfully completing the form. The coupon block has easy copy functionality, where users can click directly on the code to copy it to their clipboard and then paste it into their cart at checkout.

    Email or text message campaign

    Include a discount code in an email or text messagecampaign to incentivize purchases. When using unique coupon codes in campaigns, you’ll need to make sure that you have generated enough unique codes to cover the total number of recipients. If you don’t have enough codes, Klaviyo will flag this as an error that you must fix before sending the campaign.

    Flow message

    Include a unique coupon code in a flow, like welcome series or abandoned cart, to incentivize action. Note that if you are not using Shopify or Magento (1.x or 2), you will need to upload more unique codes on a regular basis. Since flows are sent on a recipient-by-recipient basis, Klaviyo cannot check to make sure that enough codes are available.

    Barcode within an email

    If you have a physical retail location, you may want to display your discount codes as barcodes that can be scanned in-store. Klaviyo allows you to render dynamic codes as barcodes within emails by including the following template tag:

    {% barcode_code 'CouponName' height=100 width=200 %}

    For more exact steps on how to set this up and ensure that it works with your POS system, follow the guidance within our Getting started with coupon codes help guide.

    Best practices for managing unique coupon codes

    Upload codes at least 1 day before you plan to use them

    For all integrations except for Shopify and Magento

    If you need to upload thousands of unique codes to Klaviyo, the upload may take a while to complete. It is a best practice to upload your coupon codes 1 or 2 days before deploying any sort of communication using that code.

    Replenish your codes on a regular basis

    For all integrations except for Shopify and Magento

    If you use unique codes in your sign-up forms or flows, monitor your Klaviyo account to make sure that there are enough unique coupon codes available for use. Since unique codes do not generate automatically for non-Shopify and non-Magento users, you should set a reminder for yourself to upload a new set of coupon codes every 30 or 60 days.

    Preview messages to make sure codes are displaying properly

    Always use the Preview & test function when drafting campaigns or flows to make sure that you’ve formatted the coupon template tag correctly. In the preview rendering, Klaviyo will not show a real discount code because this would actually use up one of your unique codes. Instead, you should see the name of the coupon with the word PREVIEW affixed to the end.

    Apply unique coupon codes to messages dynamically