Skip to main content
This guide explains how to integrate the Auxia SDK into your web application to deliver personalized treatments to your users.

Table of Contents

  1. Quick Start
  2. Installation
  3. Initialization
  4. SDK Methods Overview
  5. Method 1: fetchAndRenderTreatments
  6. Method 2: getTreatments
  7. Contextual Attributes
  8. Complete Examples
  9. Error Handling

Quick Start

Here’s a minimal example to get Auxia treatments rendering on your page. Each part is explained in detail in the sections that follow.
Note: Don’t worry if the code above looks unfamiliar. Each component—installation, initialization, and the SDK methods—is explained step-by-step in the following sections.

Installation

Include the Auxia SDK script in your HTML page:
This script exposes a global Auxia object that you use to initialize and interact with the service.

Prerequisites

Before integrating, ensure you have:
  • An API Key provided by Auxia
  • Your Project ID from the Auxia Console
  • A configured Surface in the Auxia Console (e.g., “HOME_PAGE”, “CHECKOUT_BANNER”)

Initialization

Before calling any SDK methods, you must initialize it with your credentials:

Configuration Options

Updating User ID

If the user ID is not available at initialization (e.g., the user logs in after page load), you can update it later:

SDK Methods Overview

The Auxia SDK provides two methods for fetching treatments: Both methods accept similar parameters. The key difference is that fetchAndRenderTreatments() requires you to specify where to render each treatment, while getTreatments() simply returns the treatment data.

Method 1: fetchAndRenderTreatments

Use this method when you want the SDK to both fetch treatments from Auxia and automatically render them into your page. This method returns Promise<void> - the treatments are rendered directly to the DOM.
Renderer ConfigurationAuxia configures renderers for each surface. Contact your Auxia POC to set up or modify renderers for your surfaces.
Automatic Interaction LoggingWhen using fetchAndRenderTreatments, the SDK automatically handles logTreatmentInteraction calls for treatment views, clicks, and dismissals.

Basic Usage

Request Parameters

Surface Request Parameters

Each object in the surfaceRequests array must include:
Note: For surfaces configured as pop-ups, modals, or slide-ups, the SDK renders the treatment as an overlay appended to the document body — not inside the container element you specify via surfaceHtmlElementId. This is intentional: overlay treatment types (pop-ups, modals, slide-ups) are designed to appear on top of existing page content regardless of where they are triggered. You can use a placeholder value for surfaceHtmlElementId (e.g., "popup-surface") for these surfaces. Contact your Auxia POC to configure overlay renderers or to request that a slide-up render inside a specific container element.

HTML Setup

Your page must have container elements with IDs matching the surfaceHtmlElementId values:

Fetching Multiple Surfaces

You can request treatments for multiple surfaces in a single call:
With corresponding HTML:

Adding Contextual Attributes

You can pass additional context to improve personalization:
See Contextual Attributes for all supported attribute types.

Complete fetchAndRenderTreatments Example


Method 2: getTreatments

Use this method when you need full control over how treatments are rendered. The SDK fetches treatments and returns them as data, allowing you to build your own UI.
Manual Interaction Logging RequiredWhen using getTreatments, you are responsible for calling logTreatmentInteraction to track treatment views, clicks, and dismissals. See Log Treatment Interactions for details.

Basic Usage

Request Parameters

Surface Request Parameters

Note: Unlike fetchAndRenderTreatments, you do NOT need surfaceHtmlElementId since you handle rendering yourself.

Response Structure

The method returns a Promise that resolves to:

Treatment Object Properties

Content Fields

Each treatment contains contentFields—an array of name-value pairs configured in the Auxia Console. Common fields include:

Working with Content Fields

Custom Rendering Example


Contextual Attributes

Contextual attributes allow you to pass additional information about the user, session, or page context to improve treatment personalization.

Supported Attribute Types

Common Contextual Attributes

Here are examples of commonly used contextual attributes:

Usage Example


Complete Examples

Example 1: Basic Page with Banner


Error Handling

Error handling is managed by the Auxia SDK. Contact your Auxia POC for more details on error handling behavior and configurations.