More Tutorials

In-app Offers Quickstart

Chargebee.js
Growth

Personalized Offers enable contextual upselling by displaying dynamic upgrade suggestions based on customer behavior, subscription data, and targeting rules. You can initialize the experience by passing customer and subscription identifiers into the Chargebee JavaScript SDK. The offers returned include predefined content blocks and call-to-action options that trigger billing updates, hosted checkouts, or redirects. Engagement events such as views and dismissals are also tracked to refine your targeting strategies.

Integration guide

Follow the steps below to set up Personalized Offers using Chargebee.js.

Prerequisites

Before integrating the SDK, you must define the offers to be displayed. Create and activate plays in the Chargebee Growth dashboard. Each play you create must be activated to be available for display in your application.

Integrate Chargebee.js

1. Load Chargebee.js

Load Chargebee.js by adding the following script to the global <head>.

<script src="https://js.chargebee.com/v2/chargebee.js"></script>

2. Initialize Chargebee.js

Once the page loads, initialize Chargebee.js with your Chargebee site subdomain name to enable the use of the SDK.

const chargebee = window.Chargebee.init({
   site: "YOUR-CHARGEBEE-SUBDOMAIN",
})

3. Create the Personalized Offers object

Use the personalizedOffers() function to instantiate Personalized Offers.

const personalizedOffers = await chargebee.personalizedOffers();

4. Initialize the Personalized Offers experience

Call the init() function to register the user context and prepare the offers for display.

personalizedOffers.init({
  account: {
    customerId: "16CRibUdE6pV6HoU"
  },
  externalUserId: "jane_doe",
  firstName: "Jane",
  lastName: "Doe",
  roles: ['sales-manager'],
  locale: "fr-FR",
  custom: {
    viewCount: 6
  }
});

You're all set, no further steps are needed! Chargebee now processes the user interactions and automatically renders eligible offers on the page based on your play configuration.

JS API reference

See the Personalized Offers JS API reference for more details.

Was this tutorial helpful ?
Need more help?

We're always happy to help you with any questions you might have! Click here to reach out to us.