Eric Nagel

Tracking CJ Commissions with Prosper202

I have been, or can be if you click on a link and make a purchase, compensated via a cash payment, gift, or something else of value for writing this post. Regardless, I only recommend products or services I use personally and believe will be good for my readers.

I got a call today from a guy in NJ looking to track CJ sales with Prosper202. He saw my post on Tracking ShareASale Commissions with Prosper202 and another post on using the Commission Junction Web Services and wanted some info on how to combine the two.

It’s actually pretty simple… just take the code from the CJ page, then the part where 202 is pinged from the SAS+202 post, and you get:

<?php
	$cDevKey = 'your-developer-key';

	$cURL = 'https://commission-detail.api.cj.com/v3/commissions?';
	$cURL .= 'date-type=event&';

	$ch = curl_init();
	curl_setopt($ch, CURLOPT_URL, $cURL);
	curl_setopt($ch, CURLOPT_HTTPHEADER, array(
				  'Authorization: ' . $cDevKey,
				  'User-Agent: "Mozilla/5.0 (Windows; U; Windows NT 6.0; en-US; rv:1.9.0.15) Gecko/2009101601 Firefox/3.0.15 GTB6 (.NET CLR 3.5.30729)"'
				));

	curl_setopt($ch, CURLOPT_HEADER, false);
	curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

	curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10);
	curl_setopt($ch, CURLOPT_TIMEOUT, 10);

	$cHTML = curl_exec($ch);
	if (curl_error($ch)) {
		echo "Curl error: " . curl_error($ch);
	} // ends if (curl_error($ch))
	else {
		$cXML = simplexml_load_string($cHTML);

		for ($i = 0; $i < count($cXML->commissions->commission); $i++) {
			$oCJCommission = $cXML->commissions->commission[$i];

			$cPostback = 'http://yourdomain.com/tracking202/static/gpb.php?amount=' . urlencode($oCJCommission->{'commission-amount'}) . '&subid=' . urlencode($oCJCommission->sid);
			$fpPostback = @fopen($cPostback, "r");
			if ($fpPostback !== false) {
				fclose($fpPostback);
			} // ends if ($fpPostback !== false)
		} // ends for ($i = 0; $i < count($cXML->commissions->commission); $i++)
	} // ends else from if (curl_error($ch))
?>

Cron this script (I have mine run every day about 7am) and you’ll see your CJ commissions in Prosper202