> ## 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.

# Custom Launcher

> Learn how to implement your own button to open Referral Component and display notifications.

The Cello custom launcher allows you to open the Referral Component from any element that you want to use. **It can be a button, a menu item, a link and you can use multiple places that open Cello Referral Component**. Additionally, you can choose to open it either in a popup or modal view.

![Custom launcher integration showing referral component embedded in application menu](https://mintcdn.com/cello/6Zr08teY9AER0ncF/referral-component/referral-component-custom-launcher.png?fit=max\&auto=format\&n=6Zr08teY9AER0ncF\&q=85\&s=aec285ec2a31c0e90417f957045b4060)

> [!WARNING]
>
> **Critical Requirements for Custom Launchers:**
>
> * The custom launcher element **MUST exist in the DOM before Cello initializes**
> * The element **MUST have `position: relative` styling**
> * You **MUST configure the selector in Cello Portal** to match your element
> * Cello does **NOT automatically rescan the DOM** for new elements after initialization

> [!TIP]
>
> If your launcher can't be in the DOM before Cello initializes, or you want the badge and announcement to match your own design, you can draw them in your own components. See [Build your own badge and announcement](#build-your-own-badge-and-announcement).

## Implementation Guide

### Step 1: Create your launcher element

Create an HTML element that will trigger the Referral Component. The element must:

1. Exist in the DOM **before** `cello.boot()` is called
2. Have `position: relative` CSS styling
3. Use a unique identifier (ID, class, or attribute)

> [tab] React
>
> ```jsx theme={null}
> // ❌ WRONG: Element created after Cello initialization
> function MyComponent() {
>   const [celloReady, setCelloReady] = useState(false);
>
>   useEffect(() => {
>     initializeCello(); // Initializes Cello
>     setCelloReady(true);
>   }, []);
>
>   return (
>     <>
>       {celloReady && (
>         <button id="cello-launcher">Invite</button> // Too late!
>       )}
>     </>
>   );
> }
>
> // ✅ CORRECT: Element exists before Cello initialization
> function MyComponent() {
>   const [celloReady, setCelloReady] = useState(false);
>
>   useEffect(() => {
>     // Element already exists in DOM
>     initializeCello(); // Now initialize Cello
>     setCelloReady(true);
>   }, []);
>
>   return (
>     <>
>       <button 
>         id="cello-launcher"
>         style={{ 
>           position: 'relative',
>           display: celloReady ? 'block' : 'none' 
>         }}
>       >
>         Invite Friends
>       </button>
>     </>
>   );
> }
> ```

> [tab] HTML
>
> ```html theme={null}
> <!-- Element with ID selector -->
> <button id="cello-launcher" style="position: relative;">
>   Invite Friends
> </button>
>
> <!-- Element with class selector -->
> <button class="cello-custom-launcher" style="position: relative;">
>   Share & Earn
> </button>
>
> <!-- Element with attribute selector -->
> <button data-cello-launcher="true" style="position: relative;">
>   Refer Now
> </button>
> ```

> [tab] Vue
>
> ```vue theme={null}
> <template>
>   <!-- Element always rendered, visibility controlled by CSS -->
>   <button 
>     id="cello-launcher"
>     :style="{ 
>       position: 'relative',
>       display: celloInitialized ? 'block' : 'none' 
>     }"
>   >
>     Invite Friends
>   </button>
> </template>
>
> <script>
> export default {
>   data() {
>     return {
>       celloInitialized: false
>     }
>   },
>   mounted() {
>     // Element already exists in DOM
>     this.initializeCello().then(() => {
>       this.celloInitialized = true;
>     });
>   }
> }
> </script>
> ```

> [tab] Angular
>
> ```typescript theme={null}
> // ❌ WRONG: Element created after Cello initialization
> @Component({
>   selector: 'app-my-component',
>   template: `
>     <button *ngIf="celloReady" id="cello-launcher">
>       Invite
>     </button> <!-- Too late! -->
>   `
> })
> export class MyComponent implements OnInit {
>   celloReady = false;
>
>   ngOnInit() {
>     this.initializeCello();
>     this.celloReady = true; // Button appears after Cello init
>   }
> }
>
> // ✅ CORRECT: Element exists before Cello initialization
> @Component({
>   selector: 'app-my-component',
>   template: `
>     <button 
>       id="cello-launcher"
>       [style.position]="'relative'"
>       [style.display]="celloReady ? 'block' : 'none'"
>     >
>       Invite Friends
>     </button>
>   `
> })
> export class MyComponent implements OnInit {
>   celloReady = false;
>
>   async ngOnInit() {
>     // Element already exists in DOM (hidden)
>     await this.initializeCello();
>     this.celloReady = true; // Now show the button
>   }
>
>   async initializeCello() {
>     // Initialize Cello here
>     window.cello = window.cello || { cmd: [] };
>
>     window.cello.cmd.push(async (cello) => {
>       try {
>         await cello.boot({
>           productId: "YOUR_PRODUCT_ID",
>           token: "YOUR_JWT_TOKEN",
>           // ... other configuration
>         });
>         console.log('Cello initialized successfully');
>       } catch (error) {
>         console.error('Failed to initialize Cello:', error);
>       }
>     });
>   }
> }
> ```

### Step 2: Configure Cello Portal

1. Navigate to [User experience → Widget in Cello Portal](https://app.cello.so/user-experience/component)
2. Set the **Custom Launcher Selector** to match your element:
   * For ID: `#cello-launcher`
   * For class: `.cello-launcher`
   * For attribute: `[cello-launcher]`

![Cello Portal configuration for custom launcher selector settings](https://mintcdn.com/cello/6Zr08teY9AER0ncF/referral-component/referral-component-custom-launcher-portal-customer-launcher-selector.png?fit=max\&auto=format\&n=6Zr08teY9AER0ncF\&q=85\&s=ba237d88d8f1f629726fed8e409dcfcc)

### Step 3: Initialize Cello

After the custom launcher element exists in the DOM, initialize Cello:

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

window.cello.cmd.push(async (cello) => {
  try {
    await cello.boot({
      productId: "YOUR_PRODUCT_ID",
      token: "USER_JWT_TOKEN",
      // ... other configuration
    });
    
    console.log("Cello initialized successfully");
    // Custom launcher is now active
  } catch (error) {
    console.error("Failed to initialize Cello:", error);
  }
});
```

## Common Issues and Solutions

### Custom launcher not working

> [accordion] Element doesn't exist when Cello initializes
>
> **Problem:** The custom launcher element is created after Cello has already initialized.
>
> **Solution:** Ensure the element exists in the DOM before calling `cello.boot()`. In React/Vue, render the element with `display: none` initially, then show it after initialization.
>
> **Alternative:** Open the Referral Component from your own click handler, so the element doesn't need to exist when Cello initializes. See [Open the Referral Component from your own launcher](#open-the-referral-component-from-your-own-launcher).

> [accordion] Missing position: relative
>
> **Problem:** The element doesn't have `position: relative` styling.
>
> **Solution:** Add `style="position: relative"` to your launcher element. This is required for Cello to properly attach event handlers.

> [accordion] Selector mismatch or selector matches multiple elements
>
> **Problem:** The selector in Cello Portal doesn't match your element, or matches several elements where only one is visible.
>
> **Solution:** Verify the exact selector format:
>
> * ID selectors need `#` prefix: `#my-launcher`
> * Class selectors need `.` prefix: `.my-launcher`
> * Attribute selectors need brackets: `[my-attribute]`
>
> Also verify uniqueness - Cello uses `document.querySelector` and picks the **first match** in DOM order. Run `document.querySelectorAll("<your selector>")` in the browser console: it should return exactly one visible element with a non-zero bounding box. If multiple elements match (for example, a wrapper `<li>` and an inner `<span>` share the same class), Cello will use the first one, which may be invisible. Either narrow the selector with a parent prefix or use an `id`. See [Troubleshooting: announcement not showing](#troubleshooting-announcement-not-showing) for the same diagnostic flow applied to announcements.

> [accordion] Dynamic elements in SPAs
>
> **Problem:** In single-page applications, elements are dynamically added/removed.
>
> **Solution:** Keep the launcher element persistent in the DOM, use CSS to control visibility instead of conditional rendering.
>
> **Alternative:** Open the Referral Component from your own click handler, so the element can mount and unmount freely. See [Open the Referral Component from your own launcher](#open-the-referral-component-from-your-own-launcher).

## Add reward in launcher

1.5x activation rate

3.5x sharing rate

Increase the sharing activity of your users by highlighting the reward directly in the referral launcher inside your menu item.

![Custom launcher displaying reward amount directly in menu item](https://mintcdn.com/cello/6Zr08teY9AER0ncF/referral-component/referral-component-custom-launcher-reward-in-launcher.png?fit=max\&auto=format\&n=6Zr08teY9AER0ncF\&q=85\&s=e0cf4e96b23cbe8ccd7e9f435b51330a)

You can get the text for the menu launcher from [cello.js](https://docs.cello.so/sdk/client-side/cello-js-usage.md#getlabels). Text will be localized to the [referrer's language](https://docs.cello.so/guides/user-experience/overview.md#texts-and-language) and the reward amount is based on the [referrer's campaign](https://docs.cello.so/guides/campaigns/setting-up-campaigns.md).

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

## Disable Cello button

**Cello button** is a floating action button or bookmark style button provided as a default Referral Component launcher. When integrating a Customer Launcher, you may choose to disable the Cello button or keep it as an additional launcher.

![Default Cello floating action button launcher](https://mintcdn.com/cello/6Zr08teY9AER0ncF/referral-component/referral-component-custom-launcher-cello-button.png?fit=max\&auto=format\&n=6Zr08teY9AER0ncF\&q=85\&s=74ec433ad1b4bf6753a56cb65de816f1)

You can choose to disable the default launcher, the Cello button. Go to [User experience → Widget](https://app.cello.so/user-experience/component) settings in Cello Portal and **uncheck** "Show Cello Button".

![Configuration to disable default Cello button and use custom launcher](https://mintcdn.com/cello/6Zr08teY9AER0ncF/referral-component/referral-component-custom-launcher-disable-cello-button.png?fit=max\&auto=format\&n=6Zr08teY9AER0ncF\&q=85\&s=b9139513f53b3c7dea15fc4048967cae)

## Configure notification badge

![Notification badge attached to custom launcher showing unread updates](https://mintcdn.com/cello/6Zr08teY9AER0ncF/referral-component/referral-component-custom-launcher-notification-badge.png?fit=max\&auto=format\&n=6Zr08teY9AER0ncF\&q=85\&s=99e2d0249c714d5374e1d4adaf4dceb5)

You can control the behaviour of the [notification badge](https://docs.cello.so/guides/user-experience/referral-notifications-and-emails.md#alert-and-badge), which is attached to your Custom Launcher Selector by default:

> [accordion] Default behavior (clickable with badge)
>
> This is the default behavior - the element opens the Referral Component on click and shows notification badges.
>
> ```html theme={null}
> <!-- Any of these work the same - default behavior -->
> <button id="cello-launcher" style="position: relative;">
>   Invite
> </button>
>
> <button class="my-launcher" style="position: relative;">
>   Share & Earn
> </button>
> ```

> [accordion] Clickable without badge
>
> Add `data-cello-badge="false"` to hide the notification badge while keeping the element clickable.
> Use this when you have multiple launchers but only want badges on some of them.
>
> ```html theme={null}
> <button 
>   id="cello-launcher" 
>   data-cello-badge="false"
>   style="position: relative;"
> >
>   Invite (no badge)
> </button>
> ```

> [accordion] Badge only, non-clickable
>
> Add `data-cello-click="false"` to show the notification badge but prevent clicks from opening the panel.
> Use this to show badge notifications on parent menu items for better visibility.
>
> ```html theme={null}
> <div 
>   class="menu-section"
>   data-cello-click="false"
>   style="position: relative;"
> >
>   <!-- Shows badge but doesn't open panel on click -->
>   Settings Menu
> </div>
> ```

> [accordion] Your own badge, with or without a count
>
> Draw the badge in your own component instead, as a dot or with the number of unread rewards. Cello's own badge is always a dot.
> If Cello still opens the Referral Component from this element, add `data-cello-badge="false"` to hide Cello's badge.
> See [Show your own badge](#show-your-own-badge).

> [!NOTE]
>
> The `data-cello-badge` and `data-cello-click` attributes are **optional modifiers**. If you want the default behavior (clickable with badge), you don't need these attributes at all.

> [!TIP]
>
> **Testing notification badge position**
>
> To trigger a notification badge to be shown on your Custom Launcher simply visit the referral link, of the same user you are testing with, e.g. `moonly.cello.so/pNRB1aYqArN` . A link visit will trigger a [view notification](https://docs.cello.so/guides/user-experience/referral-notifications-and-emails.md#alert-and-badge) and a badge will be displayed.

## Add announcement selector

![Announcement callout anchored to custom launcher element](https://mintcdn.com/cello/6Zr08teY9AER0ncF/referral-component/referral-component-custom-launcher-announcement-selector.png?fit=max\&auto=format\&n=6Zr08teY9AER0ncF\&q=85\&s=18d52b952cfe75d1febe8b5713a6bdd3)

Announcement are callout style notifications used to [communicate important information](https://docs.cello.so/guides/user-experience/referral-notifications-and-emails.md#announcement) to the user if we need to grab their attention and direct them to the Referral Component.

> [!TIP]
>
> To show announcements in your own component instead of Cello's callout, skip the Announcement Selector and see [Show your own announcement](#show-your-own-announcement).

> [!NOTE]
>
> If the Cello button is disabled, the announcement needs to be anchored to one of your Custom Launchers.

Depending on the implementation, the Announcement Selector can be the same as for Custom Launcher, i.e. you can use exactly the same class ID, attribute selector or element ID.

Add this identifier as Announcement Selector under [User experience → Widget in Cello Portal](https://app.cello.so/user-experience/component).

> [!WARNING]
>
> **Critical requirements for Announcement Selector:**
>
> * The selector **MUST resolve to exactly one element** when passed to `document.querySelector`. Cello uses the **first match** in DOM order and does not fall back to siblings.
> * The matched element **MUST be visible and have a non-zero bounding box** at announcement time. `display: none`, `visibility: hidden`, or `width: 0 / height: 0` will cause the announcement to render against an invisible anchor.
> * If multiple elements share the same class or attribute (e.g. a wrapper `<li>` and an inner `<span>` both have `.my-launcher`), narrow the selector with a parent prefix or use an `id`.
> * Verify in the browser console: `document.querySelectorAll("<your selector>")` should return exactly one element with non-zero size. See [Troubleshooting: announcement not showing](#troubleshooting-announcement-not-showing).

![Cello Portal configuration for announcement selector and positioning](https://mintcdn.com/cello/6Zr08teY9AER0ncF/referral-component/referral-component-custom-launcher-portal-announcement-selector.png?fit=max\&auto=format\&n=6Zr08teY9AER0ncF\&q=85\&s=0434a02b46f88982f149c069c1567ca1)

Here you can also configure where you want announcement to be shown relative to the Announcement Selector by specifying **Announcement position** and **Announcement position offset.**

> [!TIP]
>
> **Testing Announcement position**
>
> While choosing Announcement Selector and choosing its position, you will want to see how it looks and make necessary adjustments. You can trigger an [announcement](https://docs.cello.so/guides/user-experience/referral-notifications-and-emails.md#announcement) using [Cello JS](https://docs.cello.so/sdk/client-side/cello-js-usage.md#showannouncement-announcement) `showAnnouncement(announcement)` method.
>
> Example below will trigger the default welcome announcement:
>
> ```javascript theme={null}
> window.Cello("showAnnouncement", { "type": "welcome-announcement-1" })
> ```
>
> A fulfilled promise from `showAnnouncement` only means the SDK accepted the request. It does **not** mean the announcement is visible. If you see `Promise {<fulfilled>: undefined}` in the console but no announcement on the page, see [Troubleshooting: announcement not showing](#troubleshooting-announcement-not-showing).

## Build your own badge and announcement

By default, Cello draws the [notification badge](https://docs.cello.so/guides/user-experience/referral-notifications-and-emails.md#alert-and-badge) and [announcements](https://docs.cello.so/guides/user-experience/referral-notifications-and-emails.md#announcement) on your launcher, using the selectors you set in Cello Portal. You can draw them in your own components instead. [cello.js](https://docs.cello.so/sdk/client-side/cello-js-usage.md) tells you when the unread counts or the active announcement change, and you decide how they look.

This is useful when:

* Your launcher can't be in the DOM before Cello initializes, for example in a single-page app.
* You want the badge and announcement to match your own design system.
* You want to show the number of unread rewards. Cello's own badge is always a dot.

Each part below works on its own, so you can replace only the badge, only the announcement, or the whole launcher.

### Open the Referral Component from your own launcher

Call [`open()`](https://docs.cello.so/sdk/client-side/cello-js-usage#open-destination) from your launcher's click handler. Without a destination, the Referral Component opens on the invite tab. Pass `"rewards"` to open it on the rewards tab instead, for example when your badge shows unread rewards.

```javascript theme={null}
document.getElementById("my-referral-button").addEventListener("click", () => {
  window.Cello("open");
});
```

Cello doesn't need to find this element, so it doesn't have to exist before Cello initializes, and it doesn't need `position: relative` or a Custom Launcher Selector. If you don't want the [Cello button](#disable-cello-button) as an extra launcher, turn it off. To show the reward in your launcher text, use [`getLabels()`](#add-reward-in-launcher).

### Show your own badge

Add [`onUnreadCountChanged`](https://docs.cello.so/sdk/client-side/cello-js-usage#cello-boot-options) to the options of your `cello.boot()` call from [Step 3](#step-3-initialize-cello). It receives two values you can draw your badge from:

* `badgeCount`: the number of unread rewards, otherwise `1` for another unread notification such as an unseen alert, otherwise `0`. It's at most 99. Cello's own badge doesn't show a number, so this is only available through cello.js.
* `counts.shouldShowBadge`: `true` whenever Cello's own badge would show. Unlike `badgeCount`, it also covers new referral link views.

Show a dot, or a number:

```javascript Dot theme={null}
const badge = document.getElementById("my-referral-badge");

await cello.boot({
  // ... other configuration
  onUnreadCountChanged: (badgeCount, counts) => {
    badge.hidden = !counts.shouldShowBadge;
  },
});
```

```javascript Number theme={null}
const badge = document.getElementById("my-referral-badge");

await cello.boot({
  // ... other configuration
  onUnreadCountChanged: (badgeCount) => {
    badge.hidden = badgeCount === 0;
    badge.textContent = badgeCount;
  },
});
```

Cello calls `onUnreadCountChanged` right at boot with every count at `0`, again once notifications have loaded, and then every time a count changes. It can also be called again with the same values. Both examples handle this, because they only set the badge from the values they get. Start with the badge hidden, so the first call with `0` doesn't change anything.

When the user opens the Referral Component, Cello clears the counts and calls `onUnreadCountChanged` again, so your badge hides without extra code.

If your badge mounts after boot, read the current counts with [`getUnreadEventCounts()`](https://docs.cello.so/sdk/client-side/cello-js-usage#getunreadeventcounts). It returns the same values as `counts`, including `badgeCount`, so you can draw the dot or the number right away.

If Cello still opens the Referral Component from this element through the Custom Launcher Selector, add `data-cello-badge="false"` to the element, so Cello doesn't draw its own badge as well. See [Configure notification badge](#configure-notification-badge).

### Show your own announcement

In [User experience → Widget in Cello Portal](https://app.cello.so/user-experience/component), leave the **Announcement Selector** empty and turn off the [Cello button](#disable-cello-button), so Cello has nowhere to draw its own announcement.

Then add [`onAnnouncementChanged`](https://docs.cello.so/sdk/client-side/cello-js-usage#cello-boot-options) to the options of your `cello.boot()` call. Cello calls it with the active announcement, or with `null` when there's nothing to show:

```javascript theme={null}
const box = document.getElementById("my-announcement");
const ctaButton = document.getElementById("my-announcement-cta");

const toPlainText = (html) =>
  new DOMParser().parseFromString(html, "text/html").body.textContent;

const renderAnnouncement = (announcement) => {
  box.hidden = !announcement;
  if (!announcement) return;

  document.getElementById("my-announcement-heading").textContent = announcement.heading;
  document.getElementById("my-announcement-text").textContent = toPlainText(announcement.text);
  ctaButton.hidden = !announcement.ctaLabel;
  ctaButton.textContent = announcement.ctaLabel || "";
  ctaButton.onclick = () => window.Cello("open", announcement.ctaDestination);
};

document.getElementById("my-announcement-close").addEventListener("click", () => {
  window.Cello("dismissAnnouncement");
});

await cello.boot({
  // ... other configuration
  onAnnouncementChanged: renderAnnouncement,
});
```

* The call-to-action opens the Referral Component on the page in `ctaDestination`. That marks the announcement as read, and Cello calls `onAnnouncementChanged` with `null`.
* The close button calls [`dismissAnnouncement()`](https://docs.cello.so/sdk/client-side/cello-js-usage#dismissannouncement), which marks the announcement as read without opening the Referral Component. Cello then calls `onAnnouncementChanged` with `null`.
* `icon` is an optional icon name, `Heart`, `Success` or `Gift`, that you can map to your own icons.

Cello calls `onAnnouncementChanged` with `null` right at boot, then with the announcement once it has loaded, if there is one. It's called again when a new announcement arrives and when its text changes, for example after [`changeLanguage`](https://docs.cello.so/sdk/client-side/cello-js-usage#changelanguage-language).

If your announcement component mounts after boot, read the active announcement with [`getActiveAnnouncement()`](https://docs.cello.so/sdk/client-side/cello-js-usage#getactiveannouncement):

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

> [!NOTE]
>
> `text` can contain `<strong>` tags. The example above shows it as plain text. To keep the bold parts, sanitize `text` first, then insert it as HTML.

You place the announcement yourself, so the Announcement Selector requirements and [Troubleshooting: announcement not showing](#troubleshooting-announcement-not-showing) don't apply.

### Full example

Both versions connect the launcher, a numbered badge and the announcement to one `cello.boot()` call. The React version keeps the latest values from Cello in a small store, so components that mount after boot show the current badge and announcement straight away.

> [tab] HTML
>
> ```html theme={null}
> <button id="my-referral-button" type="button">
>   Invite friends
>   <span id="my-referral-badge" hidden></span>
> </button>
>
> <div id="my-announcement" hidden>
>   <strong id="my-announcement-heading"></strong>
>   <p id="my-announcement-text"></p>
>   <button id="my-announcement-cta" type="button"></button>
>   <button id="my-announcement-close" type="button" aria-label="Dismiss">×</button>
> </div>
>
> <script>
>   const badge = document.getElementById("my-referral-badge");
>   const box = document.getElementById("my-announcement");
>   const ctaButton = document.getElementById("my-announcement-cta");
>
>   const toPlainText = (html) =>
>     new DOMParser().parseFromString(html, "text/html").body.textContent;
>
>   const renderBadge = (badgeCount) => {
>     badge.hidden = badgeCount === 0;
>     badge.textContent = badgeCount;
>   };
>
>   const renderAnnouncement = (announcement) => {
>     box.hidden = !announcement;
>     if (!announcement) return;
>
>     document.getElementById("my-announcement-heading").textContent = announcement.heading;
>     document.getElementById("my-announcement-text").textContent = toPlainText(announcement.text);
>     ctaButton.hidden = !announcement.ctaLabel;
>     ctaButton.textContent = announcement.ctaLabel || "";
>     ctaButton.onclick = () => window.Cello("open", announcement.ctaDestination);
>   };
>
>   document.getElementById("my-referral-button").addEventListener("click", () => {
>     window.Cello("open");
>   });
>
>   document.getElementById("my-announcement-close").addEventListener("click", () => {
>     window.Cello("dismissAnnouncement");
>   });
>
>   window.cello = window.cello || { cmd: [] };
>
>   window.cello.cmd.push(async (cello) => {
>     try {
>       await cello.boot({
>         productId: "YOUR_PRODUCT_ID",
>         token: "USER_JWT_TOKEN",
>         onUnreadCountChanged: renderBadge,
>         onAnnouncementChanged: renderAnnouncement,
>       });
>     } catch (error) {
>       console.error("Failed to initialize Cello:", error);
>     }
>   });
> </script>
> ```

> [tab] React
>
> ```jsx theme={null}
> import { useSyncExternalStore } from "react";
>
> // Keeps the latest values from Cello, so components that mount later can read them
> let celloState = { badgeCount: 0, announcement: null };
> const listeners = new Set();
>
> const setCelloState = (update) => {
>   celloState = { ...celloState, ...update };
>   listeners.forEach((listener) => listener());
> };
>
> const subscribe = (listener) => {
>   listeners.add(listener);
>   return () => listeners.delete(listener);
> };
>
> const getSnapshot = () => celloState;
>
> const useCelloState = () => useSyncExternalStore(subscribe, getSnapshot, getSnapshot);
>
> // Call once, after the user logs in
> export function bootCello(token) {
>   window.cello = window.cello || { cmd: [] };
>
>   window.cello.cmd.push(async (cello) => {
>     try {
>       await cello.boot({
>         productId: "YOUR_PRODUCT_ID",
>         token,
>         onUnreadCountChanged: (badgeCount) => setCelloState({ badgeCount }),
>         onAnnouncementChanged: (announcement) => setCelloState({ announcement }),
>       });
>     } catch (error) {
>       console.error("Failed to initialize Cello:", error);
>     }
>   });
> }
>
> const toPlainText = (html) =>
>   new DOMParser().parseFromString(html, "text/html").body.textContent;
>
> export function ReferralButton() {
>   const { badgeCount } = useCelloState();
>
>   return (
>     <button type="button" onClick={() => window.Cello("open")}>
>       Invite friends
>       {badgeCount > 0 && <span className="referral-badge">{badgeCount}</span>}
>     </button>
>   );
> }
>
> export function ReferralAnnouncement() {
>   const { announcement } = useCelloState();
>   if (!announcement) return null;
>
>   return (
>     <div className="referral-announcement">
>       <strong>{announcement.heading}</strong>
>       <p>{toPlainText(announcement.text)}</p>
>       {announcement.ctaLabel && (
>         <button
>           type="button"
>           onClick={() => window.Cello("open", announcement.ctaDestination)}
>         >
>           {announcement.ctaLabel}
>         </button>
>       )}
>       <button
>         type="button"
>         aria-label="Dismiss"
>         onClick={() => window.Cello("dismissAnnouncement")}
>       >
>         ×
>       </button>
>     </div>
>   );
> }
> ```

### Test your components

> [!TIP]
>
> **Testing your badge and announcement**
>
> * **Badge:** visit the referral link of the user you're testing with, e.g. `moonly.cello.so/pNRB1aYqArN`. The view sets `shouldShowBadge` to `true`, so a dot badge shows. Views don't add to `badgeCount`, so a numbered badge stays hidden until the user has an unread reward or alert.
> * **Announcement:** run `window.Cello("showAnnouncement", { "type": "welcome-announcement-1" })` in your browser console. Cello calls `onAnnouncementChanged` with the welcome announcement.
> * **Clearing:** open the Referral Component from your launcher. Cello clears the counts and the announcement, so both disappear.

## Troubleshooting: announcement not showing

**Short answer:** The most common cause is that your **Announcement Selector** matches more than one element, and the first match in DOM order is invisible (zero-sized, hidden, or off-screen). Cello uses `document.querySelector`, which always picks the first match. Narrow the selector until `document.querySelectorAll(<your selector>)` returns exactly one visible element.

If you'd rather not depend on a selector at all, [show announcements in your own component](#show-your-own-announcement) instead. Cello doesn't position those, so none of this section applies.

### How announcement positioning works

* Cello calls `document.querySelector(<your Announcement Selector>)` once when an announcement is rendered.
* `document.querySelector` returns the **first matching element in DOM order**, not the most visible one.
* The matched element must be present in the DOM, have non-zero width and height, and not be `display: none` or `visibility: hidden` at the moment the announcement renders.
* A fulfilled `showAnnouncement` promise means the SDK accepted the request. It does **not** mean the announcement is visible to the user.
* Cello does not retry, fall back to siblings, or rescan the DOM if the matched element is invisible.

### Symptom: `showAnnouncement` returns a fulfilled promise but nothing appears

If your browser console shows:

```
> window.Cello("showAnnouncement", { "type": "welcome-announcement-1" })
< Promise {<pending>}
    [[PromiseState]]: "fulfilled"
    [[PromiseResult]]: undefined
```

...this only means the SDK accepted the call. The announcement may still be invisible because of the selector resolving to a hidden or zero-sized element.

### Symptom map

| Symptom | What to run in DevTools | What it means | Fix |
| - | - | - | - |
| `showAnnouncement` returns fulfilled promise but no announcement appears | `document.querySelectorAll("<your selector>").length` | If `> 1`, your selector is too broad. Cello picked the first match, which is likely invisible. | Use a more specific selector (add a parent class, or use an `id`). Update **Announcement Selector** in [User experience → Widget](https://app.cello.so/user-experience/component). |
| Announcement renders at the top-left of the viewport (0,0) | `document.querySelector("<your selector>").getBoundingClientRect()` | If width/height is `0`, the matched element has no layout box. | Move the class/attribute to the visible element (icon/button), not a wrapper `<li>` or `<span>`. |
| Announcement renders but is cut off or off-screen | Same as above; check `top` / `left` values | The matched element is off-screen or inside a scrolled container. | Anchor to an in-viewport element, or adjust **Announcement position offset** in the Portal. |
| `querySelectorAll` returns `0` matches | n/a | Element does not exist when the announcement renders, or the selector has a typo. | Confirm the element exists before `cello.boot()`; check `#`, `.`, `[]` prefixes match your element. |
| `querySelectorAll` returns `1` and the element is visible, but still no announcement | Inspect computed styles | The matched element may be missing `position: relative`. | Add `position: relative` to the matched element. |

### Related questions this section answers

* Why does `showAnnouncement` resolve but no announcement appears?
* Why is my Cello announcement invisible?
* Why does my Cello announcement render at the top-left of the screen?
* How do I fix "announcement selector matches multiple elements"?
* Why does Cello pick the wrong element for my announcement?
* Cello announcement not working / not showing / not appearing


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