Search by

expertsystemsau / trackto-php-client

xsys

Framework-agnostic PHP client for the track.to API

Package info

github.com/expertsystemsau/trackto-php-client

pkg:composer/expertsystemsau/trackto-php-client

Statistics

Installs: 79

Dependents: 1

Suggesters: 0

Stars: 0

Open Issues: 0

v1.1.0 2026-10-14 10:06 UTC

This package is auto-updated.

Last update: 2026-10-14 10:07:07 UTC


README

Framework-agnostic PHP client for the track.to API. Requires PHP 8.2 or later.

This repository is a read-only split of expertsystemsau/trackto-php-sdk. Open issues and pull requests there, not here.

Compatibility

Version PHP Laravel track.to API (Track-Version)
1.x 8.2, 8.3, 8.4, 8.5 any (framework-agnostic) 2026-07-06

Install

composer require expertsystemsau/trackto-php-client

Quick start

Build the client with named arguments and make one call per resource:

use ExpertSystems\TrackTo\TrackToClient;

$client = new TrackToClient(apiKey: getenv('TRACKTO_API_KEY'));

$link = $client->links()->create(destinationUrl: 'https://example.com/landing', slug: 'launch');
echo $link->shortUrl;

$page = $client->links()->list(search: 'launch', perPage: 50);

foreach ($client->links()->all() as $link) {
    echo $link->slug;
}

$folder = $client->folders()->create(name: 'Campaigns');
$tag = $client->tags()->create(name: 'launch');

list() fetches one page. all() walks every page lazily.

Errors

Every exception the SDK throws implements TrackToException. API errors expose status(), errors() and rateLimit():

use ExpertSystems\TrackTo\Exceptions\RateLimitedException;
use ExpertSystems\TrackTo\Exceptions\TrackToException;

try {
    $client->links()->get('launch');
} catch (RateLimitedException $e) {
    sleep($e->rateLimit()->retryAfter ?? 1);
} catch (TrackToException $e) {
    error_log($e->getMessage());
}

Testing

withMockClient() returns a copy of the client wired to Saloon's MockClient. Fixtures builds response bodies that match the API spec:

use ExpertSystems\TrackTo\Testing\Fixtures;
use Saloon\Http\Faking\MockClient;
use Saloon\Http\Faking\MockResponse;

$client = $client->withMockClient(new MockClient([
    MockResponse::make(Fixtures::page([Fixtures::link()])),
]));

The full contract, including retries, pagination and update semantics, is in the conventions.

See the changelog for release history.

License

MIT. See LICENSE.md.