Integration with Chargify is achieved by placing a sale tracking script into the thank you page using a simple JavaScript logic.

1.

First step

The first step would be to find the needed section where you can place the click tracking and sale tracking code. In your Chargify account navigate to Config > Settings > Public Page Default Settings and find the section called Custom JavaScript

2.

Sale tracking

Put the following code into the section described in the previous step:

</script>
<script id="pap_x2s6df8d" src="http://URL_TO_PostAffiliatePro/scripts/trackjs.js" type="text/javascript"></script>
<script type="text/javascript">
PostAffTracker.setAccountId('Account_ID');
try {
PostAffTracker.track();
} catch (err) { }

if (document.getElementById('analytics-signup-payment-id') != null) {
PostAffTracker.setAccountId('Account_ID');
var sale = PostAffTracker.createSale();
sale.setTotalCost($('#analytics-signup-revenue').html());
sale.setOrderID($('#analytics-signup-payment-id').html());
sale.setProductID($('#analytics-product-id').html());
sale.setCurrency($('#analytics-currency').html());

PostAffTracker.register();
}

3.

Custom thank you page

If you have defined a custom thank you page in your product or public signup page then you will also need to integrate the custom thank you page.
First thing though is to edit your Products and Public Signup Pages under Catalog menu in your Chargify account and see whether you have Return URL after successful signup or account update defined. If you do have it set then add the following into the Return Parameters field:
orderid={signup_payment_id}&totalcost={signup_revenue}&productid={product_id}&customer={customer_id}

Once you have that set you will need to edit the content of your custom thank you page and add this script to it:

<script id="pap_x2s6df8d" src="http://URL_TO_PostAffiliatePro/scripts/trackjs.js" type="text/javascript"></script>
<script type="text/javascript">
  var urlParams;
  (window.onpopstate = function () {
    var match,
        pl     = /\+/g,  // Regex for replacing addition symbol with a space
        search = /([^&=]+)=?([^&]*)/g,
        decode = function (s) { return decodeURIComponent(s.replace(pl, " ")); },
        query  = window.location.search.substring(1);

    urlParams = {};
    while (match = search.exec(query))
       urlParams[decode(match[1])] = decode(match[2]);
  })();
  if (urlParams['orderid'] != '') {
    PostAffTracker.setAccountId('Account_ID');
    var sale = PostAffTracker.createSale();
    sale.setTotalCost(urlParams['totalcost']);
    sale.setOrderID(urlParams['orderid']);
    sale.setProductID(urlParams['productid']);
    sale.setData1(urlParams['customer']);
    PostAffTracker.register();
  }
</script>

4.

Webhooks

Chargify gives us an option to use webhooks which we can use to track recurring commissions. To setup a webhook, first enable the Chargify plugin in your merchant panel. Then navigate to your Chargify account into Settings> Webhooks and click Add New Endpoint button where you can add your plugin's URL:
https://URL_TO_PostAffiliatePro/plugins/Chargify/chargify.php
and choose these endpoints: Payment Success, Refund Success
Save it and you are done.
NOTE: The endpoint has to use a valid SSL certificate, so only HTTPS connection is allowed.


It is now integrated. Every time a customer enters the order confirmation page, the tracking code is called, and it will register a sale for referring affiliate.