Skip to Content

Interface: HostContext

Global context singleton shared by every integration element on the page.

Examples

await customElements.whenDefined('my-integration'); const integration = document.querySelector('my-integration'); const { hostContext } = integration.constructor; hostContext.set({ appVersion: '2.3.0', deviceId: { id: '...', name: 'idfa' }, providers: { 'my-provider': async () => ({ token: await myAuth.getFreshToken() }) }, userIds: { netId: async ({ consent }) => consent ? { id: await getNetId() } : null }, });
<Integration tagName="my-integration" moduleUrl="https://example.com/integration/1/integration.js" integrationId="YOUR_INTEGRATION_ID" hostContextData={{ appVersion: '2.3.0', userIds: { netId: async ({ consent }) => consent ? { id: await getNetId() } : null }, }} />

Methods

get()

get<K>(key): HostContextData[K] | undefined

Read a static value. Returns undefined when not set.

Type Parameters

K

K extends "b2bContext" | "appVersion" | "presentationalContext" | "appName" | "appBundleId" | "appStoreId" | "appStoreUrl" | "deviceId"

Parameters

key

K

Returns

HostContextData[K] | undefined


has()

has(key): boolean

Whether a static value has been set.

Parameters

key

"b2bContext" | "appVersion" | "presentationalContext" | "appName" | "appBundleId" | "appStoreId" | "appStoreUrl" | "deviceId"

Returns

boolean


hasUserId()

hasUserId(name): boolean

Whether a user-id resolver has been registered.

Parameters

name

string

Returns

boolean


set()

set(data): void

Merge context data. Static fields are replaced; providers and userIds are merged per-name.

Parameters

data

HostContextData

Returns

void