Integration with Foxy Cart - a hosted e-commerce solution that was built specifically with web developers in mind. 

1.

Login

Log into your FoxyCart store's AdminPage, go to Templates> Receipt. In case there is no code yet, click to the FoxyCart Standard template.

2.

Integration - track whole cart as one transaction

Above the  </body> tag of the code of receipt template insert the following code:

<script type="text/javascript">
	document.write(unescape("%3Cscript id=%27pap_x2s6df8d%27 src=%27" + (("https:" == document.location.protocol) ? "https://" : "http://") + "URL_TO_PostAffiliatePro/scripts/trackjs.js%27 type=%27text/javascript%27%3E%3C/script%3E")); 
</script>
<script type="text/javascript">
var ototal = '{{ total_order }}';
var odiscount = '{{ total_discount }}';
var oshipping = '{{ total_shipping }}';
var otax = '{{ total_tax }}';

var ofinalprice = ototal - odiscount - oshipping - otax;

PostAffTracker.setAccountId('default1');
var sale = PostAffTracker.createSale();;
sale.setTotalCost(ofinalprice);
sale.setOrderID('{{ order_id }}');
PostAffTracker.register();
</script>

Click the update template button and save your work.

For older versions of FoxyCart skip the rows that  declare (define) the 'ototal', ..., 'ofinalprice' variables and 
instead of these 2 lines of code:

sale.setTotalCost(ofinalprice);

sale.setOrderID('{{ order_id }}');


use these ones:

sale.setTotalCost('^^subtotal^^');

sale.setOrderID('^^order_id^^');



in the code given in the box above.


If you wish to track the customer's email address into the 'Data1' parameter of sale tracking code in order to utilize Lifetime Commissions, then right above


PostAffTracker.register() 


add the following code:


sale.setData1('{{ customer_email }}');


In older versions use ^^customer_email^^ instead of {{ customer_email }} .

3.

Coupon tracking

In case you would like to use coupon tracking, use this version of code:

<script type="text/javascript">
	document.write(unescape("%3Cscript id=%27pap_x2s6df8d%27 src=%27" + (("https:" == document.location.protocol) ? "https://" : "http://") + "URL_TO_PostAffiliatePro/scripts/trackjs.js%27 type=%27text/javascript%27%3E%3C/script%3E")); 
</script>
<script type="text/javascript">

var sale = PostAffTracker.createSale();
var coupon_code = "";
if(FC.json.hasOwnProperty('coupons')) {
  $.each(FC.json.coupons, function(i, coupon){
    if(coupon.name.search(/CS4/i) > -1) {
      coupon_code = coupon.name;
    }
  });
}

var ototal = '{{ total_order }}';
var odiscount = '{{ total_discount }}';
var oshipping = '{{ total_shipping }}';
var otax = '{{ total_tax }}';

var ofinalprice = ototal - odiscount - oshipping - otax;

PostAffTracker.setAccountId('default1');
var sale = PostAffTracker.createSale();;
sale.setTotalCost(ofinalprice);
sale.setOrderID('{{ order_id }}');
sale.setCoupon(coupon_code);
PostAffTracker.register();
</script>

4.

Integration - tracking each product as a separate transaction

This option is available for FoxyCart version 2.0 and higher.

If you wish to take use of product id matching capability of Post Affiliate Pro, then you need to use a different integration code instead of the one mentioned in step no. 3.

Here is the code to be used:

<script type="text/javascript">
document.write(unescape("<script id='pap_x2s6df8d' src='"   (("https:" == document.location.protocol) ? "https://" : "http://")   "URL_TO_PostAffiliatePro/scripts/trackjs.js' type='text/javascript'></script>")); 
</script>
{% set counter = 0 %}

{% for item in items %}

<script type="text/javascript">
PostAffTracker.setAccountId('deafult1');
var sale{{ counter }} = PostAffTracker.createSale();
sale{{ counter }}.setTotalCost('{{ item.price }}');
sale{{ counter }}.setProductID('{{ item.code }}');
sale{{ counter }}.setOrderID('{{ order_id }}_{{ counter }}');
sale{{ counter }}.setData1('{{ customer_email }}');
PostAffTracker.register();
</script>

{% set counter = counter   1 %}

{% endfor %}

That's it.

5.

Integration - tracking each product as a separate transaction + coupon tracking

This option is available for FoxyCart version 2.0 and higher.

If you wish to utilize coupon tracking along with the per product tracking, then use the following code instead of the one in step no.5. 

This option is available for FoxyCart version 2.0 and higher.

<script type="text/javascript">
document.write(unescape("<script id='pap_x2s6df8d' src='"   (("https:" == document.location.protocol) ? "https://" : "http://")   "URL_TO_PostAffiliatePro/scripts/trackjs.js' type='text/javascript'></script>")); 
</script>
{% set counter = 0 %}

{% for item in items %}

<script type="text/javascript">
var coupon_code = "";
if(FC.json.hasOwnProperty('coupons')) {
  $.each(FC.json.coupons, function(i, coupon){
    if(coupon.name.search(/CS4/i) > -1) {
      coupon_code = coupon.name;
    }
  });
}

PostAffTracker.setAccountId('deafult1');
var sale{{ counter }} = PostAffTracker.createSale();
sale{{ counter }}.setTotalCost('{{ item.price }}');
sale{{ counter }}.setProductID('{{ item.code }}');
sale{{ counter }}.setOrderID('{{ order_id }}_{{ counter }}');
sale{{ counter }}.setCoupon(coupon_code);
sale{{ counter }}.setData1('{{ customer_email }}');
PostAffTracker.register();
</script>

{% set counter = counter   1 %}

{% endfor %}

If you wanted to track some more details into the Extra Data 2-5 fields of sale tracking code, check out the details available in the receipt template of foxycart:

https://wiki.foxycart.com/v/2.0/receipt

Foxycart supports twig syntax:

http://twig.sensiolabs.org/doc/templates.html