Nx10 Logo
Docs

2. Attributes API

Manage dynamic, changing state during app usage to provide context to nx10.

Context is Everything

While session configuration remains static, Attributes describe the rapidly changing runtime context of your app. Rapid tapping during an active checkout flow reads very differently to rapid tapping on a frozen loading screen, and the Attributes API is what tells nx10 the difference.

Attributes are sent through NX10Core.shared.attributes, backed by the SDK's AttributesProvider. Every call is dispatched asynchronously off the calling thread, so setting attributes never blocks your UI.

A reminder

You can only set basic key-value pairs here. No complex or nested values are allowed; set multiple flat pairs instead where more detail is needed.

The API Surface

The SDK exposes a small set of methods for managing attribute state and reporting device and app-level context alongside it.

1. Setting a Single Attribute

Use setAttribute(with:and:) to add a new key or overwrite an existing one. This is ideal for isolated state changes, like the user reaching a new step in a flow.

CheckoutViewController.swift
import NX10CoreSDK

await NX10Core.shared.attributes.setAttribute(with: "currentScreen", and: "checkout_step_1")

2. Bulk Updates

When several contextual values change at once, use setAttributes(_:) to merge a dictionary of values into the current state in a single call.

WorkoutTrackerView.swift
import NX10CoreSDK

let workoutContext: [String: Any] = [
    "currentScreen": "active_workout",
    "workoutType": "HIIT",
    "difficultySetting": "hard",
    "isMusicPlaying": true
]

await NX10Core.shared.attributes.setAttributes(workoutContext)

3. Clearing Attributes

Use clearAttributes() to wipe the current attribute state, for example when the user returns to a home screen and earlier flow-specific context is no longer valid.

HomeViewController.swift
import NX10CoreSDK

await NX10Core.shared.attributes.clearAttributes()

Data Constraints

Supported Value Types
  • setAttribute(with:and:) takes a single String value.
  • setAttributes(_:) accepts a flat [String: Any] of encodable primitives.
  • Strings, numbers, and booleans are supported values within that dictionary.
Unsupported Types

Like session initialization, the Attributes API enforces a flat structure.

  • No nested dictionaries or objects.
  • No arrays of any kind.
  • No custom class or struct instances.