How to add a script to checkout (for affiliate partner programme)? Original question:
I want to add a script to an order on checkout completion or even better with the rule 'when an order is first paid in full'. But I don't know how or where exactly.

Why I need it:
we want to use an external affiliate partner programme for PPS (pay per sale). So when a customer is coming from site A to our shop and orders somthing, the owner of site A gets a certain percentage of the sale.
In order for that to work, I need to add a script to the checkout. Or better add the script when the order is paid in full. I use tokens for the UID, order number and total amount in the script I got from the external affiliate partner.

The script looks like this:

&lt;script type="text/javascript" src="https://track.adcocktail.com/tracking_sale.php?t=s&amp;kid=xxxx&amp;lv=0&amp;bestid=[commerce-order:order-number]&amp;wert=[commerce-order:commerce_order_total]&amp;beschreibung=[commerce-order:mail-username]"&gt;&lt;/script&gt;


I tried adding it by a rule "add a variable" (on checkout completion) but that doesn't do anything. 
When I add the script to the order as a text field in the checkout, I can't use the tokens (they aren't recognized) and the script is run every time I do something to that order so it appears more than once in the affiliate overview.

Does someone know how I can make this script work ?

(I hope my question is clear. If not, just ask.)


Drupal Commerce Kickstart 7.x-2.25
Drupal 7.38


EDIT:

I don't need to activate the script on checkout completion, but 30 days after the order is paid in full. So after the 30 days the customer legally has to return goods. And that's not so easily done as adding the script on checkout completion.

Does anyone has an idea on how to make a rule for it ?
I would add the script by implementing hook_commerce_checkout_complete in a custom module. You also have access to the order in the function.

function MYMODULE_commerce_checkout_complete($order) {
  drupal_add_js(
   'https://track.adcocktail.com/...',
    array('type' =&gt; 'external')
  );
}


You need to debug the variable $order to find the values you stated, [commerce-order:order-number] etc.