Chargebee Integration

Integrate your Refersion and Chargebee accounts

Andre Tan avatar
Written by Andre Tan
Updated over a week ago

Chargebee is a powerful subscription billing platform that integrates with Refersion to help boost sales generated by your affiliate marketing program. Once integrated any affiliate orders generated from your Chargebee platform will be tracked in Refersion.

Chargebee can integrate with your store in a few different ways, and the specifics of your setup will determine how you’ll integrate your store with Refersion.

Check the Chargebee support docs here for full coverage, but in brief these are the three different ways you might be integrated with Chargebee:

  1. In-App checkout via Drop-in script:
    If your site has checkout buttons allowing customers to checkout on your site via a lightbox, then you’re using Chargebee’s drop-in script.

  2. Checkout via Hosted Pages API:
    If your site has custom JavaScript that programmatically calls Chargebee’s API to start the checkout process, then you’re using Chargebee’s Hosted Pages API checkout.

  3. Single Page Checkout (legacy):
    If customers are redirected in the browser to a full page checkout (not in a lightbox), you’re using the legacy Single Page Checkout.

    Please note: As of February 2018 Chargebee is no longer offering the single-page hosted checkout option for customers, and we do not have integration steps for this deprecated option

Keep your particular set up in mind as you proceed with the integration instructions below.

Step 1 - Tracking clicks on your site

In order to track the clicks when affiliates refer customers to your site, you’ll need to add a small snippet of JavaScript code.

First, you’ll need your public key, secret key and subdomain from your Refersion account - see how to get them here. Keep these handy as you’ll need them again in later steps.

Next, you’ll need to copy/paste the below code into the header (<head>) section of your website - replacing the words “SUBDOMAIN” and “PUBLIC_KEY” with your subdomain and public key that you just grabbed from Refersion.

<script src="//"></script>
<script>_refersion(function(){ _rfsn._setSource("CHARGEBEE"); });</script>

Step 2: Configure webhook tracking in Chargebee

This step allows Chargebee to send order data to Refersion utilizing a webhook. To set it up, log in to your Chargebee account and navigate to Settings > Configure Chargebee > Webhooks.

Once there, click “New Webhook” and give it a name. You’ll then need to copy/paste the below URL into Chargebee - like above, first replacing “PUBLIC_KEY” and “SECRET_KEY” with the values you grabbed from Refersion.

Change the 'Event to Send' field to 'Payment Succeeded', and you're all set. Check out the image below to get an idea of what your settings will look like:

Click Create to save your webhook.

Step 3: Add the Refersion tracking attribute

As mentioned above, how you’ve set up your Chargebee account will determine which of the below to follow.

If you’re using the Drop-in script:

In the header script provided by Chargebee, add the attribute data-cb-refersion-enabled="true" inside of the script tag. Check out this example:

<script src="" data-cb-site="your-site" data-cb-refersion-enabled="true"></script>

If you’re using the Hosted Pages API:

In the script used to initialize your Chargebee instance, add the enableRefersionTracking parameter to the init() options and set a value of true. Here is an example:

$( document ).ready(function() {
var chargebeeInstance = Chargebee.init({
site: "your-site",
enableRefersionTracking: true

When using the Chargebee API set up, once this step is complete you can move directly to step 5.

Step 4: Whitelist your domain in Chargebee

If you have not done so already, you'll need to whitelist your domain in Chargebee in order to track conversions via the lightbox without a thank you page or when using the hosted pages API.

In your Chargebee account, go to Settings. Then navigate to Configure Chargebee > Checkout & Self Serve Portal:

Navigate to Advanced Settings > Add Domains:

Add your site:

Click Apply and then Publish on the top of the page to save the whitelisted domain that you have added.

When using the Chargebee API set up, once this step is complete you can move directly to step 6.

Step 5: Add conversion tracking to your thank you page

If you’ve configured a thank you page Redirect URL for your Chargebee Plans, you’ll need to update the Chargebee Plans to be compatible with Refersion tracking.

In Chargebee, navigate to Product Catalog > Plans. For each Plan, click “Edit Plan” and add the following URL parameter to the Redirect URL: ?rfsn_ci={{}}, as seen below:

Once you’ve added the URL parameter to all Plans, copy/paste the below script - first replacing SUBDOMAIN and PUBLIC_KEY with your own values as described above - on your thank you page(s).

<script src="//"></script>
<script>function rfsn_getQS(e){e=e.replace(/[\[]/,"\\[").replace(/[\]]/,"\\]");var t=new RegExp("[\\?&]"+e+"=([^&#]*)"),n=t.exec(;return n==null?"":decodeURIComponent(n[1].replace(/\+/g," "))}
if (rfsn_getQS('rfsn_ci')) {

Step 6: Run a Test Order

Run a test order to make sure everything is tracking properly. Please note that your test order MUST include a paid charge. Chargebee only sends payment succeeded events into Refersion for conversion tracking, so free trials will not be reported as conversions.

If you have any issues, then please reference our help article on troubleshooting your Chargebee integration. You can also chat with us from your Refersion dashboard or send us an email.

Did this answer your question?