Binom Documentation

К навигации

Click API

With Click API you can get all the data for a click from the tracker wihout waiting or using an additional redirect. For example you can send your traffic right to your landing page and filter it by IP, geo, device and other things you setup in the tracker's campaign.
Also Click API allows you to avoid an additional redirect beween landing page and offer.

Its functionality is based on PHP-file binom_click_api.php, which should be connected with 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{ 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.'='.$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){ $this->includeLanding(); }else{ echo $this->loadLanding(); } } } } function includeLanding(){ ob_start(); include($this->getLandingUrl()); return $this->replaceLandingLink(ob_get_clean()); } function loadLanding(){ return $this->replaceLandingLink(file_get_contents($this->getLandingUrl())); } 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){ $ClickURL=$ClickURL.$this->getClickGet(); $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(!$result=json_decode($result,true)){ $result['status']='error'; $result['error']='Incorrect Campaign link'; } return $result; } function getClickGet(){ $gets=''; foreach($_GET AS $key=>$val){ $gets=$gets.'&'.$key.'='.$val; } return $gets; } function getClickOptions(){ $posts=array(); foreach($_POST AS $key=>$val){ $posts[]=$key.'='.$val; } $Headers=array(); $TrueHeaders=array( 'REMOTE_ADDR','HTTP_USER_AGENT','HTTP_COOKIE','HTTP_X_PURPOSE', 'HTTP_REFERER','HTTP_ACCEPT_LANGUAGE','HTTP_X_FORWARDED_FOR' ); foreach($_SERVER AS $key=>$val){ if(in_array($key,$TrueHeaders)){ $Headers[$key]=$val; } } if(!isset($Headers['HTTP_X_FORWARDED_FOR']) && isset($Headers['REMOTE_ADDR'])){ $Headers['HTTP_X_FORWARDED_FOR']=$Headers['REMOTE_ADDR']; } $posts[]='ClickDataHeaders='.json_encode($Headers); return implode('&',$posts); } } ?>

You should put your campaign link in $CampaignLink (with only key parameter) and your API-key in $ApiKey
You need to send traffic source tokens into the landing URL (with Click-API) to be taken into stats by the tracker.
Your landing should have .php extension since it works on PHP.

AVAILABLE OPTIONS

OptionDescription
$getClick=new getClick($CampaignLink, $ApiKey);Send click to the tracker,
this is necessary option,
all other options won't work without it
$getClick->setLPClick();Send LP click to the tracker
$getClick->getLPClickURL();Display link for LP click
$getClick->getLPClickURL(0);Display link for sending click to offer (with hiding referer)
$getClick->DataClick();Display all click data
$getClick->getLanding()Load the landing page
$getClick->getLandingUrl();Get the landing page URL
$getClick->getOfferUrl();Get the offer URL

Sending click to offer

If you want to send a click directly to the offer link and trace LP CTR at the same time, you can use the following code:

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

But this method will not allow you to use hide referrer. If you need hide referrer, an extra redirect is required and the code will be like this:

                            
                                <a href="<?= $getClick->getLPClickURL(); ?>" >link to the offer</a>
                            
                        

ONE LANDING PAGE FOR MULTIPLE CAMPAIGN

If you want to use one LP with Click API with multiple campaigns - you should:
1) Remove the campaign key from $CampaignLink: 'https://tracker.com/click.php';
2) Pass the parameter key with your campaign key in the landing page URL.

LP TOKENS, EVENTS AND CONVERSION PIXEL

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