Table of Contents
- Quick Start
- Installation
- Initialization
- SDK Methods Overview
- Method 1: fetchAndRenderTreatments
- Method 2: getTreatments
- Contextual Attributes
- Complete Examples
- 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: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 returnsPromise<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.
Basic Usage
Request Parameters
Surface Request Parameters
Each object in thesurfaceRequests 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 viasurfaceHtmlElementId. 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 forsurfaceHtmlElementId(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 thesurfaceHtmlElementId values:
Fetching Multiple Surfaces
You can request treatments for multiple surfaces in a single call:Adding Contextual Attributes
You can pass additional context to improve personalization: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.Basic Usage
Request Parameters
Surface Request Parameters
Note: UnlikefetchAndRenderTreatments, you do NOT needsurfaceHtmlElementIdsince you handle rendering yourself.
Response Structure
The method returns a Promise that resolves to:Treatment Object Properties
Content Fields
Each treatment containscontentFields—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 2: User Authentication Flow
Example 2: User Authentication Flow
Example 3: Custom Rendering with getTreatments
Example 3: Custom Rendering with getTreatments