Configuration

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_statsTypeWhat SlimStat writes thereHolds UTM tags?
resourceVARCHAR(2048)Path plus query string of the page viewedYes, verbatim
refererVARCHAR(2048)Full referring URL, query string intactOnly the referrer’s own
outbound_resourceVARCHAR(2048)External link the visitor clickedOnly the link’s own
searchtermsVARCHAR(2048)Term taken from a search engine referrerNo
notesVARCHAR(2048)Annotations stored alongside the pageviewOnly 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.

  1. Open SlimStat, then the Overview screen, in your WordPress admin.
  2. Set Dimension to Permalink.
  3. Set the operator to contains.
  4. Type utm_campaign in the value box and submit the filter.
  5. Read Top Web Pages, which now lists only tagged URLs.
  6. 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.

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 typeOperatorResult against a stored URL
utm_campaigncontainsMatches, underscores and letters survive
august-salecontainsMatches, hyphens survive
utm_campaign=august-salecontainsMatches nothing, = became %3D
utm_campaign.august-salematchesMatches, 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.

SlimStat Pro — plans start at $3.25/mo