playtini / keitaro-client
Keitaro Client: Click API, Admin API
Installs: 5 901
Dependents: 0
Suggesters: 0
Security: 0
Stars: 2
Watchers: 2
Forks: 3
Open Issues: 0
Requires
- php: ^8.1
- gupalo/dateutils: ^1.13
- gupalo/json: ^1.0
- psr/cache: ^3.0
- symfony/http-client: ^6.1|^7.0
- symfony/http-foundation: ^6.1|^7.0
Requires (Dev)
- phpunit/phpunit: ^10.5
- dev-main
- 2.15.0
- 2.14.0
- 2.13.3
- 2.13.2
- 2.13.1
- 2.13.0
- 2.12.0
- 2.11.1
- 2.11.0
- 2.10.0
- 2.9.0
- 2.8.0
- 2.7.6
- 2.7.5
- 2.7.4
- 2.7.3
- 2.7.2
- 2.7.1
- 2.7.0
- 2.6.10
- 2.6.9
- 2.6.8
- 2.6.7
- 2.6.6
- 2.6.5
- 2.6.4
- 2.6.3
- 2.6.2
- 2.6.1
- 2.6.0
- 2.5.0
- 2.4.4
- 2.4.3
- 2.4.2
- 2.4.1
- 2.4.0
- 2.3.6
- 2.3.5
- 2.3.4
- 2.3.3
- 2.3.2
- 2.3.1
- 2.3.0
- 2.2.0
- 2.1.1
- 2.1.0
- 2.0.0
This package is auto-updated.
Last update: 2024-11-26 17:01:20 UTC
README
Keitaro is a tool for affiliate and performance marketing.
It has 2 APIs: Click API, Admin API.
Maintainer
This library is created and supported by Playtini.
We're hiring marketers (FB, Tiktok, UAC, in-app, Google) and developers (PHP, JS): playtini.ua/jobs
Install
composer require playtini/keitaro-client
Click API
Accept traffic at your server, let Keitaro track and route your traffic.
Click API is available in Pro and Business Keitaro editions.
Click API docs:
- https://docs.keitaro.io/en/development/click-api.html
- https://docs.keitaro.io/en/campaign-integrations/kclient-php.html
- https://blog.keitaro.io/en/kclient-php-an-in-depth-article/
Usage:
use Playtini\KeitaroClient\ClickApi\KeitaroClickApiClient; use Playtini\KeitaroClient\ClickApi\KeitaroParams; use Playtini\KeitaroClient\ClickApi\KeitaroRequest; use Playtini\KeitaroClient\Http\KeitaroHttpClient; use Symfony\Component\HttpClient\CurlHttpClient; use Symfony\Component\HttpFoundation\Request; require_once(__DIR__ . '/vendor/autoload.php'); $keitaroHttpClient = new KeitaroHttpClient(new CurlHttpClient(), 'https://keitaro.example.com'); // change to your TDS domain $keitaroRequest = KeitaroRequest::create(Request::createFromGlobals()), $keitaroParams = KeitaroParams::createFromKeitaroRequest($keitaroRequest, 'CAMPAIGN_TOKEN_HERE'); // change campaign token $clickApiClient = new KeitaroClickApiClient($keitaroHttpClient, $keitaroRequest, $keitaroParams); $response = $clickApiClient->createResponse($clickApiClient->getResult()); $response->send();
If you don't know campaign token but know campaign alias (unique URL part in TDS link - like
https://keitaro.example.com/THIS_IS_ALIAS ) then use KeitaroClickApiTokenResolver
to get token via Admin API.
use Playtini\KeitaroClient\AdminApi\KeitaroAdminApiClient; use Playtini\KeitaroClient\ClickApi\KeitaroClickApiTokenResolver; use Playtini\KeitaroClient\Http\KeitaroHttpClient; use Symfony\Component\HttpClient\CurlHttpClient; $keitaroHttpClient = new KeitaroHttpClient(new CurlHttpClient(), 'https://keitaro.example.com'); // change to your TDS domain $adminClient = new KeitaroAdminApiClient($keitaroHttpClient, 'ADMIN_API_KEY_HERE'); // change api key $resolver = new KeitaroClickApiTokenResolver($adminClient); $resolver->getCampaignToken('test-tds')
For dependency injection you can use KeitaroClickApiClientFactory
.
Admin API
View, edit data at Keitaro without using UI.
Admin API is available only in Business Keitaro edition.
Admin API docs:
Usage:
use Playtini\KeitaroClient\AdminApi\KeitaroAdminApiClient; use Playtini\KeitaroClient\Http\KeitaroHttpClient; use Symfony\Component\HttpClient\CurlHttpClient; require_once(__DIR__ . '/vendor/autoload.php'); $keitaroHttpClient = new KeitaroHttpClient(new CurlHttpClient(), 'https://keitaro.example.com'); // change to your TDS domain $adminClient = new KeitaroAdminApiClient($keitaroHttpClient, 'ADMIN_API_KEY_HERE'); // change api key print_r($adminClient->campaigns());
Warning! Only several endpoints are implemented. If you need more please add an issue, we'll make them sooner.
Symfony config example
config/services.yaml
Playtini\KeitaroClient\Http\KeitaroHttpClient: bind: $trackerUrl: '%env(KEITARO_TRACKER_URL)%' Playtini\KeitaroClient\AdminApi\KeitaroAdminApiClient: bind: $adminApiKey: '%env(KEITARO_ADMIN_API_KEY)%' Playtini\KeitaroClient\ClickApi\KeitaroClickApiClientFactory: {public: true} Playtini\KeitaroClient\ClickApi\KeitaroClickApiTokenResolver: {public: true}
KEITARO_TRACKER_URL=https://keitaro.example.com KEITARO_ADMIN_API_KEY=aaa111bbb222aaa111bbb222
Don't forget to set real values in environment variables.
Click API controller method
public function __invoke( string $slug, Request $request, KeitaroClickApiClientFactory $clientFactory, KeitaroClickApiTokenResolver $apiTokenResolver, ): Response { $client = $clientFactory->create( request: $request, campaignToken: $apiTokenResolver->getCampaignToken($slug), // it's cached ); $client->params->set('log', 1); return $client->createResponse($client->getResult()); }
Admin API controller method
public function __invoke(KeitaroAdminApiClient $keitaroAdminApiClient): JsonResponse { $campaigns = $keitaroAdminApiClient->campaigns(); $tokens = []; foreach ($campaigns as $campaign) { $tokens[$campaign->alias] = $campaign->token; } return new JsonResponse($tokens); }