Functions and API

SlimStat Database Tables and Columns Reference

Applies to SlimStat 5.5.0 and SlimStat Pro 2.0.0 · checked

SlimStat creates four tables in your WordPress database: slim_stats for pageviews, slim_events for outbound clicks and other events, and an archive counterpart for each. Every name carries your site’s table prefix, so a default install writes pageviews to wp_slim_stats. Deleting the plugin removes none of it unless you opt in first.

Table suffixPrimary keyWhat it stores
slim_statsidOne row per tracked pageview, 33 columns
slim_stats_archiveidPurged pageviews, created LIKE slim_stats
slim_eventsevent_idOutbound clicks and other events
slim_events_archiveevent_idPurged events, same seven columns

The four tables and the prefix rule

Table names resolve through $wpdb->prefix, which is whatever $table_prefix in wp-config.php sets rather than a literal wp_. On multisite every subsite owns its own set of four, so blog 2 writes to wp_2_slim_stats. Never hardcode wp_ in a query.

All four are created COLLATE utf8_general_ci, and with ENGINE=InnoDB where the server reports InnoDB as available. SlimStat Pro adds no tables of its own; its external-database add-on relocates these same four rather than creating more.

The table layout is not part of the plugin’s public API and does change between major versions. This page describes the version currently published on wordpress.org. Run SHOW CREATE TABLE wp_slim_stats on your own install before writing anything that depends on a column’s exact type.

Every column in wp_slim_stats

ColumnTypeWhat it holds
idINT UNSIGNED, auto incrementPrimary key
ipVARCHAR(39)Visitor IP, anonymised or hashed per your settings
other_ipVARCHAR(39)Originating IP behind a proxy, when present
usernameVARCHAR(256)WordPress login, for logged-in visitors
emailVARCHAR(256)Commenter email, where one was left
countryVARCHAR(16)Two-letter country code, lowercased
locationVARCHAR(36)Coordinates as latitude,longitude
cityVARCHAR(256)City, at City geolocation precision only
refererVARCHAR(2048)The URL that sent this visit
resourceVARCHAR(2048)The permalink that was requested
searchtermsVARCHAR(2048)Search terms parsed from the referrer
notesVARCHAR(2048)Tracker annotations for this hit
visit_idINT UNSIGNEDGroups pageviews into one visit, 0 if none
server_latencyINT(10) UNSIGNEDMilliseconds your server took to reply
page_performanceINT(10) UNSIGNEDMilliseconds the browser took to render
browserVARCHAR(40)Browser name
browser_versionVARCHAR(15)Browser version
browser_typeTINYINT UNSIGNEDDesktop, crawler, mobile or touch
platformVARCHAR(15)Operating system
languageVARCHAR(5)Browser language code
fingerprintVARCHAR(256)Anonymous identifier, when one is collected
user_agentVARCHAR(2048)Full user-agent string
resolutionVARCHAR(12)Viewport size as text
screen_widthSMALLINT UNSIGNEDScreen width in pixels
screen_heightSMALLINT UNSIGNEDScreen height in pixels
content_typeVARCHAR(64)post, page, 404, feed, or a custom type
categoryVARCHAR(256)Category and tag IDs for the content
authorVARCHAR(64)Post author login
content_idBIGINT(20) UNSIGNEDWordPress post ID, 0 if not a post
outbound_resourceVARCHAR(2048)Outbound URL followed from this pageview
tz_offsetSMALLINTVisitor timezone offset
dt_outINT(10) UNSIGNEDTimestamp the visitor left, 0 while unknown
dtINT(10) UNSIGNEDTimestamp the pageview was recorded

Reading these from PHP is covered in the database API methods and retrieving and outputting data in PHP.

Indexes, and the four that are optional

Two indexes on slim_stats are always present besides the primary key: slim_stats_dt_idx on dt, and the composite stats_dt_visit_idx on dt and visit_id. Anything filtering on a date range is therefore already served.

Four more are prefix indexes over long text columns, and they are controlled by Increase Performance (db_indexes) at Settings, Maintenance. The plugin’s own help text puts their cost at roughly 30% extra table size.

IndexCoversOptional
slim_stats_dt_idxdtNo
stats_dt_visit_idxdt, visit_idNo
stats_resource_idxresource(20)Yes
stats_browser_idxbrowser(10)Yes
stats_searchterms_idxsearchterms(15)Yes
stats_fingerprint_idxfingerprint(20)Yes

Each name carries the table prefix, so on a default install the first is wp_slim_stats_dt_idx. A query filtering on a long text column without one of the optional indexes will scan.

The events table

slim_events has seven columns: event_id, type, event_description, notes, position, id and dt. position stores the click coordinates the heatmap report renders, which is a Pro feature — see how to enable and view the heatmap.

The id column is a real foreign key onto slim_stats(id), declared ON UPDATE CASCADE ON DELETE CASCADE, so deleting a pageview deletes its events with it and you never clean up orphans by hand. slim_events_archive carries the same seven columns without the foreign key, because the pageviews it refers to have moved to the archive table.

Querying from your own code

Read through $wpdb rather than opening your own connection, so an install pointing SlimStat at an external database keeps working:

global $wpdb;
$table = $wpdb->prefix . 'slim_stats';

$top = $wpdb->get_results( $wpdb->prepare(
    "SELECT resource, COUNT(*) AS hits
     FROM {$table}
     WHERE dt > %d
     GROUP BY resource
     ORDER BY hits DESC
     LIMIT 10",
    strtotime( '-30 days' )
) );

The slimstat_get_results_sql and slimstat_get_var_sql filters let you modify the queries SlimStat itself runs, and slimstat_custom_wpdb lets you substitute the connection.

What an uninstall removes

Deleting the plugin removes nothing by default. uninstall.php reads the delete_data_on_uninstall setting and returns immediately unless it is on, so stats, settings and tables all survive a delete-and-reinstall. Deactivating never runs the uninstaller at all.

ItemToggle offToggle on
The four analytics tablesKeptDropped
Legacy tables from older versionsKeptDropped
slimstat_options and the other optionsKeptDeleted
Goal, funnel and filter transientsKeptDeleted
The scheduled purge jobClearedCleared

With the toggle on, uninstall also deletes slimstat_visit_id, slimstat_filters, slimstat_tracker_error, the goals and funnels records and their cached transients. On a multisite network it repeats the whole sequence for every non-deleted, non-spam site. Where a Pro external database is configured, it connects to that database to drop the tables there too.

To reclaim space without removing the plugin, use the retention window rather than a manual DROPretention and auto-purge covers what each setting does to old rows and which of them archives rather than deletes.

SlimStat Pro — plans start at $3.25/mo