Tracking with JavaScript

Partnero simplifies the process of integrating and managing affiliate programs with its easy-to-use platform. This guide will walk you through the steps of integrating an Affiliate programopen in new window into your stack using simple front-end integration.

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 programopen in new window.

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:

  1. Log in to Partneroopen in new window
  2. Go to Programs
  3. Choose your Program if there is more than one
  4. On the left sidebar, go to Integration under Program
  5. 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 -->

Sign-ups tracking

The second step is to notify Partnero about new user sign-ups to keep track of referrals from affiliate partners.

Immediately after a user successfully signs up, make sure to run this script to ensure proper tracking.

<script>
    po('customers',
        'signup', {
            data: {
                key: 'customer_123456', // or email address
                name: 'John',
                email: 'john.doe@partnero.com'
            }
        }
    );
</script>
<script>
    po('customers',
        'signup', {
            data: {
                key: 'customer_123456', // or email address
                name: 'John',
                email: 'john.doe@partnero.com',
                partner: {
                    key: '{UNIQUE_PARTNER_KEY}'
                }
            }
        }
    );
</script>

Customers referred by partners are automatically identified when their data matches information stored in the partnero_partner or patnero_referral (Refer-a-friend program) cookies, which is set by our Partnero Universal script. This process is handled by the Partnero Universal script, ensuring accurate recognition of referred customers.

Request parameters

ParametersTypeRequiredLimitationsDetails
keystringyesCan be anything, but we recommend using an account ID or customer's email address. This will be required when creating transactions for the customer.
namestringoptionalThe name of the customer.
emailstringoptionalThe email of the customer.
partnerobject[]optional
partner.keystringoptionalPartner's key from partnero_partner or patnero_referral cookies. If a partner or referring customer is not specified, Patnero Universal will automatically attempt to identify and include this information from the URL or cookies.

Sales tracking

The following step of the integration is sending data about sales. When any user makes a purchase, it is recommended to inform Partnero about it.

Please ensure to execute this script immediately following a successful sale.

<script>
    po('transactions', 'create', {
        data: {
            key: 'transaction_123',
            amount: 99.99,
            amount_units: 'usd',
            product_id: 'prod_123', // optional
            product_type: 'monthly', // optional
            customer: {
                key: 'customer_123456'
            }
        }
    });
</script>
<script>
    po('transactions', 'create', {
        data: {
            key: 'transaction_123',
            amount: 99.99,
            amount_units: 'usd',
            product_id: 'prod_123', // optional
            product_type: 'monthly', // optional
            customer: {
                key: 'customer_123456'
            }
        },
    	options: {
    		create_customer: true // Use this option to create a customer and a transaction at the same time
    	}   
    });
</script>

Request parameters

ParametersTypeRequiredLimitationsDetails
keystringoptionalPayment ID. It is not required but recommended (must be unique). We recommend using a payment ID on your system. Later can be used to refund/delete transactions.
amountstringyesA full amount of the purchase. Partnero will calculate partner's reward based on program settings.
amount_unitsstringoptional
actionstringoptionalFor example, sale.
customerobject[]yes
customer.keystringyesThe same value from customer creation (if customer exists).
customer.emailstringoptional
customer.namestringoptional
product_idstringoptionalProduct ID. It is used to for advanced commmission calculation.
product_typestringoptionalProduct type or category. It is used to for advanced commmission calculation.
optionsobject[]optional
options.create_customerstringoptionaltrue or falseUse this option to create a customer and a transaction at the same time.