Skip to content

Retention Flow (Cancel Button)

The cancel button is the quickest way to get started with the Renumerate Retention Engine. The cancel button will render a button to the container and manage the entire retention workflow.

You can display the retention modal in two ways:

  1. Using the Cancel Button:
    The mountCancelButton function automatically handles the retention workflow when the button is clicked. This is the simplest way to integrate the retention modal.
renumerate.mountCancelButton("elementId", "sessionId", "classes");
  1. Directly Invoking the Retention View:
    If you want more control over when and where the retention modal appears, you can use the showRetentionView function. This allows you to trigger the modal programmatically.
renumerate.showRetentionView("sessionId");
keytypenotes
elementIdstringThe id for the container element
sessionIdstringYour customer’s session id
classesstring | undefinedButton classes (optional)

For React applications, Renumerate provides components and hooks that integrate seamlessly with your existing React workflow.

All Renumerate React components must be wrapped in a RenumerateProvider to access the Renumerate instance:

import React from 'react';
import { RenumerateProvider, CancelButton } from '@renumerate/js/react';
function MyComponent() {
const sessionId = "ret_example123";
// Get this from your backend
// The "Generating a Retention Session Id" section will show you how
return (
<RenumerateProvider config={{ publicKey: 'your-public-key' }}>
{/* Default styled cancel button */}
<CancelButton sessionId={sessionId} />
{/* Custom styling cancel button */}
<CancelButton
sessionId={sessionId}
className="bg-red-500 hover:bg-red-600 text-white px-6 py-2 rounded-lg font-medium transition-colors"
/>
</RenumerateProvider>
);
}

For more control over when and how the retention flow is triggered, use the useRenumerate hook:

import React from 'react';
import { RenumerateProvider, useRenumerate } from '@renumerate/js/react';
function CustomCancelComponent({ sessionId }: { sessionId: string }) {
const { open } = useRenumerate({ sessionId });
const handleCancelClick = () => {
// You can add custom logic here before opening the retention flow
if (confirm('Are you sure you want to cancel your subscription?')) {
open();
}
};
return (
<button
onClick={handleCancelClick}
className="cancel-subscription-btn"
>
Cancel My Subscription
</button>
);
}
function App() {
const sessionId = "ret_example123";
return (
<RenumerateProvider config={{ publicKey: 'your-public-key' }}>
<CustomCancelComponent sessionId={sessionId} />
</RenumerateProvider>
);
}

Retention sessions allow you to present a retention workflow when a customer goes to cancel their subscription. This sessionId can be passed into the showRetentionView or cancelButton functions.

Retention sessions begin with ret_

To generate a customer’s session ID, make a POST request to https://api.renumerate.com/v1/retention/session from your application’s backend.

Ensure the following:

  1. Include the X-Brand-Key header with your Brand’s private key for authentication. See the Where To Find Private Key section.
  2. Pass the customer’s ID and any other required parameters in the request body as specified by the API documentation.

This process securely creates a session ID for the customer cancellation flow.

Request Body Parameters:

When generating a retention session, you must include either the customer_id or customer_email (or both). Below is a table of all available parameters:

keytypenotes
retentionobject
retention.customer_idstring | undefinedYour stripe customerId
retention.customer_emailstring | undefinedThe customer’s email address in stripe
retention.subscription_idstring | undefinedThe specific subscription id (optional)

Node.js/TypeScript

const privateKey = process.env.RENUMERATE_PRIVATE_KEY;
const requestBody = {
retention: {
customer_id: "cus_NffrFeUfNV2Hib", // Example stripe id
subscription_id: "sub_1MowQVLkdIwHu7ixeRlqHVzs", // Your specific subscription
},
};
const response = await fetch("https://api.renumerate.com/v1/retention/session", {
method: "POST",
headers: {
"Content-Type": "application/json",
"X-Brand-Key": privateKey,
},
body: JSON.stringify(requestBody),
});
const {
session: { id },
} = await response.json();