Skip to main content
Add the SDK to your site once. Where treatments appear, and what they look like, is then managed in the Auxia Console, with no further code changes on your site. If a surface needs fine-grained control from your page code, you can instead fetch and render its treatments yourself. See Render from Your Own Code. Both approaches use the same script and can run side by side, one per surface, in the same project. The rest of this page covers Console-managed rendering.

Prerequisites

  • API key and Project ID from the Auxia Console.
  • Project Website URL set in your project settings in the Auxia Console. The Console uses it to open your site for picking placements and previewing treatments.

1. Install

Add the SDK script to every page where treatments may appear:

2. Initialize

This is the only code your site needs. The SDK renders treatments on the surfaces you configure in the Auxia Console.
userId must be present at initialize()Console-managed rendering starts during initialize() and does nothing when userId is empty. Calling updateUserId() afterwards does not start it. On a page where the user is known only after login, call Auxia.initialize() after you have the ID.

3. Enable Console-managed rendering for your project

Ask your Auxia contact to enable Console-managed rendering for your project. Once enabled, the Surfaces list under Configuration > UI Layout in the Auxia Console shows an SDK status column, which shows the surfaces it serves.

4. Set up surfaces and treatments

In the Auxia Console:
  1. Create a surface and pick where it appears by selecting an element on your live site.
  2. Choose the pages it applies to and how it is inserted relative to that element.
  3. Choose a Layout for the surface.
  4. Set up treatments, and preview them on your site before publishing.
To show a surface over the page instead of at an element, see Overlay Layouts.

Page paths

