Referral Component

What is it?

The Cello Referral Component is a Javascript library that you can use to connect your logged-in users to the referral experience of your product. It facilitates communication between your application and Cello and adds the Cello Referral Component and entry widgets to your page.

The library is a Javascript library that is meant to run on a browser. As such, it will work with all web frameworks whose end product is HTML/Javascript. That includes React, Next.js, Vue, Angular etc. (for SSR supporting frameworks like Next.js, the limitation is that interacting with Cello needs to happen on the browser and not server side).

By default, the action button and component will appear in the upper right corner and will look something like this:

How does it work?

In order to make your page work with the Referral Component, you need to follow these steps:

  1. Make your page download our Javascript bundle from our CDN, which includes the Referral Component.
  2. Have your product ID and product secret handy. You can get them from your Cello product dashboard on the Access Keys page
  1. Create a Cello JWT token to connect the logged-in user and your page to Cello.
  2. Initialize the library with the token.

1. Download the bundle

Below is an example of how to download the Referral Library javascript bundle from our CDN.

In the example, the javascript tag is being loaded asynchronously, meaning it does not block your page from rendering other components and can be included in any part of your website. This is the recommended way of downloading the app, especially if SEO score is important for your page.

Once the bundle is loaded, it registers the library and is ready to be consumed by your javascript code.

To add the Cello Referral Component from CDN, use the following script in the head tag of your index.html

Sandbox Script CDN URL

Javascript
Copy

Production Script CDN URL

Javascript
Copy

2. Create a token

In order to connect your customer's session to Cello and to securely communicate with Cello, you will need to create a JWT token to authenticate to Cello. The token will certify to Cello that it is your application and also provides the user's identity, making it possible to create a referral link unique to your user.

Minting a JWT token should always be done on your backend code and not on browser side.

👉 See details in User Authentication

3. Initialize the library

It requires one call to download the Cello Referral Library to initialize it.

In the initialization call, you tell Cello your product ID, created token, and configuration parameters on how you want the Referral Library to behave.

You do not have to wait and check whether the library has been loaded in point 1. In the below example, you can see a mechanism we provide to handle that particular race condition, so you can work with the window.cello object. If you are sure that the code is called later than the library is downloaded, then you can talk to the window.Cello("boot"... command directly.

User details such as email and first name are required for fraud detection, features like email notifications, and the new user banner.

Javascript
Copy

If you are experiencing issues integrating the Referral component, check out common errors and ways to mitigate them in the Troubleshooting guide

What does the library do to your web application?

After downloading the bundle

  1. It registers window.Cello which allows your web page code to communicate to Cello.
  2. It grabs all calls you may have already made via the window.cello.cmd array, executes them, and reassigns window.Cello to our own proxy so that calls to it will also continue working.

After initialization (boot command)

  1. Depending on your calls, it alters your web page by adding a Cello button or connecting your button or menu item to display the Referral Component.
  2. It also creates the session that will be calling your defined callbacks or allows you to start communicating to Cello via window.Cello.

Referral Library SDK

Below is the full list of commands with which you can call the Cello Referral Library.

Note that the above mentioned window.cello.cmd mechanism does work but is unnecessary for any other reason than initial calls where you may not be sure if your code is executed before the library is loaded. It is recommended to just call the methods via window.Cello

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.

NameTypeDescriptionRequired
productIdstringIdentifier of the product your users will refer. You can obtain this in your Cello Portal.Required
productUserCountryCodestringProduct user country, if known. ISO 3166 Alpha-2 standard. If the user is from an unsupported country, the Cello Referral Component will not be booted for this user and an error will be returned. If no country is passed, Cello will still be booted. Example: DE
tokenstringAccess token generated for the given user. More in User Authentication.Required
hideDefaultLauncherbooleanShow or hide the Cello button, launching the Referral Component when it's first booted. Default: false
productUserDetails.emailstringEmail of the product user. This data is used in the personalization of the referral experience, e.g. email notifications.Recommended for feature functionality
productUserDetails.firstNamestringFirst 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.Recommended for feature functionality
productUserDetails.lastNamestringLast name of the product user
productUserDetails.fullNamestringFull name of the product user. Use this option if you do not have first name and last name separately.
languagestringThe 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.
onOpen: () => { your code }functionCallback event for when Referral component widget is opened.
onClose: () => { your code },functionCallback event for when Referral component widget is closed.
Javascript
Copy

shutdown()

Shuts down connection to Cello and unmounts the component

Javascript
Copy

show()

Shows the Cello button or bookmark that launches the Referral Component

Javascript
Copy

hide()

Hides the Cello button or bookmark that launches the Referral Component

Javascript
Copy

open()

Opens the Referral Component

Javascript
Copy

open(destination)

Opens the referral component on a specific tab / page

Javascript
Copy

destination = "rewards"|"edit-payments"

  • rewards - open referral component on rewards tab
  • edit-payments - open referral components on the payment details page

close()

Closes Referral Component

Javascript
Copy

updateProductUserDetails

Updates user details at runtime without re-initialising the component.

Javascript
Copy

changeLanguage(language)

Changes the language of the Referral component at runtime without re-initialising component

New since 21 Dec 2022
Deprecated
Copy

getActiveUcc()

A method to get an active ucc and invite link for the currently logged in user.

Javascript
Copy

Returns

  • ucc - active unique campaign code or referral code for the current logged in user
  • link - personal invite link for the current logged in user

showAnnouncement()

A method to trigger an announcement. Example below will trigger the default welcome announcement:

Javascript
Copy

getCampaignConfig()

A method to get campaign config values for the currently logged in user.

Javascript
Copy

Returns

  • primaryCurrency - primary currency code
  • revenuePercentage - percentage of attributed new revenue that will be paid as a reward
  • rewardCap - maximum reward that can be earned per referral
  • newSignupBonus - additional reward for signups to encourage more sharing
  • newPurchaseBonus - additional reward for purchases to encourage more sharing
  • newUserDiscountMonth - how long new users get a discount
  • newUserDiscountPercentage - the discount new users get

getLabels()

Returns select labels used in our Referral Component

Javascript
Copy

Returns

  • customLauncher - a welcome text useful for building custom launchers

Controlling access to Referral component

If you want to enable the Cello referral component only to selected users or control its visibility dynamically, we provide the following options:

a. Named user whitelist

During the new referral program rollout with Cello, you may want to pilot with a small cohort of selected users. This can be achieved using our Named user whitelist. All you need to do is to provide a list of selected users UID's (productUserId's) to Cello. After they are added to the whitelist, only these users will have access to the Referral component until you are ready to rollout to your entire user base.

b. Show / Hide Referral component conditionally

To control dynamically when and who sees the Referral component, you can also use show() and hide(). methods. For example, you may decide to only show the Referral component after the user has completed onboarding. In that case, when a user first logs in, boot the component with showOnBoot = false and after onboarding is complete, use cello.show() to show the Cello button.

You can automatically open the Cello widget with a link to your product by adding a param ?cello-open=true to your URL.

Add a link to the referral component to your email communication to help your users access the sharing options directly from the email.

💡 Tip: If on sign-in the user is redirected between URL's, remember this parameter and then reattach it the final URL the user should end up on to automatically launch the Cello Referral Component.

HTML
Copy
HTML
Copy
HTML
Copy
Type to search, ESC to discard
Type to search, ESC to discard
Type to search, ESC to discard