> ## Documentation Index
> Fetch the complete documentation index at: https://docs.cello.so/llms.txt
> Use this file to discover all available pages before exploring further.

# Usage

> Below is the full list of commands to call the Cello JS SDK with.

## `cello.boot(options)`

Initializes Cello Referral Component in your product.

Returns a promise that is resolved once the whole initialization process is finished or rejected if the boot command failed.

```javascript theme={null}
window.cello = window.cello || { cmd: [] };

window.cello.cmd.push(async (cello) => {
  try {
    await cello.boot(options);
  } catch (error) {
    // Handle the error appropriately
  }
});
```

The solution above is designed so that you don't have to wait for the library to finish loading before you call the command - follow it and use the `window.cello` object to avoid that particular race condition.
For any other commands, or when you are sure that the command is called after the library has finished loading, you can opt to use the regular command syntax:

```javascript theme={null}
await window.Cello("boot", options);
```

### Accepts

**options** `object` *required*

The initialization options object:

**properties**

**productId** `string` *required*

Identifier of the product your users will refer.
You can obtain this in your Cello Portal.

**token** `string` *required*

Access token generated for the given user.
More in [User Authentication](https://docs.cello.so/referral-component/user-authentication.md).

**productUserDetails** `object` *required*

Product user details object. Required for select features

**properties**

**email** `string` *required*

Email of the product user. This data is used in the personalization of the referral
experience, e.g. email notifications. Required for select features

**firstName** `string` *required*

First name of the product user.
This data is used in the personalization of the referral experience, e.g. email notifications and the [personalized message to referees](https://docs.cello.so/docs/add-personalized-message.md).
Required for select features

**lastName** `string`

Last name of the product user

**fullName** `string`

Full name of the product user.
Use this option if you do not have first name and last name separately.

**productUserCountryCode** `string`

Product user country, if known. ISO 3166 Alpha-2 standard e.g. `DE`.
If the country is not on the [supported payout countries list](https://docs.cello.so/guides/user-experience/overview.md#reward-countries-and-payout-methods), the Referral Component will not be booted for this user.
If no country is passed, Cello will still be booted.
Note: this uses the country your product has on file, which may differ from the user's actual PayPal payout country. See the [unsupported countries guidance](https://docs.cello.so/guides/user-experience/overview.md#reward-countries-and-payout-methods) for tradeoffs before using this to gate visibility.

**language** `string`

The language, in which the Referral Component will be loaded in ISO 639-1.
Default: `undefined`. If undefined, we use default language set for your product.
Note: the language must be enabled for your product by Cello - if the language is not enabled, this parameter has no effect and the component falls back to your product's default language. Contact Cello support to enable additional languages.

**themeMode** `string`

Set light or dark theme to match your app’s interface. Accepts `light` and `dark`.
Default: `light`.

**nonce** `string`

The CSP nonce of the current response, for sites whose Content Security Policy uses a nonce in `style-src` or `script-src`. The Referral Component puts it on every style it creates and on the font stylesheet it loads.
Default: `undefined`. Not needed when your policy allows `'unsafe-inline'` or you set no CSP. See [Nonce-based policies](#nonce-based-policies).

**hideDefaultLauncher** `boolean`

Hides the entire default Cello launcher button. Use this when you want to provide your own launcher element via `customLauncherSelector`.
Default: `false`.
Note: this hides the **button**, not just the notification badge. To hide only the badge on a custom launcher element, add `data-cello-badge="false"` to your HTML element instead - see [Configure notification badge](https://docs.cello.so/referral-component/custom-launcher.md#configure-notification-badge). There is no `hideDefaultBadge` boot option.

**onOpen** `function`

Callback event for when Referral Component widget is opened.

**onClose** `function`

Callback event for when Referral Component widget is closed.

**onUserInteraction** `function`

Callback handler for user interactions within the Referral Component.
Receives two parameters: `action` (string) and `payload` (any).
Currently supports `linkCopied` action which provides the copied URL as payload.

**onUnreadCountChanged** `function`

Callback for when the unread counts change. Use it to show the [notification badge](https://docs.cello.so/guides/user-experience/referral-notifications-and-emails.md#alert-and-badge) in your own UI, as described in [Show your own badge](https://docs.cello.so/referral-component/custom-launcher.md#show-your-own-badge).
Receives two parameters:

* `badgeCount` (number): a number you can show on your own badge, at most 99. The number of unread rewards, otherwise `1` for another unread notification such as an unseen alert, otherwise `0`. Unread views are not counted. Cello's own badge is a dot and doesn't show this number
* `detailedCounts` (object): the unread counts by type, same shape as [`getUnreadEventCounts()`](#getunreadeventcounts) returns

Called right at boot with all counts at `0`, again once notifications have loaded, and then on every change, including when the user opens the Referral Component and the counts are cleared. It can be called again with the same values, so make your handler safe to call repeatedly.

**onAnnouncementChanged** `function`

Callback for when the active [announcement](https://docs.cello.so/guides/user-experience/referral-notifications-and-emails.md#announcement) changes. Use it to show announcements in your own UI instead of the Referral Component's announcement bubble. [Show your own announcement](https://docs.cello.so/referral-component/custom-launcher.md#show-your-own-announcement) explains how, including how to turn off the bubble.
Receives one parameter: the active `announcement` object (same shape as [`getActiveAnnouncement()`](#getactiveannouncement) returns), or `null`.

* Called with `null` right at boot, then with the active announcement once it has loaded, if there is one
* Called with the new announcement when one arrives, or after [`showAnnouncement`](#showannouncement-announcement)
* Called again if the announcement content changes, e.g. after [`changeLanguage`](#changelanguage-language)
* Called with `null` when the announcement is read or dismissed, including when the user opens the Referral Component

### Example

```javascript theme={null}
window.cello = window.cello || { cmd: [] };

window.cello.cmd.push(async (cello) => {
  try {
    const options = {
      productId: "REPLACE_WITH_PRODUCT_ID",
      token: "REPLACE_WITH_TOKEN",
      language: "en",
      productUserDetails: {
        firstName: "Bob",
        lastName: "Bobsky",
        fullName: "Bob B Bobsky",
        email: "bob@gmail.com",
      },
      onUserInteraction: (action, payload) => {
        console.log('user interaction', action, payload)
        if (action === 'linkCopied') {
          const urlThatWasCopied = payload
          // Handle the copied link (e.g., track analytics, show notification)
        }
      }
    };

    await cello.boot(options);
    // Call other Cello commands, if necessary
  } catch (error) {
    console.error("Failed to boot cello:", error);
  }
});
```

***

## `changeLanguage(language)`

Changes the Referral Component language at runtime without re-initializing it.

```javascript theme={null}
window.Cello("changeLanguage", "de");
```

### Accepts

**language** `string` *required*

The language string in ISO 639-1

## `setThemeMode(theme)`

Changes the Referral Component theme at runtime without re-initializing it.

```javascript theme={null}
window.Cello("setThemeMode", "dark");
```

### Accepts

**theme** `string`

The theme mode to apply. Accepted values are `light` or `dark`.

## `close()`

Closes Referral Component.

```javascript theme={null}
window.Cello.close();
```

***

## `dismissAnnouncement()`

Dismisses the active [announcement](https://docs.cello.so/guides/user-experience/referral-notifications-and-emails.md#announcement) without opening the Referral Component. Use it for the close button when you show announcements in your own UI.
The announcement is marked as read, and [`onAnnouncementChanged`](#cello-boot-options) is called with `null`. Does nothing if there is no active announcement.

```javascript theme={null}
window.Cello("dismissAnnouncement");
```

***

## `getActiveAnnouncement()`

Returns the active [announcement](https://docs.cello.so/guides/user-experience/referral-notifications-and-emails.md#announcement) for the currently logged-in user, or `null` if there is none.
Heading and text are translated and personalized the same way as in the Referral Component's own announcement bubble, including your label overrides.

Use it when your page loads after the announcement arrived. To be notified when the announcement changes, use the [`onAnnouncementChanged`](#cello-boot-options) boot option.

```javascript theme={null}
const announcement = await window.Cello("getActiveAnnouncement");
```

### Returns

**announcement** `object | null`

The active announcement object:

**properties**

**id** `string`

Unique identifier of the announcement

**type** `string`

Announcement type, e.g. `welcome-announcement-1`

**heading** `string`

Announcement heading, translated to the current language

**text** `string`

Announcement text, translated to the current language. May contain simple `<strong>` markup

**icon** `string`

Optional icon name: `Heart`, `Success` or `Gift`

**ctaLabel** `string`

Optional call-to-action button label

**ctaDestination** `string`

Optional Referral Component page the call-to-action opens, e.g. `invite` or `rewards`. Pass it to [`open`](#open-destination)

### Example

Example below shows the announcement in your own UI. The call-to-action opens the Referral Component on the right page, which also marks the announcement as read:

```javascript theme={null}
const renderAnnouncement = (announcement) => {
  if (!announcement) {
    hideMyAnnouncement();
    return;
  }

  showMyAnnouncement({
    heading: announcement.heading,
    text: announcement.text,
    ctaLabel: announcement.ctaLabel,
    onCtaClick: () =>
      window.Cello("open", announcement.ctaDestination),
    onClose: () => window.Cello("dismissAnnouncement"),
  });
};

await window.Cello("boot", {
  // ...other options
  onAnnouncementChanged: renderAnnouncement,
});

// In a component that mounts later, read the active one
renderAnnouncement(await window.Cello("getActiveAnnouncement"));
```

> [!NOTE]
>
> `text` can contain `<strong>` tags. If you insert it as HTML, sanitize it first. Otherwise, strip the tags and show it as plain text.

## `getActiveUcc()`

Returns active `ucc` and invite `link` for the currently logged-in user.

```javascript theme={null}
const { ucc, link } = await window.Cello("getActiveUcc");
```

### Returns

**activeUcc** `object`

The active ucc object:

**properties**

**ucc** `string`

Active unique campaign code or referral code for the current logged-in user

**link** `string`

Personal invite link for the current logged-in user

## `getCampaignConfig()`

Returns campaign config values for the currently logged-in user.

```javascript theme={null}
const campaignConfig = await window.Cello("getCampaignConfig");
```

### Returns

**campaignConfig** `object`

The campaign config object:

**properties**

**primaryCurrency** `string`

Primary currency code

**revenuePercentage** `number`

Percentage of attributed new revenue that will be paid as a reward

**rewardCap** `number`

Maximum reward that can be earned per referral

**newSignupBonus** `number`

Additional reward for signups to encourage more sharing

**newPurchaseBonus** `number`

Additional reward for purchases to encourage more sharing

**newUserDiscountMonth** `number`

How long new users get a discount

**newUserDiscountPercentage** `number`

The discount new users get

## `getLabels()`

Returns select labels used in our Referral Component.

```javascript theme={null}
const labels = await window.Cello("getLabels");
```

### Returns

**labels** `object`

The labels object:

**properties**

**customLauncher** `string`

A welcome text useful for building custom launchers

## `getUnreadEventCounts()`

Returns the unread counts for the currently logged-in user, the same counts that drive the Cello [notification badge](https://docs.cello.so/guides/user-experience/referral-notifications-and-emails.md#alert-and-badge).

Use it to read the counts once, e.g. when your launcher renders. To be notified when they change, use the [`onUnreadCountChanged`](#cello-boot-options) boot option.

```javascript theme={null}
const counts = await window.Cello("getUnreadEventCounts");
```

### Returns

**counts** `object`

The unread counts:

**properties**

**badgeCount** `number`

A number you can show on your own badge, the same value as the `badgeCount` parameter of [`onUnreadCountChanged`](#cello-boot-options). At most 99. Unread views are not counted. Cello's own badge is a dot and doesn't show this number

**views** `number`

Number of unread referral link views

**rewards** `number`

Number of unread rewards

**alerts** `number`

`1` if there is an unseen [alert](https://docs.cello.so/guides/user-experience/referral-notifications-and-emails.md#alert-and-badge), otherwise `0`

**shouldShowBadge** `boolean`

Whether the Cello launcher shows the notification badge right now

### Example

Example below shows a dot badge on your own launcher. To show a number instead, see [Show your own badge](https://docs.cello.so/referral-component/custom-launcher.md#show-your-own-badge).

```javascript theme={null}
const updateBadge = (counts) => {
  const badge = document.getElementById("my-referral-badge");
  badge.hidden = !counts.shouldShowBadge;
};

await window.Cello("boot", {
  // ...other options
  onUnreadCountChanged: (badgeCount, counts) => updateBadge(counts),
});

// In a component that mounts later, read the current counts
updateBadge(await window.Cello("getUnreadEventCounts"));
```

***

## `hide()`

Hides the Cello button or bookmark that launches the Referral Component.

```javascript theme={null}
window.Cello("hide");
```

***

## `open(destination)`

Opens Referral Component.

```javascript theme={null}
window.Cello("open", destination);
```

### Accepts

**destination** `string`

Optional destination string to open Referral Component on a specific tab or page. Without it, Referral Component opens on the invite tab:

* `"rewards"` - open Referral Component on the rewards tab
* `"edit-payments"` - open Referral Component on the payment details page

## `show()`

Shows the Cello button or bookmark that launches the Referral Component.

```javascript theme={null}
window.Cello("show");
```

***

## `showAnnouncement(announcement)`

Triggers an [announcement](https://docs.cello.so/guides/user-experience/referral-notifications-and-emails.md#announcement).

```javascript theme={null}
window.Cello("showAnnouncement", announcement);
```

### Accepts

**announcement** `string` *required*

### Example

Example below triggers a default welcome announcement:

```javascript theme={null}
const announcement = { type: "welcome-announcement-1" };
window.Cello("showAnnouncement", announcement);
```

> [!WARNING]
>
> A fulfilled promise from `showAnnouncement` only means the SDK accepted the request. It does **not** mean the announcement is visible to the user.
>
> The announcement is anchored to the element matched by your **Announcement Selector** using `document.querySelector` (first match in DOM order). If that element is hidden, zero-sized, or off-screen, the announcement renders but is invisible. If you see `Promise {<fulfilled>: undefined}` but no announcement, run `document.querySelectorAll("<your selector>")` in the console - the result must be exactly one visible element.
>
> See [Troubleshooting: announcement not showing](https://docs.cello.so/referral-component/custom-launcher.md#troubleshooting-announcement-not-showing) for the full diagnostic flow.

## `shutdown()`

Shuts down connection to Cello and unmounts the Referral Component.

```javascript theme={null}
window.Cello("shutdown");
```

***

## `updateProductUserDetails(productUserDetails)`

Updates user details at runtime without re-initializing the Referral Component.

```javascript theme={null}
window.Cello("updateProductUserDetails", productUserDetails);
```

### Accepts

**productUserDetails** `object` *required*

The product user details object

**properties**

**email** `string` *required*

Email of the product user. This data is used in the personalization of the referral
experience, e.g. email notifications. Required for select features

**firstName** `string` *required*

First name of the product user.
This data is used in the personalization of the referral experience, e.g. email notifications and the [personalized message to referees](https://docs.cello.so/docs/add-personalized-message.md).
Required for select features

**lastName** `string`

Last name of the product user

**fullName** `string`

Full name of the product user.
Use this option if you do not have first name and last name separately.

### Example

```javascript theme={null}
const productUserDetails = {
  email: "bob@gmail.com",
  firstName: "Bob",
  lastName: "Bobsky",
  fullName: "Bob Bobsky",
};
window.Cello("updateProductUserDetails", productUserDetails);
```

***

## Content Security Policy (CSP)

Most applications don't need any changes here. This section only applies if your site enforces a Content Security Policy - if you don't set CSP headers, or your policy is permissive, you can skip it.

The Cello Referral Component loads its script and assets from Cello domains at runtime. If your policy is restrictive, extend it with the following sources so the Referral Component can load and run:

```text theme={null}
script-src  https://assets.cello.so
connect-src https://share.cello.so
img-src     https://cdn.cello.so https://p.typekit.net blob: data:
style-src   https://use.typekit.net https://p.typekit.net 'unsafe-inline'
font-src    https://use.typekit.net https://p.typekit.net
```

> [!NOTE]
>
> * These directives extend your existing policy; if you use a restrictive `default-src`, keep all of the above explicit.
> * Sandbox environments use the equivalent `*.sandbox.cello.so` domains (for example `https://assets.sandbox.cello.so` and `https://share.sandbox.cello.so`).

If the Referral Component fails to load and your browser console shows errors like `Refused to connect because it violates the document's Content Security Policy`, see [Troubleshooting](https://docs.cello.so/referral-component/quickstart.md#troubleshooting) in the Referral Component quickstart.

### Nonce-based policies

If your `style-src` or `script-src` contains a `'nonce-...'` source, browsers ignore `'unsafe-inline'`. The Referral Component then cannot apply its styles and renders without them. Pass the nonce of the current response to `boot` instead, and put it on the two script tags as well:

```html theme={null}
<script type="module" src="https://assets.cello.so/app/latest/cello.js" async nonce="{{ nonce }}"></script>

<script nonce="{{ nonce }}">
  window.cello = window.cello || { cmd: [] };
  window.cello.cmd.push(async function (cello) {
    await cello.boot({
      productId: "CELLO_PRODUCT_ID",
      token: "REPLACE_ME",
      nonce: "{{ nonce }}",
      // ...the rest of your options
    });
  });
</script>
```

The Referral Component puts the nonce on every style it creates and on the font stylesheet it loads. `'unsafe-inline'` is no longer needed in `style-src`; keep the Cello and Typekit hosts listed above. Pass a fresh nonce on every page load. A nonce reused across responses defeats the policy.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.