---
updatedAt: 2026-07-15T19:10:41.000Z
agentTools:
  siteIndex: https://docs.affirm.com/llms.txt
  projectIndex: https://docs.affirm.com/developers/llms.txt
---

# Set Up Promotional Messaging

Integrate Affirm's promotional messaging to showcase flexible financing options, increase conversion rates, and enhance customer experience. This guide walks you through placement, setup, and configuration.

## Prerequisites

* Review [Affirm Marketing Compliance Guidelines](https://businesshub.affirm.com/hc/en-us/articles/5997808392724-Getting-Started-With-Affirm-Compliance-and-Guidelines).
* Determine where to display Affirm messaging on your site (e.g., product, category, cart, and homepage).
* Confirm your public API keys are available, you can access them in the [Affirm Merchant Portal](https://affirm.com/dashboard/#/apikeys). You’ll need this to configure Affirm.js and API requests.
* (*Optional*) Work with your Client Success Manager to customize [co-branded visuals](https://businesshub.affirm.com/hc/en-us/articles/12497969065620-How-can-I-co-brand-promotional-messaging-modals) or prequalification settings.

## Steps

### 1. Add Affirm.js (AFJS)

Embed the following snippet into the `<head>` section of your site’s global template:

<Recipe slug="embed-affirmjs" title="Embed Affirm.js" />

```javascript AFJS
<script>
var _affirm_config = {
		public_api_key: "YOUR_PUBLIC_API_KEY", /* replace with public api key */
		script: "https://cdn1-sandbox.affirm.com/js/v2/affirm.js",
		locale: "en_US",
		country_code: "USA",
	};

(function(m,g,n,d,a,e,h,c){var b=m[n]||{},k=document.createElement(e),p=document.getElementsByTagName(e)[0],l=function(a,b,c){return function(){a[b]._.push([c,arguments])}};b[d]=l(b,d,"set");var f=b[d];b[a]={};b[a]._=[];f._=[];b._=[];b[a][h]=l(b,a,h);b[c]=function(){b._.push([h,arguments])};a=0;for(c="set add save post open empty reset on off trigger ready setProduct".split(" ");a<c.length;a++)f[c[a]]=l(b,d,c[a]);a=0;for(c=["get","token","url","items"];a<c.length;a++)f[c[a]]=function(){};k.async=
  !0;k.src=g[e];p.parentNode.insertBefore(k,p);delete g[e];f(g);m[n]=b})(window,_affirm_config,"affirm","checkout","ui","script","ready","jsReady");
</script>
```

### 2. Insert HTML Tags Where Messaging Will Appear

Place Affirm HTML components on relevant pages. Examples:

```html Promotional Messaging HTML Tags
<!-- Product Page -->
<p class="affirm-as-low-as" data-page-type="product" data-amount="50000"></p>

<!-- Cart Page -->
<p class="affirm-as-low-as" data-page-type="cart" data-amount="50000"></p>

<!-- Homepage Modal -->
<a class="affirm-site-modal" data-page-type="homepage">Learn more</a>
```

Use the `data-amount` in cents (e.g., 100.00 = 10000) and `data-page-type` values that correspond to the location.

#### Full HTML Example

The following example shows how to include Affirm.js and the necessary HTML tags on a product detail page:

```html Promotional Messaging Full HTML Example
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Product Detail Page</title>
  <link rel="stylesheet" href="styles.css">
  <!-- Affirm -->
<script>
 _affirm_config = {
   public_api_key:  "YOUR_PUBLIC_KEY",
   script:          "https://cdn1.affirm.com/js/v2/affirm.js",
   locale:          "en_US",
   country_code:    "USA"
 };
 (function(l,g,m,e,a,f,b){var d,c=l[m]||{},h=document.createElement(f),n=document.getElementsByTagName(f)[0],k=function(a,b,c){return function(){a[b]._.push([c,arguments])}};c[e]=k(c,e,"set");d=c[e];c[a]={};c[a]._=[];d._=[];c[a][b]=k(c,a,b);a=0;for(b="set add save post open empty reset on off trigger ready setProduct".split(" ");a<b.length;a++)d[b[a]]=k(c,e,b[a]);a=0;for(b=["get","token","url","items"];a<b.length;a++)d[b[a]]=function(){};h.async=!0;h.src=g[f];n.parentNode.insertBefore(h,n);delete g[f];d(g);l[m]=c})(window,_affirm_config,"affirm","checkout","ui","script","ready");
</script>
<!-- End Affirm -->
</head>
<body>
  <header>
    <!-- Site Header -->
  </header>
  <main>
    <div class="product-detail">
      <img src="product-image.jpg" alt="Product Image">
      <h1>Product Name</h1>
      <p>Product Description</p>
      <p>Price: $100</p>

      <!-- Add promotional messaging below the product price -->
<div id="prices">
    <div id="buy-button">
      Buy Now
    </div>
    <div id="regular-price">
      $500.00
    </div>
    <p class="affirm-as-low-as" data-page-type="product" data-amount="50000"></p>
</div>
    </div>
  </main>
  <footer>
    <!-- Site Footer -->
  </footer>
</body>
</html>


```

#### Promotional Messaging Placement Examples

* **Banner**

<Image src="https://files.readme.io/10c2e92d55b4d68a701c60bf88bc702bff6d8c029cb7acfdf208fbb203406f07-Screenshot_2025-07-15_at_12.46.32_PM.png" alt="Simulated laptop and iphone screens showing Affirm's promotional messaging via banner." align="center" />

* **Products Page**

<Image src="https://files.readme.io/10c2e92d55b4d68a701c60bf88bc702bff6d8c029cb7acfdf208fbb203406f07-Screenshot_2025-07-15_at_12.46.32_PM.png" alt="Simulated laptop and iphone screens showing Affirm's promotional messaging via product page." align="center" />

* **Product Overview Page**

<Image src="https://files.readme.io/665a5d1ac57d90d65d9933617720c1da1ad763ebe77196e64ebf8b66dfeef175-Screenshot_2025-07-15_at_12.48.32_PM.png" alt="Simulated laptop and iphone screens showing Affirm's promotional messaging via product overview page." align="center" />

### 3. Add Code to Handle Price Changes

If product pricing on your site updates dynamically, such as when customers select different variants or adjust quantities, ensure that Affirm’s promotional messaging reflects the updated pricing. The following functions are covered in this section:

* Refresh UI
* Page Reload
* Price Update
* Detect Modal Close

#### Refresh UI

To keep messaging updated, add this refresh function into your price change callback function:

```javascript Promotional Messaging Refresh UI
affirm.ui.refresh();
```

#### Page Reload

If the product’s price or the Affirm promotional messaging display after the page loads, or if you included the previous refresh function statically on the page, wrap it in the affirm.ui.ready() callback function. Doing so ensures that the page calls the refresh function only after Affirm.js initializes.

```javascript Promotional Messaging Page Reload
affirm.ui.ready(function(){
    affirm.ui.refresh();
});
```

#### Price Update

When the price updates on your page, call the refresh function in the same callback function that handles your price change event. Add element IDs to promotional messaging components for easy access and modification of their attributes. Note that we use example ID names below.

```javascript Promotional Messaging Price Update
priceUpdateEventHandler(){
    changePriceHandler(newPrice);
}
 
function updateAffirmPromos(newPrice){
    //Update the wrapper elements' attributes in the DOM
    document.getElementById('affirmProductModal').setAttribute('data-amount',newPrice);
    document.getElementById('affirmLearnMore').setAttribute('data-amount',newPrice);
   
    //Call affirm.ui.refresh to re-render the promotional messaging components
    affirm.ui.refresh();
}
```

#### Detect Modal Close

When an education modal is closed (non-prequal), you can detect that event by using the following code:

```javascript Promotional Messaging Detect Modal Close
affirm.events.on('learnMore:close',function(){console.log('fired')});
```

### 4. Add Prequalification Messaging (*Optional*)

To give shoppers the option to check if they prequalify for Affirm financing, integrate As Low As (ALA) messaging. ALA placements automatically support prequalification modals when clicked and no separate integration is needed.

#### Prequalification Flow (New Customer)

<Image src="https://files.readme.io/7b037cc0d132f5b63aec6900d50e014812a80d6d7d0a0fc1ad127b5dbba2f07e-Prequal_Flow_2025_1.svg" alt="Simulated iphone screens showing the six steps of Affirm's new customer prequalification flow." align="center" />

#### Prequalification Flow (Existing Customer)

<Image src="https://files.readme.io/5dd9f7b13560731b04ed477586a25b7c9de8e1db9edb295958404ccd3d3f8e3b-Prequal_Flow_2025_2.svg" alt="Simulated iphone screens showing the six steps of Affirm's existing customer prequalification flow." align="center" width="700px" />

### 5. Test and Deploy

1. Confirm all Affirm components render correctly.
2. Switch your JS script from the sandbox to production (<https://cdn1.affirm.com/...>).
3. In the Affirm.js code you added to your site, replace `"YOUR_PUBLIC_KEY"` with your live key from the [Affirm Merchant Portal](https://affirm.com/dashboard/#/apikeys).
4. Validate functionality end-to-end before going live.

<Image src="https://files.readme.io/b4b3145a53e23463cdf5ca2e662d21a87d84767c58baae86f2b7d58745e175fe-Screenshot_2025-07-15_at_1.01.25_PM.png" alt="A simulated screen on a laptop displaying Affirm's promotional messaging on a prodcut page." align="center" width="600px" />

## What's Next?

* [Promos API](https://docs.affirm.com/developers/docs/promos-api-integration-overview)
* [Test and Go Live](https://docs.affirm.com/developers/docs/partner-test-and-go-live)
* [Marketing and Compliance](https://docs.affirm.com/developers/docs/email-marketing)
* [Manage Promotional Messaging Components](https://docs.affirm.com/developers/docs/manage-components)

<br />

# Sub pages

* [Promos API Integration Overview](https://docs.affirm.com/developers/docs/promos-api-integration-overview.md)

# Sibling pages

* [About Promotional Messaging and Prequalification](https://docs.affirm.com/developers/docs/about-promotional-messaging-and-prequalification.md)
* [Manage Promotional Messaging Components](https://docs.affirm.com/developers/docs/manage-components.md)
* [HTML Reference: Promotional Messaging](https://docs.affirm.com/developers/docs/html-reference-promotional-messaging.md)
* [About Google Tag Manager](https://docs.affirm.com/developers/docs/google-tag-manager.md)
* [Set Up Google Tag Manager](https://docs.affirm.com/developers/docs/set-up-google-tag-manager.md)
* [Marketing and Compliance](https://docs.affirm.com/developers/docs/email-marketing.md)