API Reference
Every export of @covergenius/elements.
registerElements(config)
Registers the <cg-elements> custom element and creates the SDK context. Call it once for each page, before getElement().
registerElements(config: RegisterElementsConfig): voidThe call is safe to repeat. It does nothing when no customElements registry exists, for example on a server.
RegisterElementsConfig
environment
'production', 'uat', or 'develop'
Yes
production
Selects the SDK environment.
currencyConfig
CurrencyFormatOptions
No
none
Price format. See Currency and Language.
scheme
'light' or 'dark'
No
light
The active color scheme.
debug
boolean
No
false
Writes SDK logs to the browser console.
getElement(ref?)
Returns the client for one placement.
getElement(ref?: string): Client | undefinedref
The data-presentation-ref value of the placement. Omit it for a single placement.
It returns undefined when registerElements() has not run. It also returns undefined outside a browser.
Client
The object that getElement() returns.
Methods
render(response)
Renders or renders again from the Create Offer response.
on(event, handler)
Sets the handler for an event. A new call for the same event replaces the old handler.
selection.set(optionId)
Chooses an option.
selection.get()
Returns the last selected option ID, or null.
selection.getAll()
Returns all selected option IDs in order.
selection.reset()
Clears the selection and the required prompt.
selection.required()
Shows the required prompt while nothing is selected.
unmount()
Clears handlers, selection, and state. Hides the element.
Events
ready
None.
change
{ selectedOption: string, selectedProductIDs: string[], declined?: boolean }
error
{ code: string, message: string }
Attributes
data-presentation-ref
<cg-elements>
Names a placement. Use the value of presentation.ref.
data-cg-elements-state
<cg-elements>
Read-only. Holds loading, rendered, or error.
data-cg-elements-required
<cg-elements>
Read-only. Present while the required prompt shows.
Package entry points
@covergenius/elements
The SDK. ESM and CommonJS.
@covergenius/elements/loader.css
The optional loading animation.
Offer response fields that the SDK reads
currency
The currency code for all prices.
products[]
The quotes. Each has an id, price details, and a policy wording URL.
product_rules[]
How many options the customer can choose, and which options show or hide others.
content
The customer-facing text.
presentation
The schema_version, ref, layout, and theme.
The SDK needs a non-empty presentation field and a supported schema_version. The current version is 1.0.
Last updated
Was this helpful?

