Custom Promotional Messaging
Overview
This guide will review Affirm promotional messaging and tell you how to add it to your site.
The steps for adding Affirm promotional messaging are:
- Determine Affirm promotional messaging placement
- Add Affirm.js
- Create promotional messaging components
- Add code to handle price changes
- Test and set live
Sandbox development
We recommend adding and testing promotional messaging in your development environment connected to our sandbox. To connect your development environment to our sandbox, you'll need to do the following:
- Retrieve your sandbox API keys at https://sandbox.affirm.com/dashboard/#/apikeys to use in the Affirm.js embed code
- Use the script URL https://cdn1-sandbox.affirm.com in the Affirm.js embed code
1. Determine Affirm promotional messaging placement
If you’re integrating Affirm for the first time, you’ll need to go through a design process to determine where you want to include Affirm promotional messaging on your site and what the messaging should look like and say.
Please reach out to your Client Success Manager if you need help designing your messaging placement. Also, remember that Affirm must approve your messaging to ensure that it complies with regulatory guidelines. After your team finalizes the design, you can add the messaging to your site quickly.
2. Add Affirm.js
Add the Affirm.js embed code to the head of your global page template if you haven't already done so.
<!-- Affirm --> <script> _affirm_config = { public_api_key: "YOUR_PUBLIC_KEY", script: "https://cdn1-sandbox.affirm.com/js/v2/affirm.js" }; (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"); // Use your live public API Key and https://cdn1.affirm.com/js/v2/affirm.js script to point to Affirm production environment. </script> <!-- End Affirm -->
Be sure to use your public API key from the sandbox merchant dashboard for public_api_key.
Your global page template is the only place where you need this embed code.
3. Create promotional messaging components
Add an HTML element everywhere you want to display an Affirm promotional messaging component. The element attributes (see below) determine which component displays. We generally recommend adding promotional messaging to your category, product, cart, and payment pages.
See the following examples for how to add promotional messaging components to your site.
To add monthly payment messaging and a product modal to your product page:
<p class="affirm-as-low-as" data-page-type="product" data-amount="your_price_variable"></p>
Be sure to use your page's price variable or price amount in USD cents (e.g., $100 = 10000) for data-amount.
To add monthly payment messaging and a product modal to your cart page:
<p class="affirm-as-low-as" data-page-type="cart" data-amount="your_price_variable"></p>
Be sure to use your page's price variable or price amount in USD cents (e.g., $100 = 10000) for data-amount.
To add a site modal to a text link on your home page:
<a class="affirm-site-modal" data-page-type="homepage">Learn more</a>
To add a site modal to a banner link:
<a class="affirm-site-modal" data-page-type="banner"><img src="https://cdn-assets.affirm.com/images/banners/300x50.png"></a>
In each HTML element, be sure to include the data-page-type attribute corresponding to the page where that promotional messaging component is placed. The data-page-type attribute allows you to customize messaging in the future without development work. By default, promotional messaging on product pages have prequalification enabled, but you can work with your Client Success Manager to change this and configure additional customizations. See the links below for additional sample code.
- Monthly payment messaging with prequalification (single price)
- Monthly payment messaging with prequalification (single price displayed in multiple locations)
- Monthly payment messaging (multiple products and multiple prices)
- Site modal
HTML attributes
Monthly payment messaging (affirm-as-low-as) usually display price-specific information (requires data-amount) and are typically used with the following data-page-types:
- category
- product
- cart
- payment
Since site modals (affirm-site-modal) do not display price-specific information, they are typically used with the following data-page-types:
- homepage
- banner
- landing
- search
If you don’t pass data-page-type, the component will use a default setting.
Customize monthly payment messaging
You can customize the messaging to say anything you'd like, however, Affirm will need to approve it. Popular messaging examples include:
“As low as”
As low as {payment}/mo with [affirm_logo]. Learn more. |
As low as {payment}/month at {lowest_apr}% APR with [affirm_logo]. Learn more. |
As low as {payment}/month with [affirm_logo]. Learn more. |
For as low as {payment}/month with [affirm_logo]. Learn more. |
Financing as low as {payment}/month with [affirm_logo]. Learn more. |
“Starting at”
Starting at {payment}/month at {lowest_apr}% APR with [affirm_logo]. Learn more. |
Starting at {payment}/month with [affirm_logo]. Learn more. |
APR
{apr_range}% APR financing for {payment}/month with [affirm_logo]. Learn more. |
{apr_range}% APR starting at {payment}/month with [affirm_logo]. Learn more. |
Affirm monthly payments; rates from {apr_range}% APR. Learn more. |
Generic
Monthly payments with [affirm_logo]. Learn more. |
You can also:
- Replace the Affirm logo with plain text (data-affirm-type = "text")
- Change the Affirm logo color to black (data-affirm-color = "black")
- Remove the Learn more link
Customize educational modals
You can customize your Affirm messaging by adding a hero image and a logo for co-branded modals. Send the files below to merchanthelp@affirm.com to set this up:
- Hero image @2x: 960px width x 1462px height
- Hero image @1x: 480px width x 731px height
- Logo image @2x: 400px width x 112px height
- Logo image @1x: 200px width x 56px height
4. Add code to handle price changes
The price displayed on your product or cart pages may change due to product variants, quantity changes, etc. If your Affirm promotional messaging displays before the price update, the messaging will be inaccurate. To keep messaging updated, implement this refresh function into your price change callback function:
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 above refresh function statically on the page, wrap it in the affirm.ui.ready() callback function. Doing so ensures that the page does not call the refresh function before Affirm.js initializes.
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 to an existing callback that fires when the price updates 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 componenets affirm.ui.refresh(); }
Detect modal close
When an education modal is closed (non-prequal), you can detect that event by using the following code:
affirm.events.on('learnMore:close',function(){console.log('fired')});
5. Test and set live
If you're implementing promotional messaging as part of your initial integration, then don't connect to our live environment until you've tested your entire integration.