WPLytic
  • What is WPLytic?
  • Get WPLytic
  • Guides
    • Installing WPLytic
    • Tracking Current WordPress Site
    • Tracking External Websites
    • Updating WPLytic
  • API
    • Tags
    • Events
    • Track pageviews for SPAs
  • Examples
    • External Link Click Tracking
  • Features
    • Statistics and Graphs
      • Realtime Visitors Count
      • Multi-domain view
      • Visitor Stats
      • Top Countries
      • Top Pages
      • Top Referrers
    • Individual Session Explorer
    • Filters - User Segments
    • Tracking and Privacy Settings
  • Extras
    • Troubleshoot
      • Updating fails
    • Support
    • License Terms
  • Guides
    • Tracking UTM parameters
Powered by GitBook
On this page
  1. Guides

Tracking UTM parameters

By default, UTM parameters and not tracked in any way, they are even removed from the saved URL so that the number of unique links stored is reduced.

If you want to store the UTM params for each session, you can automatically tag each session with the name and value of each UTM parameter. Add this after the tracking snippet:

Store UTM parameters as tags
<script>
(function() {
function getParameterByName(name, url = window.location.href) {
    name = name.replace(/[\[\]]/g, '\\$&');
    var regex = new RegExp('[?&]' + name + '(=([^&#]*)|&|#|$)'),
        results = regex.exec(url);
    if (!results) return null;
    if (!results[2]) return '';
    return decodeURIComponent(results[2].replace(/\+/g, ' '));
}

var utms = ['utm_source', 'utm_medium', 'utm_campaign'];
utms.forEach(function(utm) {
   var val = getParameterByName(utm);
   val && WPLY.addTag(utm + ':' + val);
});
})();
</script>

Once you have stored the utm parameters as tags you can create segments and filter sessions based on those tags.

PreviousLicense Terms

Last updated 8 months ago