Affiliate tracking for Stripe
This guide shows you a simple way to connect Stripe with Partnero using JavaScript. It helps you keep track of customer buys and link them to your affiliate partners easily.
Please note that before proceeding with the integration, you should already have an affiliate program created on Partnero. If you haven't created a program yet, refer to our guide on creating an affiliate program.
Visitors tracking
Visitor tracking enables the identification of referral visits to your website.
For accurate tracking and attribution of referral visits and signups to the appropriate partners, you need to install the Partnero Universal script on your website as custom code.
To find the snippet, please follow these steps:
- Log in to Partnero
- Go to Programs
- Choose your Program if there is more than one
- On the left sidebar, go to Integration under Program
- Copy the Partnero Universal snippet
Once you have your unique Partnero Universal javascript snippet copied, paste it into your website’s HTML just before the closing of the </head>
tag.
Example of Partnero Universal
<!-- Partnero Universal -->
<script>
(function(p,t,n,e,r,o){ p['__partnerObject']=r;function f(){
var c={ a:arguments,q:[]};var r=this.push(c);return "number"!=typeof r?r:f.bind(c.q);}
f.q=f.q||[];p[r]=p[r]||f.bind(f.q);p[r].q=p[r].q||f.q;o=t.createElement(n);
var _=t.getElementsByTagName(n)[0];o.async=1;o.src=e+'?v'+(~~(new Date().getTime()/1e6));
_.parentNode.insertBefore(o,_);})(window, document, 'script', 'https://app.partnero.com/js/universal.js', 'po');
po('settings', 'assets_host', 'https://assets.partnero.com');
po('program', 'PUBLIC_PROGRAM_ID', 'load');
</script>
<!-- End Partnero Universal -->
Authorizing Stripe account
Before continue with intergation, you have to connect Partnero with your Stripe account.
- Log in to Partnero
- Go to Programs
- Choose your Program
- Go to Integration under Program
Find Stripe and follow instructions for authorization.
Method 1: Tracking via Checkout
This method is for websites that use Stripe as a main payment provider.
Run this script right after a sale is successfully concluded. For example, your order confirmation page.
<script>
po('transactions', 'create', {
data: {
key: 'STRIPE_CHARGE_ID',
amount: 99.99,
amount_units: 'usd',
product_id: 'STRIPE_PRODUCT_ID', // optional
product_type: 'monthly', // optional
customer: {
key: 'STRIPE_CUSTOMER_ID'
}
},
options: {
create_customer: true
}
});
</script>
Please be aware that the following script is only a template. To adapt it for actual use, you must replace key
, amount
, and customer.key
with the relevant information extracted from the order details.
Request parameters
Parameters | Type | Required | Limitations | Details |
---|---|---|---|---|
key | string | yes | Replace this with Stripe charge ID, for example ch_3MmlLrLkdIwHu7ix0snN0B15 . | |
amount | string | yes | The price of the product. | |
amount_units | string | optional | Currency, if it's not the same as per your program settings. | |
product_id | string | optional | Product ID. It is used to for advanced commmission calculation. | |
product_type | string | optional | Product type that has been purchased. Partnero will calculate partner's reward based on program settings. | |
customer.key | string | yes | Replace this with Stripe customer ID, for example cus_NffrFeUfNV2Hib . |
Method 2: Tracking via Payment Links
This method is for websites using Stripe Payment Links for payments.
Include the following script on every page containing payment links. It's important to place this script at the bottom of the page, directly above the closing </body>
tag for optimal functionality.
<script>
(function() {
const updateLinkHref = link => {
const cookieValue = (document.cookie.match(/(^| )partnero_partner=([^;]+)/) || [])[2];
if (cookieValue) {
try {
const url = new URL(link.href);
url.searchParams.set('client_reference_id', decodeURIComponent(cookieValue));
link.href = url.href;
} catch (error) {
console.error('Error:', error);
}
}
};
document.querySelectorAll('a[href^="https://buy.stripe.com"]').forEach(link => {
updateLinkHref(link);
link.addEventListener('click', () => updateLinkHref(link));
});
})();
</script>