Using dynamic content coupon codes - Magento 2

Learn how to set up and insert dynamic coupon codes with Dotdigital and Magento 2.


Using coupon codes generated by an external dynamic content URL lets you include unique, single-use coupon codes within your email campaigns. It’s a great way to incentivise your contacts with coupon codes without the risk of the codes being shared and abused.

Sending campaigns with dynamic content coupon codes

We'd advise that you consider using send throttling for campaigns containing a dynamic coupon code. This will help to prevent performance issues with your site related to a large number of simultaneous requests to your servers.

If you're planning to send the campaign through an automated program which is likely to have large numbers of contacts enrolling at one time, you may want to consider using quantity splits and delay nodes to stagger the sends. To learn more, check out the articles Use quantity splits in programs and Add a delay node to a program.

1. Set up Cart price rules

First you need to set up cart price rules for your coupon code:

  1. In Magento 2, go to Marketing > Promotions > Cart Price Rules, then select Add New Rule.
  2. Under Rule information, enter a Rule name and Description for your rule.
  3. Switch the Active toggle to Yes.
  4. For Websites, choose the websites you want this code to be valid on.
  5. For Customer Groups, choose the customer groups you want to be able to use this code.
  6. Expand the Coupon drop-down menu, then select Specific Coupon.
  7. For Coupon code, select the Use Auto Generation checkbox.
  8. For Uses per Coupon and Uses per Customer, enter 1.
  9. If you have a promotion with a specific end date, choose a From and To date for your code.
    If you want the code to expire after so many days, leave this blank, and we can set an expiry later.
  10. Select Save and Continue Edit.


2. Generate a Dotdigital Coupon URL

In this step, you generate your coupon code URL to use in your campaign as external dynamic content. You must generate your Coupon code URL in one step. Saving at this point won't save any of your details.

To generate a coupon code URL:

  1. Under Cart price rules, select the rule you created in Step 1.
  2. Expand the Dotdigital Coupon URL Builder settings menu.
  3. Expand the Code Format drop-down menu, then choose Alphanumeric, Alphabetical, or Numeric.
  4. If you want, enter a Code Prefix or Code Suffix.
  5. If you want your code to expire, for Expires After (days), enter the number of days you want your code to expire after.
  6. Expand the Allow Resend drop-down menu, then choose Yes or No.
    • Yes - allows a Resend using the same code.
    • No - Generates a new code with a Resend.
  7. If you selected Yes in the previous step, expand the Cancel Send if Used drop-down menu, then choose Yes or No.
    • Yes - Cancels the send if the coupon code has been used, or regenerates a code if it has expired.
    • No - The latest generated coupon code is displayed.
  8. Leave your browser tab open and do not Save at this point, or you will lose your settings.
  9. In the Coupon Codes URL box, select the URL to copy it to your clipboard.
    Paste and store the URL in notepad or a similar application as you need it in the next step.


3. Add a dynamic coupon code to an email campaign

In this step, you need to add the dynamic coupon code to your email campaign.

To add an external dynamic coupon code to your email campaign:

  1. In Dotdigital, go to Email > Campaigns > All campaigns.
  2. Edit an existing campaign or create a new campaign.
    To learn how, check out Create, edit, test, and send an email campaign.
  3. In EasyEditor, from the Build > Building blocks > Tools menu, drag the External dynamic content block onto the EasyEditor canvas.
  4. Select the External dynamic content block to open the left-side settings.
  5. For Name, enter a name for the block.
  6. For Address, paste the Coupon Codes URL you generated and copied earlier.
  7. Finish editing your campaign and save ready for sending.


Style your coupon codes

You can customise the font and style of the coupon codes you generate. To learn how, check out the article Dynamic content: Styling options.

Did you find this article helpful?

Can we help?

Thanks for using Dotdigital. If you need more help or support, then contact our support team.