Affiliate Software Documentation

API Sample Code for Setting Remote Domain Cookies

The following PHP code block will show you how to set affiliate tracking cookies on remote domains, or subdomains outside of your Affiliate Manager installation domain.

Why Remote Domains?

This setup can be useful if for example, you host your affiliate manager on a different domain name, and you want to use the remote domains URL as the affiliate link.

For example:

You have Affiliat Manager installed on affiliates.domain.com, and you want to track your referrals for www.domain2.com. You also want your affiliate links to look like:

http://www.domain2.com/username

Requirements

The example code below is written in PHP. This means that your remote domain needs to use index.php as the default home page file. Secondly, make sure that your remote domain uses .htaccess to rewrite URLs, similar to:

http://www.domain2.com/page1
http://www.domain2.com/page2

Apps like WordPress already have this setup by default, so it would work. Otherwise, you would have to change the way your links look like by using a remote file instead, like track.php:

http://www.domain2.com/track.php?id=username

The remote domain must be allowed to call remote URLs via CURL compiled in PHP

Setting Up

In order to test it, please follow these steps:

  1. Login to your Affiliate Admin Area.
  2. Click on Settings > Global Configuration, and go to the Automation Tab.
  3. On the Auto Signup Sub tab, enable automation and enter a 20 digit Automation Access Key and Automation Secret ID
  4. Click Save Changes to save it.
  5. Go to Program Offers> Manage Program Offers and edit the affiliate program you want to use.
  6. Click on Remote Affiliate Links Tab.
  7. Set the remote domain link to your format:

    http://www.yourremotedomain.com/{USERNAME}

  8. Set the remote domain name to your remote domain (do not incude http:// or www)

    yourremotedomain.com

  9. Save Changes

Example Code

You can use the example code below to add to your index.php page on your main domain (www.domain2.com as given above):

<?php
define('JX_URL', 'http://www.yourdomain.com/affiliates'); //NO TRAILING SLASH 
define('JX_ACCESS_KEY','xxxxxxxxxxxxxxxxxxxxxxxxxxxxx'); 
define('JX_ACCESS_ID','xxxxxxxxxxxxxxxxxxxxxxxxxxxxx');
define('JX_PROGRAM_ID' ,'1');

jx_set_cookie();

function jx_set_cookie()
{
	$u = parse_url($_SERVER['REQUEST_URI']);
	$jrox_aff = str_replace('/', '', $u['path']);
	
	$sdata = array(
				   	'access_key' => JX_ACCESS_KEY,
				   	'access_id' => JX_ACCESS_ID,
				   	'ip' => $_SERVER['REMOTE_ADDR'],
				   	'user_agent' => $_SERVER['HTTP_USER_AGENT'],
				   	'subdomain' => $jrox_aff, //affiliate username,
					'program_id' => JX_PROGRAM_ID,
				   );
	
	$fields = "";
	foreach( $sdata as $key => $value ) $fields .= "$key=" . urlencode( $value ) . "&";
		
	$ch = curl_init(JX_URL . '/automate/set_tracking_cookie' );
		
	curl_setopt($ch, CURLOPT_HEADER, 0); // set to 0 to eliminate header info from response
	curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, '50');
	
	curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); // Returns response data instead of TRUE(1)
	curl_setopt($ch, CURLOPT_POSTFIELDS, rtrim( $fields, "& " )); // use HTTP POST to send form data
	$resp = curl_exec($ch); //execute post and get results
	curl_close ($ch);
	
	if (!empty($resp))
	{
		$result = @json_decode( $resp);
		
		if ($result)
		{
			$jam_cookie = $result->msg;
			setcookie($jam_cookie->name, $jam_cookie->value, $jam_cookie->expire, $jam_cookie->path, $jam_cookie->domain, 0);
		}
	}
}
?>

Make sure to change the JX_URL, JX_ACCESS_KEY , JX_ACCESS_ID to point to the correct values