Click API Client

Features

  • Passing information about the current visitor to Keitaro;
  • Passing parameters from the address bar;
  • Processing and execution of Keitaro instructions: displaying a text, executing a redirect;

How to Integrate Click API Client v3 to a Website

  1. Go to Keitaro and open the campaign page.
  2. Now press “Integration” button.
  3. Choose there “Click API Client v3” and follow the instructions.
  4. Insert the code to the index.html file. Put it in the very beginning of a file.
  5. change .html extension to .php > install.php

Client Initialization

Here is an example of initialization KClickClient class.

require_once 'kclick_client.php'; // file must be uploaded into the same directory as the page  
$client = new KClickClient('API address', 'campaign token');

Description of methods

Method Description
$client->sendAllParams(); Passing parameters from address bar
$client->forceRedirectOffer(); Enables redirects to offers. If offer is chosen in the stream, it will be performed redirect to it. In other case, you must use getOffer()
$client->params('param1=c&param2=b'); Passing string parameters
$client->param('extra_param_5', '123'); Alternative method of passing a parameter
$client->sendUtmLabels(); Passing utm-labels from the address bar
$client->debug(); Displaying the debugging information
$client->currentPageAsReferrer(); Send the current page address as a referrer
$client->keyword('KEYWORD'); Using the value 'KEYWORD' as a keyword
$client->execute(); Executing Keitaro instructions with the continuation of the page code execution
$client->executeAndBreak(); Executing Keitaro instructions with stoppage of the page execution. If the action “Do Nothing” is passed in the stream, there will be no stoppage.
$client->getOffer(); Returns the offer link. The campaign must contain streams with schema 'Offers'. In other case, you'll receive 'no_offer'. Use this method if you don't want to perform automatic redirect to offer.
$client->getSubId(); Returns SubId
$client->getBody(); Get 'body' value
$client->getHeaders(); Get 'headers' value (array)
$client->isUnique(level); Uniqueness (level variations: stream, campaign, global)
$client->isBot(); Bot status
$client->restoreFromQuery() Catches query params _subid and _token without creating new click
$client->restoreFromSession() Restores previous click data from session without creating new click

This is example to use offer link in the page template:

<?php
require_once 'kclick_client.php'; 
$client = new KClickClient('http://example.con/api.php', 'token');
$offerLink = $client->getOffer();
?>
<html>
...
<body>
<a href="<?php echo $offerLink ?>">CLICK!</a>
</body>
</html>

You have to assign offers and one landing page to the stream.

How to Make Link for Particular Offer

<?php
require_once 'kclick_client.php'; 
$client = new KClickClient('http://example.con/api.php', 'token');
?>
<a href="<?php echo $client->getOffer(['offer_id' => 123]) ?>">CLICK!</a>

How to prevent a website from loading after the code

Replace

$client->execute();

with

$client->executeAndBreak();

How to Send Postbacks

To get your postback your, add new affiliate network. You'll get there the postback URL.

On your website, call this code to send a postback

$url = 'http://tds/POSTBACK_KEY/postback?payout=100&status=sale&subid=' . urlencode($_SESSION['sub_id']);
file_get_contents($url);

How to Show the Content From the Stream in the Specific Place

Instead of using $client->execute(); use $client->getContent(). Example

<?php echo $client->getContent() ?>

How to Integrate KClick Client with Wordpress

  1. Upload file “kclick_client.php” to home directory of wordpress website.
  2. Copy and paste the initialization code to the file index.php at the beginning.
  3. Choose the more appropriate for you case:
    • If you want to call redirects, use code $client->executeAndBreak(); in “index.php”.
    • If you need to show any contents in some website block. For example, banners. Use execute(); ?> in your templates file.

In case you want to call Keitaro only in single post, add to header.php of your wordpress theme

<?php
$postIds = array(100, 200, 300);  // Posts IDs
if (is_single() && in_array(get_the_id(), $postIds)) { 
   $GLOBALS['client']->executeAndBreak();
}
 
?>

An example of using KClickClient for offre link generation:

<?php
require_once 'kclick_client.php'; 
$client = new KClickClient('http://example.con/api.php', 'token');
?>
<html>
...
<body>
<a href="<?php echo $client->getOffer() ?>">CLICK!</a>
</body>
</html>

Use Landing Pages & Offers scheme in a Stream.

In case you need to call an exact offer, send offer_id parameter:

<a href="<?php echo $client->getOffer(array('offer_id' => 123), '#');?>">LINK</a>

If there's a possibility the tracker won't return an offer - you can setup a default link as a second parameter:

<a href="<?php echo $client->getOffer(null, 'http://ya.ru');?>">LINK</a>

How to Leave Users on the Website

Use action “Do Nothing” in the stream.

How to send title as a keyword

You need to learn how to get title in php scripts. You need to send the keyword with $client->keyword('...') method:

$client->keyword($myTitle);

$myTitle - is the example of how thw variable content is transferred as a keyword.

How to solve issues with Click Client

First of al,l check if the clicks get into the tracker. Check the traffic log and campaign's Clicks Report.

If there are no clicks add to the end of integration code:

$client->showLog();

After $client->execute() and $client->executeAndBreak().

This will show the debug info on the page.

If there's no log add the following before the integration code (after <?php):

