Skip to content

Developers

SleekTrack has three surfaces for code: the window.sleekTrack function on tracked pages, PHP hooks, and a REST API. Its WP-CLI commands are described in CLI.

Sending events

Custom events and their properties are sent from the browser through window.sleekTrack; see Events and goals.

Hooks

SleekTrack fires actions when its data or state changes, so your own code can react, for example to keep an external system in step:

  • Sites: sleekTrack/site/created, sleekTrack/site/updated and sleekTrack/site/deleted, from the workspace, the REST API and WP-CLI
  • Groups: sleekTrack/group/created, sleekTrack/group/updated and sleekTrack/group/deleted
  • Networks: sleekTrack/network/enabled and sleekTrack/network/disabled
  • Lifecycle: sleekTrack/init at the end of every boot, sleekTrack/activated, sleekTrack/activatedNetwork and sleekTrack/deactivated, and sleekTrack/database/tablesCreated and sleekTrack/database/tablesDropped for the analytics tables

The sleekTrack/revenue/baseCurrency filter sets the headline revenue currency on a site without WooCommerce or Easy Digital Downloads; see Revenue.

PHP
add_action('sleekTrack/site/created', function (array $site) {
    error_log('Now tracking ' . $site['domain']);
});

Hooks lists every hook with its arguments.

REST API

The dashboards read and write everything through the sleek-track/v1 REST namespace, and so can your code: sites, groups, statistics and breakdowns, goals, funnels, annotations, share links, saved views, CSV export, history import and the collection settings. Every operation needs the manage_options capability, the network operations need manage_network_options, and the operations behind a share link, Shares_stats, Shares_statsBreakdown and Shares_statsRealtime, are public and check the link’s password themselves. For example, Sites_stats returns a site’s totals, the previous period and the timeseries:

Shell
curl -u admin:APPLICATION_PASSWORD \
  'https://example.com/wp-json/sleek-track/v1/sites/1/stats?period=30d'

Statistics operations take period, from and to like the dashboard, and filters as a JSON array of {"key": "...", "value": "..."} objects. Every response is wrapped as {"success": true, "data": ...}. REST operations lists every operation with its method, path and permission.

The collector itself is not part of the REST API. The tracker posts to the site’s home URL with ?sleek-track=1, or to admin-ajax.php as a fallback; see Snippet.

Stay in the Loop!  

Be the first to hear about new updates, special offers, and helpful tips, delivered straight to your inbox.

We respect your inbox (and your privacy). Read our privacy policy.