Working with ClickBank

Step 1: Get ClickBank Link

You’ll need to get a tracking link for the ClickBank product you want to promote. From the marketplace in ClickBank, click the Promote button to get a tracking link. For “Tracking ID (Optional):” enter “TRANSACTIONID”. This will be used as placeholder. Click Create to get the link. Your ClickBank link should look something like this:

Step 2: Set Up Offer

Now that you have your ClickBank link, you can create an offer in your TUNE network. Specify the title and the description. You can copy this information from the ClickBank marketplace. For the offer URL input the ClickBank link but replace “TRANSACTIONID” with “{transaction_id}”. Your offer URL should look something like this:{transaction_id}

For the tracking protocol, select “Server Postback with Transaction ID”.

Step 3: Set Up Postback URL

First, ensure that Encrypted Conversion Tracking is set to “Disabled” in the Offer Tracking Settings for each offer you are going to promote. This allows you to create a global postback URL by removing the offer ID from any offer-specific postback URL.

Sample global postback URL (notice there is no offer ID parameter):{transaction_id}&amount={amount}

Step 4: Secret Key

Next, you’ll need to input a “secret key” in your ClickBank account that your interstitial script will use to decode the encrypted messages ClickBank sends. In ClickBank, go to Settings > My Site > “Edit” in the advanced tools box > Secret Key. Enter whatever you’d like here, and keep track of this value. You’ll need to input this key into the code you will be hosting.

How It Works

ClickBank uses a special notification system that can’t communicate directly with your TUNE network. So you’ll need to create a simple page that gets posted values from ClickBank, formats them, and sends them in the TUNE postback URL. This is sample PHP code that gets the “ctid” value from ClickBank and includes it in the TUNE postback URL as “transaction_id”. This is because TUNE passes the “transaction_id” value to ClickBank in the tracking link, as outlined above. For more information about other variables ClickBank includes in the post, see their documentation.

Step 5: Host Tracking Code

You’ll need to host this page on a server before your ClickBank setup is complete:

$secretKey = "SECRET_KEY_HERE"; // Set this to your ClickBank secret key
$HOnetworkID = "NETWORK_ID_HERE"; // Set this to your TUNE Network ID

// Grab the incoming input variables
$message = json_decode(file_get_contents('php://input'));

// Extract the encrypted notification and initialization
// vector for AES/CBC/PKCS5Padding decryption
$encrypted = $message->{'notification'};
$iv = $message->{'iv'};

// Decrypt the message body
$decrypted = trim(
        substr(sha1($secretKey), 0, 32),
// Convert the decrypted string to a JSON object
$order = json_decode($decrypted);

// Store all relevant ClickBank variables
$email = $order['customer']['billing']['email'];
$receipt = $order['receipt'];
$fname = $order['customer']['billing']['firstName'];
$lname = $order['customer']['billing']['lastName'];
$item = $order['lineItems'][0]['itemNo'];
$phone = $order['customer']['billing']['phoneNumber'];
$vendor = $order['vendor'];
$amount = $order['totalAccountAmount'];
$txnType = $order['transactionType'];
$transaction_id = $order['trackingCodes'][0];

// Assemble conversion link
$convUrl = 'http://'.$HOnetworkID.''.$transaction_id.'&amount='.$amount.'&adv_sub='.$email.'-'.$receipt;

// Ensure that transaction_id exists and is a relevant action type
if ($transaction_id) {
    if ($txnType == "SALE" or $txnType == "BILL" or $txnType == "TEST_SALE" or $txnType == "TEST_BILL") {
        // Fire the conversion postback URL
        $convresp = file_get_contents($convUrl);

Instant Notification

Now in your ClickBank account go to Account Settings > My Site. Then there is a panel for Advanced Tools Editor. Input the URL to the page you created above.