Tracking UTM and Campaign Parameters
Applies to SlimStat 5.5.0 · checked
SlimStat records UTM parameters, but keeps no utm_source or utm_campaign column. The full request path and query string are written verbatim into one field, resource, a VARCHAR(2048) column on wp_slim_stats. Campaign reporting therefore runs through filters, SQL or shortcodes aimed at resource, rather than through a dedicated campaign report.
Column in wp_slim_stats | Type | What SlimStat writes there | Holds UTM tags? |
|---|---|---|---|
resource | VARCHAR(2048) | Path plus query string of the page viewed | Yes, verbatim |
referer | VARCHAR(2048) | Full referring URL, query string intact | Only the referrer’s own |
outbound_resource | VARCHAR(2048) | External link the visitor clicked | Only the link’s own |
searchterms | VARCHAR(2048) | Term taken from a search engine referrer | No |
notes | VARCHAR(2048) | Annotations stored alongside the pageview | Only if you add them |
Which column holds your UTM parameters
src/Tracker/Processor.php line 194 falls back to wp_slimstat::get_request_uri(), then rebuilds resource as path, query string and fragment. A visit to /landing/?utm_source=newsletter&utm_campaign=august is stored exactly that way. The Top Web Pages report groups by resource, so every UTM variant of one page becomes its own row.
Neither SlimStat nor SlimStat Pro declares a utm_* column, so nothing splits utm_source from utm_medium for you. The searchterms column is not a substitute: src/Tracker/Utils.php line 480 fills it from the referring search engine’s own query parameter, matched against admin/assets/data/matomo-searchengine.json, and never reads utm_term. Full column list: SlimStat database tables and columns.
Filter any report by campaign
Every SlimStat report screen carries a filter bar with three controls: a Dimension select, an operator select and a value box. Choose the dimension labelled Permalink, which maps to the resource column at admin/view/wp-slimstat-db.php line 66, and campaign traffic separates out of every report on that screen at once.
- Open SlimStat, then the Overview screen, in your WordPress admin.
- Set Dimension to Permalink.
- Set the operator to contains.
- Type
utm_campaignin the value box and submit the filter. - Read Top Web Pages, which now lists only tagged URLs.
- Click Save beside the active filter to store the filter permanently.
Saved filters appear behind a Saved Filters button in the filter bar, and a Reset All button clears the active set. To narrow further, add a second filter such as Country Code equals us: filters combine with AND, as described in combining multiple keys and values.
Why an equals sign breaks a Permalink filter
admin/view/wp-slimstat-db.php line 417 runs every resource filter value through urlencode(), one path segment at a time, so utm_source=newsletter becomes utm_source%3Dnewsletter and the generated LIKE matches nothing. Filter on the parameter name alone, on the campaign value alone, or use the matches operator with a dot.
| Value you type | Operator | Result against a stored URL |
|---|---|---|
utm_campaign | contains | Matches, underscores and letters survive |
august-sale | contains | Matches, hyphens survive |
utm_campaign=august-sale | contains | Matches nothing, = became %3D |
utm_campaign.august-sale | matches | Matches, the dot is a regex wildcard |
Count campaigns with SQL or a shortcode
One SQL statement against wp_slim_stats produces per-source totals that no built-in report gives you. dt is a Unix timestamp and resource carries the raw query string, so SUBSTRING_INDEX can split each source out of the stored URL. Swap wp_ for whatever $table_prefix your wp-config.php sets.
SELECT SUBSTRING_INDEX(SUBSTRING_INDEX(resource, 'utm_source=', -1), '&', 1) AS source,
COUNT(*) AS pageviews
FROM wp_slim_stats
WHERE resource LIKE '%utm_source=%'
AND dt >= UNIX_TIMESTAMP('2026-08-01')
GROUP BY source
ORDER BY pageviews DESC;
The slimstat shortcode reaches the same rows from a page or widget, through the same filter parser, so the equals-sign rule above applies here too:
[slimstat f='top' w='resource']resource contains utm_campaign&&&limit_results equals 20[/slimstat]
Shortcode attributes and criteria are covered in mastering SlimStat shortcodes. Exporting a report to Excel from its header button is a SlimStat Pro feature, so on the free plugin use the SQL route or the shortcode.
Stop recording UTM parameters
Two routes remove UTM strings from your data. slimstat_filter_pageview_stat, applied at src/Tracker/Processor.php line 431 immediately before the insert, lets a callback rewrite $stat['resource']. Settings, then Exclusions, then Page Properties, then Permalinks instead discards the whole pageview, because ignore_resources patterns are anchored and drop the row entirely.
add_filter('slimstat_filter_pageview_stat', function ($stat) {
if (empty($stat['resource']) || false === strpos($stat['resource'], '?')) {
return $stat;
}
list($path, $qs) = explode('?', $stat['resource'], 2);
parse_str($qs, $params);
foreach (array_keys($params) as $key) {
if (0 === strpos($key, 'utm_')) {
unset($params[$key]);
}
}
$query = http_build_query($params);
$stat['resource'] = $path . ('' === $query ? '' : '?' . $query);
return $stat;
});
slimstat_filter_pageview_stat runs before the row is written, so the rewrite applies to new pageviews only and leaves existing rows untouched. Entering *utm_source=* in the Permalinks exclusion box is the blunter option, and it stops the pageview being recorded at all rather than merely cleaning the URL. Hook arguments are documented in slimstat_filter_pageview_stat.