ini_set('display_errors', 'on');
error_reporting(7);

How to check if Keitaro defines the user as a bot

/*
client incialization code
*/
if ($client->isBot()) {
   echo 'bot';
} else {
   echo 'not bot';
}

Why there's no offer redirect

By default, an offer is added as a link with $client->getOffer(). Add a line so the offer redirect is performed:

$client->forceRedirectOffer();	

How to insert the path to kclick_client.php if there are folders

Check your website directory and put an obsolete path:

require '/path_to_the_website/kclick_client.php';
...

Why is there a php-code on a website and it's not performed

1. Make sure the index file is with php extension. 2. The code itself has tags:

<?php 
....code.... 
?>

Error: TOO_MANY_REDIRECTS in a browser

Your stream sends visitors to the website where click api client is installed and gets redirected again and again. Edit the stream with website redirect. Change scheme to Action and select Do nothing.

How to Perform Offer Redirect

By default Click Client uses offers as link, that you can get by using $client->getOffer(). To make it perform redirect, add this:

$client->forceRedirectOffer();	

How to get a subid on secondary pages

The subid content is saved into a session:

 $_SESSION['sub_id'];

You can use the following piece of code in your scripts:

session_start(); // if the session wasn't used earlier it's better to launch it.
...
$data = array(
 'sub1' => $_SESSION['sub_id'],
 'name' => $_POST['name'],
  ...
);

How to track the domains which call the campaign

You can send domain name as a campaign parameter:

$client->param('sub_id_1', $_SERVER['HTTP_HOST']);

How to Prevent Collecting Multiple Clicks?

Add these line to the integration code:

$client->restoreFromSession();

It will look like these:

$client = new KClickClient(...);
$client->restoreFromSession();
...
$client->execute();

How to use Click Client on inner pages

Enable Click Client on an inner page adding $client->restoreFromSession(); :

<?php
require_once dirname(__FILE__) . '/kclick_client.php';
$client = new KClickClient('http://..../api.php?', 'TOKEN');
 
$client->restoreFromSession(); 

Now you can call the same methods without creating a new click:

<a href="<?php echo $client->getOffer()">offer link</a>

Request error codes

  • [REQ_ERR: 400] - This response means that server could not understand the request due to invalid syntax
  • [REQ_ERR: 401] - The client must authenticate itself to get the requested response
  • [REQ_ERR: 403] - The client does not have access rights to the content
  • [REQ_ERR: 404] - The server can not find requested resource
  • [REQ_ERR: 405] - The request method is known by the server but has been disabled and cannot be used
  • [REQ_ERR: 407] - The authentication is needed to be done by a proxy
  • [REQ_ERR: 408] - Request timeout
  • [REQ_ERR: 410] - The requested content has been permanently deleted from server, with no forwarding address
  • [REQ_ERR: 429] - The user has sent too many requests in a given amount of time
  • [REQ_ERR: 500] - The server has encountered a situation it doesn't know how to handle
  • [REQ_ERR: 501] - The request method is not supported by the server and cannot be handled
  • [REQ_ERR: 502] - The server, while working as a gateway to get a response needed to handle the request, got an invalid response
  • [REQ_ERR: 503] - The server is not ready to handle the request. Common causes are a server that is down for maintenance or that is overloaded
  • [REQ_ERR: 504] - The server is acting as a gateway and cannot get a response in time
  • [REQ_ERR: 505] - The HTTP version used in the request is not supported by the server
  • [REQ_ERR: UNSUPPORTED_PROTOCOL] - The URL you passed used a protocol that this cURL does not support
  • [REQ_ERR: FAILED_INIT] - Very early initialization failed. This is likely to be an internal error or problem, or a resource problem where something fundamental couldn't get done at init time
  • [REQ_ERR: BAD_URL] - The URL was not properly formatted
  • [REQ_ERR: COULDNT_RESOLVE_PROXY] - The given proxy host could not be resolved
  • [REQ_ERR: COULDNT_RESOLVE_HOST] - The given remote host was not resolved
  • [REQ_ERR: COULDNT_CONNECT] - Failed to connect to host or proxy
  • [REQ_ERR: PARTIAL_FILE] - A data transfer was shorter or larger than expected
  • [REQ_ERR: READ_ERROR] - There was a problem reading a data
  • [REQ_ERR: OUT_OF_MEMORY] - A memory allocation request failed
  • [REQ_ERR: OPERATION_TIMEDOUT] - The specified time-out period was reached according to the conditions
  • [REQ_ERR: HTTP_POST_ERROR] - Internal post-request generation error
  • [REQ_ERR: BAD_FUNCTION_ARGUMENT] - A function was called with a bad parameter
  • [REQ_ERR: TOO_MANY_REDIRECTS] - When following redirects, client hit the maximum amount
  • [REQ_ERR: GOT_NOTHING] - Nothing was returned from the server
  • [REQ_ERR: SEND_ERROR] - Failed sending network data
  • [REQ_ERR: RECV_ERROR] - Failure with receiving network data
  • [REQ_ERR: BAD_CONTENT_ENCODING] - Unrecognized transfer encoding
  • [REQ_ERR: SSL] - SSL error
  • [REQ_ERR: UNKNOWN] - Unknown error