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 suffix | Primary key | What it stores |
|---|---|---|
slim_stats | id | One row per tracked pageview, 33 columns |
slim_stats_archive | id | Purged pageviews, created LIKE slim_stats |
slim_events | event_id | Outbound clicks and other events |
slim_events_archive | event_id | Purged 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_statson your own install before writing anything that depends on a column’s exact type.
Every column in wp_slim_stats
| Column | Type | What it holds |
|---|---|---|
id | INT UNSIGNED, auto increment | Primary key |
ip | VARCHAR(39) | Visitor IP, anonymised or hashed per your settings |
other_ip | VARCHAR(39) | Originating IP behind a proxy, when present |
username | VARCHAR(256) | WordPress login, for logged-in visitors |
email | VARCHAR(256) | Commenter email, where one was left |
country | VARCHAR(16) | Two-letter country code, lowercased |
location | VARCHAR(36) | Coordinates as latitude,longitude |
city | VARCHAR(256) | City, at City geolocation precision only |
referer | VARCHAR(2048) | The URL that sent this visit |
resource | VARCHAR(2048) | The permalink that was requested |
searchterms | VARCHAR(2048) | Search terms parsed from the referrer |
notes | VARCHAR(2048) | Tracker annotations for this hit |
visit_id | INT UNSIGNED | Groups pageviews into one visit, 0 if none |
server_latency | INT(10) UNSIGNED | Milliseconds your server took to reply |
page_performance | INT(10) UNSIGNED | Milliseconds the browser took to render |
browser | VARCHAR(40) | Browser name |
browser_version | VARCHAR(15) | Browser version |
browser_type | TINYINT UNSIGNED | Desktop, crawler, mobile or touch |
platform | VARCHAR(15) | Operating system |
language | VARCHAR(5) | Browser language code |
fingerprint | VARCHAR(256) | Anonymous identifier, when one is collected |
user_agent | VARCHAR(2048) | Full user-agent string |
resolution | VARCHAR(12) | Viewport size as text |
screen_width | SMALLINT UNSIGNED | Screen width in pixels |
screen_height | SMALLINT UNSIGNED | Screen height in pixels |
content_type | VARCHAR(64) | post, page, 404, feed, or a custom type |
category | VARCHAR(256) | Category and tag IDs for the content |
author | VARCHAR(64) | Post author login |
content_id | BIGINT(20) UNSIGNED | WordPress post ID, 0 if not a post |
outbound_resource | VARCHAR(2048) | Outbound URL followed from this pageview |
tz_offset | SMALLINT | Visitor timezone offset |
dt_out | INT(10) UNSIGNED | Timestamp the visitor left, 0 while unknown |
dt | INT(10) UNSIGNED | Timestamp 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.
| Index | Covers | Optional |
|---|---|---|
slim_stats_dt_idx | dt | No |
stats_dt_visit_idx | dt, visit_id | No |
stats_resource_idx | resource(20) | Yes |
stats_browser_idx | browser(10) | Yes |
stats_searchterms_idx | searchterms(15) | Yes |
stats_fingerprint_idx | fingerprint(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.
| Item | Toggle off | Toggle on |
|---|---|---|
| The four analytics tables | Kept | Dropped |
| Legacy tables from older versions | Kept | Dropped |
slimstat_options and the other options | Kept | Deleted |
| Goal, funnel and filter transients | Kept | Deleted |
| The scheduled purge job | Cleared | Cleared |
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 DROP — retention and auto-purge covers what each setting does to old rows and which of them archives rather than deletes.