Binom Documentation

Go to navigation

Click API

With Click API you can get all the click data without waiting for too long or having a redirect from a landing page to an offer.

Keep in mind that you can’t use both Click API and MagicChecker.

How it works


Click API’s functionality is based on the .php file binom_click_api.php connected to your landing page:

  • binom_click_api.php
    •                                             
      <?php
          $CampaignLink='https://tracker.com/click.php?key=XXX';
          $ApiKey='YYY';
          $getClick=new getClick($CampaignLink, $ApiKey);
          
          class getClick{
              /*
              * Binom ClickAPI
              * @version 1.16
              * @date 25.08.2021
              **/
              function __construct($CampaignLink, $ApiKey){
                  if(strpos($CampaignLink, '?')!==false){
                      $this->ClickURL=$CampaignLink.'&lp_type=click_info&api_key='.$ApiKey;
                  }else{
                      $this->ClickURL=$CampaignLink.'?lp_type=click_info&api_key='.$ApiKey;
                  }
                  if(isset($_GET)){
                      foreach($_GET AS $key=>$val){
                          $this->ClickURL=$this->ClickURL.'&'.$key.'='.urlencode($val);
                      }
                  }
                  $this->DataClick=$this->getClickData($this->ClickURL);
              }
              function setLPClick(){
                  $URL=$this->getLPClickURL();
                  $ch = curl_init();
                  curl_setopt($ch, CURLOPT_URL, $URL);
                  curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
                  curl_setopt($ch, CURLOPT_TIMEOUT, 60);
                  curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
                  curl_setopt($ch, CURLOPT_HEADER, 0);
                  $result = curl_exec( $ch );
                  curl_close( $ch );
                  return true;
              }
              function getLPClickURL($emulation=1){
                  if(isset($this->ClickURL) && isset($this->DataClick['uclick'])){
                      $tempArr=explode('?',$this->ClickURL);
                      if($emulation==1){
                          $LPClickURL=$tempArr[0].'?lp=1&emulation_mode=1&uclick='.$this->DataClick['uclick'];
                      }else{
                          $LPClickURL=$tempArr[0].'?lp=1&uclick='.$this->DataClick['uclick'];
                      }
                      return $LPClickURL;
                  }
                  return false;
              }
              function getLanding(){
                  if(isset($this->DataClick['landing']['type'])){
                      if($this->DataClick['landing']['id']==0 || $this->DataClick['landing']['name']=='DIRECT'){
                          echo 'Direct';
                      }else{
                          if($this->DataClick['landing']['type']==2 && isset($this->DataClick['landing']['html'])){
                              echo $this->DataClick['landing']['html'];
                          }else{
                              echo $this->loadLanding();
                          }
                      }
                  }
              }
              function includeLanding(){
                  ob_start();
                  include($this->getLandingUrl());
                  return $this->replaceLandingLink(ob_get_clean());
              }
              function loadLanding(){
                  $postdata = http_build_query($this->DataClick);
                  $opts = array('http' =>array(
                      'method'  => 'POST','header'  => 'Content-type: application/x-www-form-urlencoded','content' => $postdata
                  ));
                  $context  = stream_context_create($opts);
                  return $this->replaceLandingLink(file_get_contents(
                      $this->getLandingUrl(), false, $context
                  ));
              }
              function replaceLandingLink($html){
                  if(isset($this->DataClick['uclick'])){
                      $html=str_replace('?lp=1','?lp=1&uclick='.$this->DataClick['uclick'],$html);
                  }
                  return $html;
              }
              function getOfferUrl(){
                  $OfferUrl='Unknown';
                  if(isset($this->DataClick['offer']['url'])){
                      $OfferUrl=$this->DataClick['offer']['url'];
                  }
                  return $OfferUrl;
              }
              function getLandingUrl(){
                  $LandingUrl='Unknown';
                  if(isset($this->DataClick['landing']['url'])){
                      if($this->DataClick['landing']['id']=='0'){
                          $LandingUrl='Direct';
                      }else{
                          $LandingUrl=$this->DataClick['landing']['url'];
                      }
                  }
                  return $LandingUrl;
              }
              function getClickData($ClickURL){
                  $ClickOptions=$this->getClickOptions();
                  $ch = curl_init();
                  curl_setopt($ch, CURLOPT_URL, $ClickURL);
                  curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
                  curl_setopt($ch, CURLOPT_TIMEOUT, 60);
                  curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
                  curl_setopt($ch, CURLOPT_HEADER, 0);
                  if(!empty($ClickOptions)){
                      curl_setopt($ch, CURLOPT_POST, true);
                      curl_setopt($ch, CURLOPT_POSTFIELDS, $ClickOptions);
                  }
                  $result = curl_exec( $ch );
                  curl_close( $ch );
                  if(strpos($result,'<body><!-- adp-fngr-prnt --><script>')) {
                      echo $result; return false;
                  }
                  if(!$result=json_decode($result,true)){
                      $result['status']='error';
                      $result['error']='Incorrect Campaign link';
                  }
                  return $result;
              }
              function getClickOptions(){
                  $posts=array();
                  if(isset($_POST) && !empty($_POST)){
                      foreach($_POST AS $key=>$val){
                          $posts[]=$key.'='.$val;
                      }
                  }
                  $Headers=array();
                  foreach($_SERVER AS $key=>$val){
                      if(strtolower(substr($key, 0, 5)) === 'http_' || strtolower($key)=='remote_addr') {
                          $Headers[$key]=$val;
                      }
                  }
                  if(!isset($Headers['HTTP_CONTENT_TYPE'])){
                      $Headers['HTTP_CONTENT_TYPE']='text/html; charset=utf-8';
                  }
                  if(!isset($Headers['HTTP_X_FORWARDED_FOR']) && isset($Headers['REMOTE_ADDR'])){
                      $Headers['HTTP_X_FORWARDED_FOR']=$Headers['REMOTE_ADDR'];
                  }
                  $posts[]='ClickDataHeaders='.urlencode(json_encode($Headers));
                  return implode('&',$posts);
              }
          }
      ?>
                                                  
                                              

