The most accurate way to track sales via Paypal is to use server-to-server tracking.
Prerequisite
Before you begin, you will need to have an understanding of scripting code. The solution we provide is using PHP code, but if you are not able to run PHP, you will need to develop your own code solution using different code.
Set Up an Offer in TUNE
Set up your offer in your TUNE network to first include {transaction_id} in the offer URL. Instead of storing a tracking ID in a user’s cookie, it is passed to you the advertiser and then you need to pass it to Paypal. Then when a user actually makes a purchase, Paypal will send us the transaction ID and we then take the transaction ID and look up the user’s session.
Sample offer URL:
http://www.yourdomain.com/index.php?sub={transaction_id}
“Please visit the bottom of the page for more details on passing values to Paypal.”
You also need to use the conversion tracking method of Server Postback with Transaction ID. After creating the offer, you will need to view the Tracking Code. When viewing an offer click the Tracking Code link in the Details panel. The Tracking Code page will display a Postback URL. You will need to take the URL and use it on a postback URL page. Read this article for more on Postback Tracking.
Create Notify Page
You’ll then need to create a notify page. Paypal will call this page on your servers behind the scenes. Since Paypal’s servers call the notify page, they are not the user and client cookies are not present. Thus, cookie tracking with pixels doesn’t work at all. That is why you have to use server-to-server tracking with TUNE.
You would need to pass the transaction ID to PayPal using the “custom” variable as defined here: https://developer.paypal.com/webapps/developer/docs/classic/products/#id08A6HH00W2J
Below is an example code of a notify page in PHP.
<?php // read the post from PayPal system and add 'cmd' $req = "cmd=_notify-validate"; foreach ($_POST as $key => $value) { $value = urlencode(stripslashes($value)); $req .= "&$key=$value"; } // post back to PayPal system to validate $header .= "POST /cgi-bin/webscr HTTP/1.0rn"; $header .= "Content-Type: application/x-www-form-urlencodedrn"; $header .= "Content-Length: " . strlen($req) . "rnrn"; $fp = fsockopen ("ssl://www.paypal.com", 443, $errno, $errstr, 30); // assign posted variables to local variables $item_name = $_POST['item_name']; $item_number = $_POST['item_number']; $payment_status = $_POST['payment_status']; $payment_amount = $_POST['mc_gross']; $payment_currency = $_POST['mc_currency']; $txn_id = $_POST['txn_id']; $receiver_email = $_POST['receiver_email']; $payer_email = $_POST['payer_email']; // get transction_id from custom $transction_id = $_POST['custom']; // set HasOffers postback URL $postback_url = "http://networkid.go2cloud.org/aff_lsr?transaction_id={transaction_id}"; // replace {transaction_id} with real value $postback_url = str_replace("{transaction_id}",$transction_id,$postback_url); if (!$fp) { // HTTP ERROR } else { // notify paypal and close fputs ($fp, $header . $req); fclose ($fp); // load HasOffers postback URL to track conversion $result = file_get_contents( $postback_url ); } ?>
You can get other code samples from Paypal here: http://paypal.github.io/sdk/sample-apps/
When you place your Paypal buy button, you’ll need to include two custom variables.
- custom – TUNE’ transaction ID
- notify_url – URL of notifying page created above hosted on your servers
By passing these variables to Paypal, they will then call the notify_url and include the custom parameter that stores the transaction ID.
In the Paypal interface, you can create a button with advanced variables. In “Step 3: Customize advanced features (optional)” specify the advanced variables like the below. You will actually need to replace “transaction_id” with the value TUNE passes to you like “1923as234asdf98asdf8a” instead of “transaction_id”. Also, make sure to set the notify_url to be the URL of the notify page on your servers.
Test Paypal Notify Script
To verify that your notify page is configured correctly, you can use Paypal’s developer page to test it. The IPN Simulator will allow you to do this. To access the IPN simulator, please log in with your Paypal developer account here: https://developer.paypal.com/webapps/developer/applications/ipn_simulator
You would insert the notify URL in the IPN Handler URL field, select “Web Accept” for the transaction type, then scroll to the bottom to insert a transaction ID into the custom field and click the Send IPN button. If everything works, you will see a green status indicating so and an actual conversion in your conversion report.
Sending Transaction ID to Paypal
For the notify URL to work, the transaction ID has to be passed to Paypal as a custom field. The example below is in PHP. On a basic level:
- The transaction ID needs to be obtained from the Default Offer URL (landing page).
- The transaction ID needs to be passed to Paypal as a custom field into the Paypal button.
When you are in your Paypal account and you copy the form code for your button, it will look like this:
<form action="https://www.paypal.com/cgi-bin/webscr" method="post" target="_top"> <input type="hidden" id="cmd" value="_s-xclick" /> <input type="hidden" id="hosted_button_id" value="PaypalAccount12345" /> <input type="image" src="https://www.paypalobjects.com/en_US/i/btn/btn_buynowCC_LG.gif" border="0" id="submit" alt="PayPal - The safer, easier way to pay online!" /> <img alt border="0" src="https://www.paypalobjects.com/en_US/i/scr/pixel.gif" width="1" height="1" /> </form>
To add the custom value to this form, the following line of code needs to be added to your button:
<input type="hidden" id="custom" value="<?= $_GET["sub"] ?>" />
What this PHP code is doing is looking for the value “sub” in the address bar and then getting the value for it. So if this is the URL in the address bar:
http://www.yourdomain.com/index.php?sub=12345
The PHP script will insert “12345” in the value field so when the Paypal button is clicked, it will pass them the custom value of 12345.
Test Integration
Now that you have you’ve created a notify page and are passing the TUNE transaction Id and the URL to the notify page to Paypal, you can test the integration to see if making a purchase will track as a conversion in TUNE.
When viewing an offer click the Tracking Code link from the details panel again. Then at the bottom of the Tracking Code page, there will be a test link. Use the test link to actually make a real purchase of one of your products.