> For the complete documentation index, see [llms.txt](https://docs.2checkout.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.2checkout.com/affiliate-network/affiliate-network/javascript-affiliate-checker.md).

# JavaScript affiliate checker

## Overview

Use the [JavaScript Affiliate Checker](https://secure.2checkout.com/cpanel/affiliate_checker.php) to keep track of sales generated by members of the 2Checkout Affiliate Network for services/products that you sell using a third-party eCommerce platform.

* 3rd party eCommerce provider -> JAVASCRIPT affiliate checker -> detects 2Checkout cookie -> 2Checkout buy-links
* 3rd party eCommerce provider -> JAVASCRIPT affiliate checker -> does not detect 2Checkout cookie -> 3rd party buy links

## Requirements

To use JavaScript Affiliate Checker, the following requirements must be met:

* The 2Checkout Affiliate Network is enabled for your account.
* Products sold through a third-party platform and available to 2Checkout Affiliates must be configured within the 2Checkout platform as well, and need to be assigned to commissions lists associated with 2Checkout Affiliates. Make sure to specify a commission you're willing to pay for affiliate referrals.

## How does the JavaScript Affiliate Checker work?

Take advantage of the JavaScript Affiliate Checker to customize the content of your online store for those shoppers that feature the 2Checkout affiliate cookie.

## Installing the JavaScript Affiliate Checker

To install, copy and customize the 2Checkout Affiliate Checker JavaScript code and place the code between the \<head>\</head> tags on your site.

```javascript
<script language="JavaScript">
var vId = 'UNIQUE CODE FOR YOUR ACCOUNT';
var scriptSRC = '/check_affiliate_v2.js';
var protocol = window.location.protocol;
if (protocol.indexOf("https") === 0) document.write(unescape("%3Cscript src='https://secure.2Checkout.com/content" + scriptSRC + "' type='text/javascript'%3E%3C/script%3E"));
else document.write(unescape("%3Cscript src='http://content.2Checkout.com" + scriptSRC + "' type='text/javascript'%3E%3C/script%3E"));
</script>
<script language="JavaScript">
var avgParams = _checkAvgParams();
var alreadyChecked = false;
if (avgParams != null) {
_AVGSetCookie('_avgCheck', avgParams);
alreadyChecked = true;
}
var avgProds = _avgProds(_AVGGetCookie('_avgCheck'), alreadyChecked, vId); //redirect
var AVG_AFF = false;var AVG_PRODS = new Array();
if (avgProds != "-") {
AVG_AFF = true;
if(avgProds != 'all') {AVG_PRODS = avgProds.split(',');}
}
</script>
```

The JavaScript code inserted into your site will help check and identify shoppers that feature the 2Checkout affiliate cookie and will return a set of results (response JavaScript variables):

* AVG\_AFF - boolean - having the following possible values
  * true - the customer has an active tracking cookie
  * false - the customer does not have an active tracking cookie
* AVG\_PRODS - JavaScript array - an associative array with all products that are tracked by 2Checkout or empty value if a general referral cookie is set.<br>

  | Table of possible responses: |                                                                                                    |
  | ---------------------------- | -------------------------------------------------------------------------------------------------- |
  | **AVG\_AFF** = false         | **AVG\_PRODS** = empty array, not applicable                                                       |
  | **AVG\_AFF** = true          | **AVG\_PRODS** = JavaScript array if no general cookie is set and specific product cookies are set |
  | **AVG\_AFF** = true          | **AVG\_PRODS** = empty array, general cookie is set                                                |
* AVG\_SET\_DATE – delivers the date when the cookie was set in the user’s browser
  * Format: YYYY-MM-DDTHH:MM:SS (E.G: 2019-10-18T15:27:54)

Use the results to:

* Build efficient landing pages for your affiliates
* Display custom information on your pages
* Prevent affiliate leaks by displaying the correct buy buttons
* Get extra information about your affiliate activity

You will need to use the responses returned by the script in order to redirect shoppers to either the 2Checkout shopping cart, if a 2Checkout affiliate ID is detected (meaning they were redirected to your website from a 2Checkout affiliate); or to the third-party shopper platform of your choice.

When redirecting customers to the 2Checkout shopping cart, use Buy Links generated via the Control Panel.

Orders placed by shoppers who used the Buy Links from 2Checkout affiliates will immediately be visible in the [Order search](https://secure.avangate.com/cpanel/reports.php) area of the Control Panel.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.2checkout.com/affiliate-network/affiliate-network/javascript-affiliate-checker.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `build a script that syncs our docs to a CMS` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