Instead of $CampaignLink specify your campaign URL (campaign must contain a non-Direct landing page) with the Campaign Key and instead of $ApiKey specify your API key (you can find it in Settings > API).

In order for Binom to see the traffic source tokens, specify them in the URL of your landing page with Click API.

Connect to a landing page


There are 2 ways you can connect Click API to a landing page:

1. Add the code from binom_click_api.php to your landing page’s file.
2. Connect the binom_click_api.php file via one of the following functions specifying a path:
include
require
include_once
require_once

Keep in mind that your landing page mush have the .php extension.

Available functions


FunctionDescription
$getClick=new getClick($CampaignLink, $ApiKey);Send click to the tracker.
This is an obligatory function,
without which others won't work.
$getClick->setLPClick();Send LP click to the tracker.
$getClick->getLPClickURL();Display link for LP click.
$getClick->getLPClickURL(0);Display link for sending a click to an offer (and hide the referrer).
$getClick->DataClick;Display all click data.
$getClick->getLanding();Load a landing page.
$getClick->getLandingUrl();Get the landing page URL.
$getClick->getOfferUrl();Get the offer URL.

getLanding()

Using the getLanding() function on the page will load (without substitution) the contents of the LP set in the campaign rule or path that the click is assigned to.

There will be no redirection in case of an integrated lander. In most cases it won't happen using a regular lander either, however in some cases redirection may be triggered depending on the server setup (e.g. Cloudflare proxy).

Please note that using getLanding(), CSS, images and other files used in a regular lander may not appear on the page if the files' paths are relative and lead to other directories on the server.

Possible scenarios


SENDING A CLICK TO AN OFFER

To send a click directly to the offer link and track LP CTR at the same time, use the following code:

                            
                                <a href="<?= $getClick->getOfferUrl(); ?>" onclick="navigator.sendBeacon('<?= $getClick->getLPClickURL(); ?>')" >Offer link</a>
                            
                        

Keep in mind that in this case you won’t be able to hide referrer. If this doesn’t suit you, then an extra redirect is required and the code will look like this:

                            
                                <a href="<?= $getClick->getLPClickURL(0); ?>" >Offer link</a>
                            
                        

ONE LANDING PAGE FOR SEVERAL CAMPAIGNS

If you want to use one landing page with Click API with many campaigns:

1. Remove the campaign key from $CampaignLink, so your link looks like this: 'https://tracker.com/click.php';
2. Pass the key parameter with a Campaign Key to the landing page URL.

LP TOKENS, EVENTS AND CONVERSION PIXEL

Click API doesn't use cookies, so in order to work with LP Tokens, Events and Conversion Pixel you should add the uclick parameter to the URL. You can get this parameter via $getClick->DataClick;.

Click API AND MULTIPLE OFFERS

Use this code in order to send the click to a specific offer (for example the third offer ot this path): <a href="<?=$getClick->getLPClickURL(0);?>&to_offer=3">To offer #3</a>