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 that setup will determine how you’ll integrate your store with Refersion. Check their support docs here, but in brief here 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, you’re using Chargebee’s drop in script.

  2. Checkout via API:
    If your site has custom JavaScript that programmatically calls Chargebee’s API to start the checkout process, you’re using Chargebee’s 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. However, if your store still uses this setup please get in touch with us at [email protected].

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 where to get them here. Keep them handy as you’ll need them again in later steps.

Next you’ll need to copy/paste the code below 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.

<!-- REFERSION TRACKING: BEGIN -->
<script src="//SUBDOMAIN.refersion.com/tracker/v3/PUBLIC_KEY.js"></script>
<script>_refersion(function(){ _rfsn._setSource("CHARGEBEE"); });</script>
<!-- REFERSION TRACKING: END -->

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.

https://inbound-webhooks.refersion.com/chargebee/v2/orders/paid?public_key=PUBLIC_KEY&private_key=SECRET_KEY

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="https://js.chargebee.com/v2/chargebee.js" data-cb-site="your-site" data-cb-refersion-enabled="true"></script>

If you’re using the Chargebee 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:

<script>
$( document ).ready(function() {
var chargebeeInstance = Chargebee.init({
site: "your-site",
enableRefersionTracking: true
});
});
</script>

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

Step 4 (Drop-in script only): 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={{subscription.id}}, 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).

<!-- REFERSION TRACKING: BEGIN -->
<script src="//SUBDOMAIN.refersion.com/tracker/v3/PUBLIC_KEY.js"></script>
<script>function rfsn_getQS(e){e=e.replace(/[\[]/,"\\[").replace(/[\]]/,"\\]");var t=new RegExp("[\\?&]"+e+"=([^&#]*)"),n=t.exec(location.search);return n==null?"":decodeURIComponent(n[1].replace(/\+/g," "))}
if (rfsn_getQS('rfsn_ci')) {
_refersion(function(){
_rfsn._addCart(rfsn_getQS('rfsn_ci'));
_rfsn._setSource("CHARGEBEE");
});}</script>
<!-- REFERSION TRACKING: END —>

Step 5: Run a Test Order

Run a test order to make sure everything is tracking properly. 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?