# Churn Deflection Object ✨

A Churn Deflection instance is used used to control and integrate deflection pages (opens new window) during subscription cancellation flows.

Create a churnDeflection object using the chargebee object to use the functions listed below.

Previous Version

The earlier version of Churn Deflection was delivered via Brightback.js, which has since been deprecated. You can still view the documentation (opens new window) for reference.

# Attach the cancellation handler

# attachCancelHandler()

Attaches a click handler to the cb‑cancel element to initialize the churn deflection flow.

DOM element required

There must be a DOM element with the id cb‑cancel on the page for this function to work. This element is typically an anchor element (<a>) with an href attribute, that initiates the cancellation flow.

# How it works

# 1. Request the deflection page URL

Sends options to Chargebee and stores the returned deflection page URL.

# 2. Attach the click handler

  1. Finds the DOM element with the id cb‑cancel.
  2. Registers a click listener that:
    • Redirects to the deflection page URL, if one was obtained and stored in the previous step.
    • Otherwise, as a fallback, redirects to the element’s href value, if present.

# Example

churnDeflection.attachCancelHandler({
  account: {
    customerId: "16CRibUdE6pV6HoU",
    firstPurchaseDate: "2024-06-26"
  },
  externalUserId: "jane_doe",
  firstName: "Jane",
  lastName: "Doe",
  saveReturnUrl: "https://app.yourcompany.com/save?id=jane_doe",
  cancelConfirmationUrl: "https://app.yourcompany.com/cancel_confirm?id=jane_doe",
  custom: {
    emailCount: 4208
  }
});
1
2
3
4
5
6
7
8
9
10
11
12
13
14

# Parameters

account
Object View properties
Details about the customer or user account.
subcription
Object Required View properties
Details about the subscription.
firstName
String
The first name of the customer or user.
lastName
String
The last name of the customer or user.
fullName
String
The full name of the customer or user.
email
String
The email address of the customer or user.
externalUserId
String
The customer's or user's unique ID in your system.
saveReturnUrl
String
The URL to redirect the user to after they click Never mind.
cancelConfirmationUrl
String
The URL to redirect the user to when they click the Cancel CTA.
custom
Object
An object containing one or more custom fields defined in the Chargebee Retention dashboard.

# Returns

None.

# Get a churn deflection page

# getPage()

Requests a churn deflection page URL from Chargebee.

This function sends options to Chargebee and the returned promise (opens new window) resolves with the URL of the churn deflection page.

# Example

function bindLink(id, url) {
    document.getElementById(id).addEventListener('click', () => {
        window.location.assign(url);
    });
}

churnDeflection.getPage({
  account: {
    customerId: "16CRibUdE6pV6HoU",
    firstPurchaseDate: "2024-06-26"
  },
  externalUserId: "jane_doe",
  firstName: "Jane",
  lastName: "Doe",
  saveReturnUrl: "https://app.yourcompany.com/save?id=jane_doe",
  cancelConfirmationUrl: "https://app.yourcompany.com/cancel_confirm?id=jane_doe",
  custom: {
    emailCount: 4208
  }
}).then((result) => {
  if (result.valid) {
    //Do any additional processing here.
    bindLink('cancel-btn', result.url);
  } else {
    //Read and process result.errorMessage or redirect to cancellation page: 
    bindLink('cancel-btn', 'https://app.yourcompany.com/cancel?id=jane_doe');
  }
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28

# Parameters

account
Object View properties
Details about the customer or user account.
subcription
Object Required View properties
Details about the subscription.
firstName
String
The first name of the customer or user.
lastName
String
The last name of the customer or user.
fullName
String
The full name of the customer or user.
email
String
The email address of the customer or user.
externalUserId
String
The customer's or user's unique ID in your system.
saveReturnUrl
String
The URL to redirect the user to after they click Never mind.
cancelConfirmationUrl
String
The URL to redirect the user to when they click the Cancel CTA.
custom
Object
An object containing one or more custom fields defined in the Chargebee Retention dashboard.

# Returns

A promise that resolves to an object with the following properties:

valid
Boolean

true: Indicates that the churn deflection page was successfully generated. See url.

false: Indicates that the churn deflection page was not generated. See errorMessage.

url
String
The URL of the generated churn deflection page. Returned only when valid is true.
errorMessage
String
A message describing the reason why the churn deflection page failed to be generated. Returned only when valid is false.