How to Use the Slimstat Tracker in External PHP Scripts
Applies to SlimStat 6.0.0 · checked
SlimStat’s wp_slimstat::slimtrack() method can record a pageview from custom code inside a loaded WordPress environment. It does not work in an arbitrary standalone script without WordPress and the plugin.
Call the tracker once
if ( class_exists( 'wp_slimstat' ) && is_callable( array( 'wp_slimstat', 'slimtrack' ) ) ) {
wp_slimstat::slimtrack();
}
Only call this where automatic tracking is not already recording the same request. Consent checks and exclusions still apply. Cron jobs have no ordinary visitor browser context, so do not treat them as human visits.
Modify a supported field
Register a filter before the tracking call:
add_filter( 'slimstat_filter_pageview_stat', function ( $stat ) {
if ( empty( $stat ) ) {
return $stat;
}
$stat['notes'][] = 'custom integration';
return $stat;
} );
Use existing schema fields; adding an arbitrary custom_param key does not create a database column. Never add personal or secret values just to label a report. See the pageview filter and tracking troubleshooting guide.
At this hook, notes is an array of strings. Append an entry; the tracker serializes the array before storage. Return an incoming empty array unchanged if another filter has already rejected the pageview.