---
updatedAt: 2025-11-13T14:09:25.000Z
agentTools:
  siteIndex: https://docs.affirm.com/llms.txt
  projectIndex: https://docs.affirm.com/developers/llms.txt
---

# Set Up Google Tag Manager

Learn how to set up Google Tag Manager for your site to manage tracking, advertising, and other marketing functions on your site.

## Prerequisites

* Create a [Google Tag Manager](https://tagmanager.google.com/) account.

<br />

## Steps

### 1. Upload the Custom Template

1. Download the template.tpl file from [Github](https://github.com/Affirm/example-code).
2. Open [Google Tag Manager](https://tagmanager.google.com/).
3. Click on the **Templates** tab.
4. In the **Tag Templates** section, click **New**.

   <Image alt="In the Templates tab, a Tag Templates section contains a button called New." align="center" className="border" border={true} src="https://files.readme.io/9ff1a819fee3b24164eb065d50b0cf98a3ab190ee3c80fb49eb7e108e1dae103-Screenshot_2025-07-17_at_2.06.00_PM.png" />
5. Click the three-dots icon to expand the menu.
6. Click **Import**.

   <Image alt="Import option on menu" align="center" className="border" width="70% " border={true} src="https://files.readme.io/c4a04145656663634c84ad666558d1db44c5433d6b32b14b304e2efd8545d95f-Screenshot_2025-07-17_at_2.07.40_PM.png" />
7. Select the template.tpl file that you downloaded from Github in Step 1.
8. Click **Save**.

### 2. Add a Tag

1. Open [Google Tag Manager](https://tagmanager.google.com/) for your Workspace.
2. Click on the **Tags** tab.
3. Click **New**.

   <Image alt="In the Tags tab, the Tag section features a New button. " align="center" className="border" border={true} src="https://files.readme.io/aaf674b84e29047a1ae8dcadfd3d8a51adc33032ce971df156f7bdc814793ab4-Screenshot_2025-07-17_at_2.02.41_PM.png" />
4. Click on the **Tag Configuration** section.
5. In the **Custom** section, click **Affirm**.
6. Click on the **Triggering** section.
7. Select **All Pages**.
8. Click **Add**.

   <Image alt="All pages are selected and Add button is shown" align="center" className="border" border={true} src="https://files.readme.io/40f4c5fb89812cd1e61e2be07a40cd4ab59a1fbec9ec99d668bbafc25f2f93f4-Screenshot_2025-07-17_at_2.10.36_PM.png" />
9. Click **Save** to save the tag configuration.

### 3. Configure the API Key

1. In the **Tags** section, click to open the tag.
2. Click on the **Tag Configuration** section.

   <Image alt="Tag Confirmation section with Tag Type, Affirm Configuration, Payment Button, Logo Color, and Position subsections." align="center" className="border" width="90% " border={true} src="https://files.readme.io/9bbed580c5ef8d4110a532572709a2ec5fe26d3bef559f4bfb4f361917145d38-Screenshot_2025-07-17_at_2.13.22_PM.png" />
3. In the **Affirm Configuration** sub-section, add your public API key in the **Affirm Public API Key** field.
4. Select the type of API key you’re using:
   1. Sandbox for testing.
   2. Production to create actual loans.

### 4. Configure Promotional Messaging

You can add as-low-as messaging and logos to your site with minimal effort:

* **Promotional Message:** This targets one element on a page.
* **List of Promotional Messages:** This is for when there are similar elements on one page that you want to target. There must be the same number of instances of classes in the **Target Element** field that there are in the **Price Element** field.
* **Logo:** This displays a logo anywhere on your site.

<HTMLBlock>{`
<div>
  
  <div class="tab">
    <button class="tablinks active" onclick="handleTabChange(event, 'Promotional Message')">Promotional Message</button>
    <button class="tablinks" onclick="handleTabChange(event, 'List of Promotional Messages')">List of Promotional Messages</button>
    <button class="tablinks" onclick="handleTabChange(event, 'Logo')">Logo</button>
  </div>
  
      <div id="Promotional Message" class="tabcontent active">
      <p><h4>Add a Promotional Message</h4>
<ol><li>Click the <b>Promotional Messaging </b>sub-section.</li>
<li>Click <b>Add Row</b> in the <b>Promotional Message </b>row.</li>
<li>In the <b>Target Element</b> field, select the HTML class or ID to identify where to display the promotional message.</li>
<li>In the <b>Price Element </b>field, select the HTML class or ID of the element that includes the price.</li>
<li>Select a <b>Page Type</b> to indicate where the promotional messaging should display.</li>
<li>In the <b>Affirm Type</b> field, you can select either:
<ul><li><b>Logo: </b>Displays the Affirm logo in promotional messaging. You can also choose a logo color.</li>
<li><b>Text: </b>Displays “Affirm” as text in promotional messaging. </li></li></ul>
<li>Select a <b>Position in Target </b>option to indicate the position of promotional messaging relative to the <b>Target Element</b>.</li></ol></p>
        </div>
   
                 <div id="List of Promotional Messages" class="tabcontent">
      <p><h4>Add a List of Promotional Messages</h4>
<ol><li>In the <b>Promotional Messaging</b> sub-section, click <b>Add Row</b> in the <b>List of promotional messages</b> row.</li>
<li>In the <b>Target Element</b> field, select the HTML class to identify where to display the promotional messaging.</li>
<li>In the <b>Price Element</b> field, select the HTML class of the element that includes the price.</li>
<li>Select a <b>Page Type</b> to indicate where the promotional messaging should display.</li>
<li>In the <b>Affirm Type</b> field, you can select either:
<ul><li><b>Logo:</b> Displays the Affirm logo in promotional messaging. You can also choose a logo color.</li>
<li><b>Text:</b> Displays “Affirm” as text in promotional messaging. </li></li>
<li>Select a <b>Position in Target</b> option to indicate the position of promotional messaging relative to the <b>Target Element</b>.</li></ol></p>
        </div>

      <div id="Logo" class="tabcontent">
      <p><h4>Add a Logo</h4>
<ol><li>In the <b>Promotional Messaging</b> sub-section, click <b>Add Row</b> in the <b>Logo</b> row.</li>
<li>In the <b>Target Element</b> field, select the HTML class to identify where to display the logo.</li>
<li>In the <b>Logo Width</b> field, enter the width that you’d like the logo to display as, in pixels. Don’t append “px” to the number (e.g., For 200 pixels wide, enter “200” in the field).</li>
<li>In the <b>Color</b> field, select the logo color.</li>
<li>Select a <b>Position in Target</b> option to indicate the position of promotional messaging relative to the <b>Target Element</b>.</li></ol></p>
        </div> 
  
  

<style>
.grid {
    display: flex;
    flex-wrap: wrap;
    gap: 20px;
    justify-content: space-between;
}

.card {
    display: flex;
    align-items: center;
    width: 360px; /* Adjust width based on the attached image */
    background-color: #ffffff;
    padding: 5px 10px;
    border-radius: 20px; /* Rounded corners */
    box-shadow: 0px 4px 8px rgba(0, 0, 0, 0.1); /* Light shadow */
    text-decoration: none;
    color: #333; /* Text color */
    transition: transform 0.3s;
    margin: 10px; /* Added margin to avoid cards sticking to each other */
}

.card:hover {
    transform: translateY(-5px); /* Slight upwards lift on hover */
}



.card__image {
    margin-right: 20px;
    width: 50px; /* Adjust based on the attached image */
    height: auto;
}

.card__content {
    display: flex;
    flex-direction: column;
}

.card__heading {
    margin: 0 0 5px 00;
    font-size: 18px; /* Adjust font size if needed */
    font-weight: normal; /* Made normal as per your image */
}

.card__description {
    margin-top: 4px;
    font-size: 14px; /* Adjust font size if needed */
}
  @media only screen and (min-width: 640px) {
  .grid {
    grid-template-columns: 1fr 1fr;
  }

  .grid--full {
    grid-template-columns: 1fr;
  }
}

</style>
`}</HTMLBlock>

### 5. Configure the Credit Card Form Fields

When the customer completes their Affirm checkout, we return them to your checkout page. At that time, a success callback function is triggered and the generated debit card details are included in the success callback event data.

To configure this checkout flow, you must:

1. Store the virtual card details returned from Affirm.
   1. Populate hidden credit card form fields so they can be leveraged by the standard 'submit' action , or
   2. Immediately make the API call to tokenize the card, in anticipation of authorization in a subsequent step.
2. Submit the in-progress checkout form on your site (either user-initiated or automatic).
   1. Customer must click the 'place/finalize/complete order' button to complete the order, or
   2. Automatically submit the checkout form after the Affirm checkout has been confirmed.
3. Put a pending authorization hold on the funds on the virtual card.
   1. Use your checkout form's existing functionality to submit the debit card details to your card gateway for authorization.
   2. Directly submit the debit card details to your card gateway for authorization at runtime, instead of using the existing card-submit-for-authorization mechanism.

### 6. Configure Checkout

1. In the **Merchant Name** field, enter the name of the merchant.
2. In the following sections, enter HTML class or ID where the associated values are on the checkout page:
   1. **Items**. Note: The **Item Container** must be an element that surrounds the following fields.
   2. **Billing**.
   3. **Shipping**.
3. In the **Payment Button** section, you can configure a button for the payment types section of your checkout:
4. In the **Target Element** field, choose the HTML class to identify where the button should show.
5. In the **Payment Description** field, you can customize the message. We suggest using **Monthly Payments**.
6. In the next field, you can choose whether Affirm appears as a logo or text in the button.
7. In the **Logo Width** field, enter the width that you’d like the logo to display as, in pixels. Don’t append “px” to the number (e.g., For 200 pixels wide, enter “200”).
8. In the **Color** field, select a logo color.
9. Select a **Position** option to indicate the position of promotional messaging relative to the **Target Element**.
10. In the **Card Output** section, enter the HTML class or ID with the corresponding hidden credit card form fields.
11. In the following fields, select the HTML class or ID where the amount is located:
    1. **Shipping Amount**
    2. **Tax Amount**
    3. **Total Amount**
12. In the **Submit Element** field, choose the HTML class or ID of the button to submit an order.

### 7. Integrate

1. Click the name of the container you’re currently editing, such as:
2. <Image title="GTM-1.png" alt="GTM-WFLMNVK" align="center" className="border" border={true} src="https://files.readme.io/1e958a7-GTM-1.png" />

   In the modal window, copy the embed code snippets for heading and body, and paste them into your page’s heading and body.

<Image title="GTM-2.png" alt="Install Google Tag Manager. First field is for HEAD code and second field is for BODY. " align="center" className="border" border={true} src="https://files.readme.io/75fac34-GTM-2.png" />

3. For more information, you can refer to [Google's quickstart guide](https://developers.google.com/tag-manager/quickstart).
4. Test the integration by providing your Affirm contact with a test card number that can be successfully authorized. See an example on [Github](https://affirm.github.io/example-code/gtm/sample.html).

# Sibling pages

* [About Promotional Messaging and Prequalification](https://docs.affirm.com/developers/docs/about-promotional-messaging-and-prequalification.md)
* [Set Up Promotional Messaging](https://docs.affirm.com/developers/docs/set-up-promotional-messaging.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)
* [Marketing and Compliance](https://docs.affirm.com/developers/docs/email-marketing.md)