Eric Nagel

Eric Nagel

CTO, PHP Programmer, Affiliate Marketer & IT Consultant

Tracking ShareASale 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.

Prosper202 is a powerful affiliate marketing tracking software package, with the ability to give you your revenue, cost, and ROI on your PPC campaigns. But the true power is shown when you automate as much as possible.

I’ve previously written how to use the ShareASale API, but left it up to you to fill in the blanks. In this example, I’m going to show you how to automatically get your ShareASale revenues to post back to Prosper202.

Before we begin, make sure you’re read the first post I wrote, or else this one will go by quickly. What this script does is fetches your sales from the previous day and submits the values and SIDs to your Prosper202 installation.

$dYesterday = date("m/d/Y", time()-86400);

$cURL = 'https://shareasale.com/x.cfm?action=activity&affiliateId=yourid&token=yourtoken&dateStart=' . $dYesterday . '&dateEnd=' . $dYesterday . '&XMLFormat=0';
// $cURL = 'sas.csv';

$fp = fopen($cURL, "r");
if ($fp) {
	$rsMap = array();
	while (empty($rsMap) && (($rsHeadings = fgetcsv($fp, 1000, "|")) !== FALSE)) {
		if (md5(serialize($rsHeadings)) != '5b448a7bdbeea0be7d7f758f5f8ee90b') {
			// echo(md5(serialize($rsHeadings)) . "\n");
			// print_r($rsHeadings);

			while (list($nIndex, $cColumn) = each($rsHeadings)) {
				// echo("$cColumn => $nIndex<br />\n");

				$cColumn = ereg_replace("\(.+\)", "", $cColumn);

				$rsMap[$cColumn] = $nIndex;
			} // ends while (list($nIndex, $cColumn) = each($rsHeadings))
			// print_r($rsMap);
		} // ends
	}

	/*
	Array
	(
		[Trans ID] => 0
		[User ID] => 1
		[Merchant ID] => 2
		[Trans Date] => 3
		[Trans Amount] => 4
		[Commission] => 5
		[Comment] => 6
		[Voided] => 7
		[Pending Date] => 8
		[Locked] => 9
		[Aff Comment] => 10
		[Banner Page] => 11
		[Reversal Date] => 12
		[Click Date] => 13
		[Click Time] => 14
		[Banner Id] => 15
	)
	*/
	while (($rsStatData = fgetcsv($fp, 1000, "|")) !== FALSE) {
		// print_r($rsStatData);
		if (
			(md5(serialize($rsDeal)) != '5b448a7bdbeea0be7d7f758f5f8ee90b') &&
			($rsStatData[$rsMap['Commission']] > 0) &&
			!empty($rsStatData[$rsMap['Aff Comment']]) &&
			($rsStatData[$rsMap['Aff Comment']] != "none")
			) {

			$cPostback = 'http://yourdomain.com/tracking202/static/gpb.php?amount=' . urlencode($rsStatData[$rsMap['Commission']]) . '&subid=' . urlencode($rsStatData[$rsMap['Aff Comment']]);
			// echo("$cPostback\n");
			$fpPostback = @fopen($cPostback, "r");
			if ($fpPostback !== false) {
				fclose($fpPostback);
			} // ends

		} // ends if (!empty($rsDeal))

	} // ends while (($data = fgetcsv($fp, 1000, "|")) !== FALSE)
	fclose($fp);
} // ends if ($fp)

The script creates a URL to grab yesterday’s stats, creates an array of the column headers ($rsMap), loops through the rest of the stats and if:

  • the line isn’t empty
  • the Commission is greater than 0.00
  • there is a SID
  • the SID is not “none”

then it pings your Prosper202 installation and updates the database with the commission for that SID.

Most of the code in this script is just reading the CSV file and getting the column names in place. The real work is done in lines 55-60.

Remember you’re limited to 200 API calls per month with ShareASale, so schedule this script to run daily (via cron).

If you have any questions, please leave them in the comments. And if you haven’t done so already, signup with ShareASale!

Comments
  • David D Ochoa
    Posted January 26, 2010 10:00 pm 0Likes

    Very nice article and script buddy.

  • PandaMarketer
    Posted February 26, 2010 5:59 pm 0Likes

    I was looking at this script again. It’s very quaint, and I am looking at implimenting. Now, obviously this has to be edited with one’s own SAS AFF ID and P202 domain.

    I do have a question about &token=yourtoken. What token are you referring to?

    Also, the generated SAS CSV if you will, has commission amounts, and I see you are including that on the postback query. Does this amount override what one has set up in their P202 for commission?

    Another thing, why are you checking if the md5 is NOT “5b448a7bdbeea0be7d7f758f5f8ee90b” twice?

    I already want to tweak this php code to include $_GET parameters to use multiple aff IDs or P202 install domains. I just don’t like having to code the sanitising of said variables. Is this what Stats202 does? Hmm.

    But I will hold off, as there is a new Prosper202 version in the works.

  • Eric Nagel
    Posted March 2, 2010 12:41 pm 0Likes

    Hey David – I’ll walk you through it on Skype to answer your questions

  • PandaMarketer
    Posted March 3, 2010 2:16 am 0Likes

    Thanks for the walk-through.

    This script doesn’t need to be CHMOD to 744 or 755 or something, right? I guess I’ll find out on my own.

  • Trackback: Tracking CJ Commissions with Prosper202 | Eric Nagel
  • Robert Anderson
    Posted May 23, 2010 6:26 pm 0Likes

    Thanks for this Eric. Is there anything we need to do within Prosper202? I have the script uploaded to my server and a cronjob scheduled every 8 hours.

    Rob

  • Eric Nagel
    Posted May 24, 2010 9:40 am 0Likes

    Hey Robert – nothing has to be done in P202. However, only run this once / day, as it grabs “yesterday’s” stats. So, running every 8 hours will give you “yesterday’s” stats 3x / day. Just run it about 4am or so

  • James Seligman
    Posted November 16, 2010 11:31 am 0Likes

    Eric,

    Thanks for this! I just got around to uploading this and wanting to let you and others know that and it works perfectly!

Leave A Comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.