A page path is matched against the page’s whole URL path. The domain, query string and fragment are not part of it. /jobs/ matches only that exact page, and /jobs without the trailing slash is a different page. Three wildcards widen a path: For example, /*/articles/*/ matches these paths as follows: To cover a path and everything below it, use **. /jobs/** matches /jobs/, /jobs/index.html and /jobs/tokyo/123. When you select an element on your page, the Console lets you choose how widely the path applies. This page only keeps the exact path, Matching pattern replaces an ID-like segment with *, and All pages below this path covers the folder that holds the page, for example /jobs/** for /jobs/index.html.

Injection positions

REPLACE keeps the anchor elementREPLACE empties the anchor and renders inside it; it does not remove the anchor. If your site’s code later rewrites that element’s content, it will silently overwrite the treatment. Pick an element your site does not re-render.
To keep your own content in a REPLACE element for when Auxia doesn’t render, see Fallback content.

Using Google Tag Manager

For the best performance, we recommend you add the SDK directly to your site’s codeThrough GTM, the SDK starts loading only after the GTM container has loaded and the tag’s trigger has fired, so treatments appear later than with the direct install in steps 1 and 2. Use GTM when editing your site’s code is not an option.
You can add the SDK through a Custom HTML tag instead of editing your site’s code. Create a Custom HTML tag that loads the SDK script and calls Auxia.initialize() once the script has loaded, pass the user ID in from a GTM variable (for example, a Data Layer Variable), and set the tag to fire on every page where treatments may appear, only after the user ID is available.

How the SDK behaves on your site

  • It loads your surface configuration from Auxia and caches it in the browser.
  • On each page, it renders treatments only on the surfaces whose page paths match, waiting for elements that load late.
  • Views, clicks and dismissals are recorded automatically. See Interaction tracking.
  • Single-page app navigation is handled: surfaces are removed and re-rendered as the path changes.
  • Failures are contained. If anything goes wrong, the page is left untouched, no error is thrown into your code, and first paint is never blocked.

Interaction tracking

A view is recorded automatically once at least half of the treatment has been visible for one second. Clicks and dismissals are recorded only on elements in the Layout or Design template that carry data-aux-button-name:
Clicks on elements without data-aux-button-name are not recorded.

Check that interactions reach Auxia

You can check in your browser that an interaction was sent, and in the Auxia Console that Auxia stored it against the right treatment. In your browser. Open DevTools, go to the Network tab and filter by LogTreatmentInteraction. Each recorded view, click or dismissal is one POST request to /v1/LogTreatmentInteraction, and a 200 status means Auxia accepted it. The request payload contains: The SDK does not report a rejected request in the browser console, so check the status in the Network tab. In the Auxia Console. Open Treatments & Journeys > QA & Testing > Recent Responses, choose the surface, and click Refresh. It shows the treatments Auxia returned and the views and clicks recorded for them. See Checking Recent Responses for what the tab shows and the role it needs.

Fallback content

Fallback content is optional. Most surfaces don’t need it:
  • Default: no fallback. For visitors who should see your existing content, such as the control group or visitors without a treatment, set up a treatment with that content in the Auxia Console. It is tracked like any other treatment, so the control group’s views and clicks stay comparable.
  • Use fallback content only when the surface must show something even if Auxia can’t be reached or doesn’t answer in time, such as a landing page’s key visual, or when the element needs real content in the HTML for crawlers.
With fallback content, your own content stays in the element and Auxia replaces it only when it renders. This works only with the REPLACE injection position.

What visitors see

The element shows loading content, then exactly one final state: Visitors never see the fallback replaced by Auxia’s content, or Auxia’s content replaced by the fallback.

Set it up

  1. Add the Auxia stylesheet to <head>, on every page with a fallback. It is the same for every page and every site.
    • Use a normal <link> in <head>, before the slot. It has to be in place before first paint: the SDK loads after the page has painted, so only CSS already on the page can keep the fallback hidden until Auxia decides. Don’t add it from a tag manager.
    • It adds one small request to auxia.net that blocks rendering, on each page that links it.
    • If auxia.net is unreachable, the fallback shows straight away, together with the loading content. Your page keeps its own content.
    • If your site can’t load a third-party stylesheet (for example because of its Content Security Policy), you can copy the contents of auxia.css into a <style> in <head> instead. You then need to update that copy yourself when the file changes.
  2. Mark up the element:
    • data-auxia-slot goes on the element the surface is placed on.
    • data-auxia-fallback is your content, shown when Auxia doesn’t render.
    • data-auxia-loading (optional) shows until the final state. Without it, the space stays blank.
    • Both must be direct children of the slot.
  3. In your own CSS, reserve the slot’s size and, optionally, set the deadline:
    • Reserve the size (aspect-ratio, min-height or a fixed height), so the page doesn’t shift when the final content appears.
    • --auxia-fallback-delay is the deadline, in ms or s. The default is 3000ms.
  4. In the Auxia Console, place the surface on the slot’s selector (for example .kv) with REPLACE.

Listen for the outcome

Optional. The slot fires auxia:slot-settled when it reaches its final state, and the event bubbles to document:
The same state is set on the slot as data-auxia-state.

Things to know

  • REPLACE only. With another position, your fallback stays next to Auxia’s content.
  • Leave the slot’s display to the Auxia stylesheet. It stacks the loading and fallback content in one grid cell. Setting display on the slot in your own CSS breaks this.
  • Keep the loading content light, such as a CSS skeleton. A large loading image can become the page’s Largest Contentful Paint.
  • The fallback image always downloads, even when Auxia renders, because hidden images still load. In return, it appears instantly when needed.
  • A late response is not shown. Once the deadline passes, the slot keeps the fallback for the rest of the page view.
  • A slot added later gets the full deadline. On a client-rendered page, the deadline counts from when the slot appears.
  • Single-page apps: a slot that stays on the page across routes keeps its state. Once it has settled on the fallback, it keeps the fallback.
Without the stylesheet, Auxia’s content never appearsThe SDK never replaces a fallback that is already visible, and without the stylesheet nothing hides it. If the slot always shows the fallback, check that the <link> is in <head> and that auxia.css loads (browser DevTools, Network tab).

Contextual attributes from your page

Pass context only your page knows, such as a membership tier or a cart value, as contextual attributes, and Auxia uses it to choose and personalize treatments on your Console-managed surfaces.
Send the attribute keys agreed with your Auxia representative. A key that hasn’t been set up for your project is ignored, so check with them before adding a new one.
  • Pass values known at page load to initialize({ contextualAttributes }), so the first request carries them.
  • setContextualAttributes(attributes, { scope }) merges into what is already set, and null removes a key. It sends no request by itself: values go out with the SDK’s next request, or immediately for a placement set to refresh on that attribute.
  • Values can be a string, number, boolean or Date.
  • scope only matters in a single-page app. Every value is cleared when the page reloads (the SDK starts fresh); with "page", it is also cleared when the URL path changes, while "session" (default) keeps it across route changes.
  • It throws on an empty or reserved key (any auxia_* key, user_id, surfaces and a few others), an unsupported value type or an unknown scope. NaN, Infinity and invalid Dates are skipped with a console error.

Refresh a placement when an attribute changes

By default, a placement fetches once per page view, so a value set later is used from the next request on. To have a placement fetch again when a specific attribute changes, turn it on for that placement in the Auxia Console (Placement step → Advanced · Refresh on context change), add the attribute, and choose what happens when it changes:
  • Fill if empty (default): fetch again only while the placement is showing nothing. Content already on the page stays.
  • Replace content: fetch again every time the value changes and show the new result. If nothing comes back, the current content stays.

Styling

Surfaces render inside a Shadow DOM, so your page stylesheet does not reach them. Reusing your own class names styles nothing. CSS custom properties do cross the boundary, so tokens defined on the page are readable from inside the surface:
Backgrounds, section padding and container width usually live on page elements outside the surface, which the SDK leaves alone. Do not re-implement them inside the template. Please reach out to your Auxia contact for further styling support.

Overlays and display timing

Overlay Layouts

With Placement Type set to Overlay, a surface shows over the page instead of at an element; the SDK adds it to the end of <body>. In the Layout step, pick Modal, Bottom bar or Corner panel. For your own backdrop, position or size, or an entrance animation, pick Custom: it starts from a copy of the Layout you had selected.

Show after a delay or a scroll

In the surface’s Placement step, where you pick the element and pages, open When it shows and set either or both. The setting applies to every treatment shown in that surface.
  • Delay: seconds to wait after the SDK adds the surface to the page. 3 shows it 3 seconds later.
  • Scroll depth: how far down the page the visitor must scroll, in % of the page. 50 shows it once they have scrolled halfway.
  • With both set, it shows once both are met. With neither, it shows right away.
The Modal Layout behaves as a modal dialog. When it appears, keyboard focus moves into it and Tab stays inside. Escape or a click on the backdrop closes it, records DISMISSED, and returns focus to where it was. To get this in a Custom Layout, add role="dialog" to the dialog element: the card, not the backdrop. Don’t add it to bars, corner panels or inline banners, where trapping focus stops keyboard users from reaching the rest of the page.

Entrance animation

When an overlay shows (after any delay or scroll), the SDK sets data-auxia-revealed on the surface’s host element. In a Custom Layout, start the animation from :host([data-auxia-revealed]):
  • Write the final look as the normal style and only the starting state in @keyframes. The Console preview never sets the attribute, so anything hidden by default stays hidden there.
  • Animate elements inside the Layout, not :host: a transform or opacity on the host can break the overlay’s fixed position and stacking.
The Console preview shows treatments right away. It ignores delay and scroll, and doesn’t play the animation or apply modal handling, so check these on your site.

Moving a surface from your own code to the Console

A surface you already render from your own code keeps working as it is. To hand it over to the Console:
  • Remove its fetchAndRenderTreatments() or getTreatments() call. Calls for your other surfaces keep working.
  • Its container element and surfaceHtmlElementId are replaced by a placement picked in the Console.
  • data-aux-* interaction attributes move from your page markup into the Layout and Design templates in the Console.
  • Contextual attributes are set once with setContextualAttributes() instead of on each call.

Troubleshooting

If a surface does not render, check that:
  • The SDK status column appears in the Console. If it does not, Console-managed rendering is not yet enabled for your project.
  • Auxia.initialize() is called with a non-empty userId.
  • The surface’s page paths match the page you are on.
  • The element the surface is placed on exists on the page.
  • The surface has a published Layout and at least one live treatment.
If a slot with fallback content always shows its fallback, check that the Auxia stylesheet is linked in <head> and loads, and that the surface uses REPLACE. If a view or click is not recorded, check that:
  • For a click, or a dismissal from a button, the element carries data-aux-button-name.
  • For a view, at least half of the treatment stayed visible for one second.
  • The LogTreatmentInteraction request returns 200. See Check that interactions reach Auxia.
  • In Recent Responses, the surface and user ID match your test, and the test was within the last 24 hours.
If it still does not render or record, send your Auxia contact the page URL, the surface name and the user ID you tested with.