For the complete documentation index, see llms.txt. This page is also available as Markdown.

Displaying an Offer

Show an offer panel on your page with a single placement.

Before you start

  • Install the SDK. See Installation.

  • Make sure your backend calls Create Offer and returns the full response to the browser.

Show the panel

1

Add the element

Add <cg-elements> where the panel must appear.

index.html
<cg-elements></cg-elements>

The tag name is fixed.

2

Register the SDK

Call registerElements() once for each page. Do this before you call getElement().

main.js
import { registerElements, getElement } from '@covergenius/elements';

registerElements({ environment: 'production' });

registerElements() is safe to call more than once.

3

Render the offer

Get the instance and call render() with the Create Offer response.

const cgElement = getElement();

cgElement.render(offerResponse);

render() accepts the complete response. Do not remove the presentation, content, products, or product_rules fields.

4

Listen for events

Add handlers before or after render(). The SDK keeps them either way.

cgElement.on('ready', () => {
  // The panel is visible.
});

cgElement.on('change', ({ selectedOption, selectedProductIDs, declined }) => {
  // The customer chose an option.
});

cgElement.on('error', ({ code, message }) => {
  // The SDK hid the panel.
});

See Handling Selection for the event payloads.

Update the offer

Call render() again with a new response. The SDK renders the panel again and removes options that no longer exist. Call it when the quote changes, for example when the customer changes the trip dates.

cgElement.render(updatedOfferResponse);

Each render() call replaces the previous response. The SDK does not merge responses.

What the customer sees

The panel has five sections. They show from top to bottom.

Section
Content

header

Title, icon, optional badge

top_body

Sub-heading, benefit lists, notices

input_body

Options, price, selection controls

bottom_body

Trust signals and testimonials

footer

Legal disclaimer and logo

Cover Genius chooses which sections and variants your offer shows. See Layouts and Sections.

Remove the panel

Call unmount() when your page removes the placement for good.

unmount() clears the handlers, the selection, and the state. The SDK hides the element but does not remove it from your DOM. Your code owns the element.

A render() call on an unmounted client does nothing. Call getElement() again to get a new client.

If nothing shows

  • Check that you called registerElements() before getElement().

  • Check that the response has a non-empty presentation field.

  • Register an error handler and read the code.

Last updated

Was this helpful?