---
title: "How to Integrate Discount Codes/Discounts Using URL Parameters"
url: "https://support.acendy.com/en/article/how-to-integrate-discount-codes-discounts-using-url-parameters"
language: "en"
last_updated: "2026-05-12T08:38:17.041Z"
---

# How to Integrate Discount Codes/Discounts Using URL Parameters

Allows you to automatically apply a coupon code or discount when customers enter the store from a specific URL

### **Introduction**

This guide lets administrators  integrate unique discount codes or discounts into customer shopping experiences seamlessly. By employing URL parameters, you can offer exclusive discounts to users redirected from partner sites, enhancing their journey and boosting engagement.

### **Implementation Guide**

**Prepare Partner Links**

-   Construct your partner links to include a **`coupon`** parameter in the URL. For example:   
    [`https://www.yourshop.com/landing-page?coupon=EXCLUSIVE20`](https://www.yourshop.com/landing-page?coupon=EXCLUSIVE20)

**Add Custom JavaScript**

Insert a JavaScript function to capture and apply the discount code from the URL.

#### On legacy templates: 

Implement this in the custom JavaScript settings from the admin panel under /kontrollpanel/custom\_javascript.php:

```
function customAddDiscountCode() {
      const urlParams = new URLSearchParams(window.location.search);
      const code = urlParams.get("coupon");
      if (code) {
        fetch(`/ajax.php?ajaxfunc=add_discount_code&discount_code=${encodeURIComponent(code)}`)
          .catch(error => console.error('Error:', error));
      }
    }
    document.addEventListener('DOMContentLoaded', customAddDiscountCode);
```

  

#### On new design-builder:

On the new design-builder, there are two ways of adding the script. You can add it in the same way as for the "Legacy templates" or you can do the following method. **However, this approach will stop all custom scripts under** `/kontrollpanel/custom_javascript.php` **from running. So make sure that all scripts are moved to the new location before this approach is chosen.** 

Within the design builder, locate **CSS / Javascript** under **Settings** and expand **Advanced Settings.** Click on the **Open editor** and insert the code. 

-   This script will extract the **`coupon`** parameter value and apply it if it's valid.

**NOTE: This code can also add a discount directly, in that case the URL will be** [`https://www.yourshop.com/landing-page?discount=EXCLUSIVE20`](https://www.yourshop.com/landing-page?discount=EXCLUSIVE20) **and the javascript that needs to be added is:**

```
function customAddDiscountCode() {
      const urlParams = new URLSearchParams(window.location.search);
      const code = urlParams.get("discount");
      if (code) {
        fetch(`/ajax.php?ajaxfunc=add_discount_code&discount_code=${encodeURIComponent(code)}`)
          .catch(error => console.error('Error:', error));
      }
    }
    document.addEventListener('DOMContentLoaded', customAddDiscountCode);
```

  

**Administrator Access**

-   This feature is accessible to all administrators through the control panel. You can implement and manage it without requiring in-depth programming skills.

**Setting Up Campaigns**

-   Ensure that all coupon codes are properly set up in your control panel. They need to be linked to valid offer to work.

**Testing**

-   Conduct thorough testing by accessing the store URLs configured with different coupon parameters to confirm that the codes are appropriately applied to the carts or checkout sessions.
