UXWizz
Searchโ€ฆ
Tracking UTM parameters
Example of reading and storing URL query parameters for each session.
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
1
<script>
2
(function() {
3
function getParameterByName(name, url = window.location.href) {
4
name = name.replace(/[\[\]]/g, '\\amp;');
5
var regex = new RegExp('[?&]' + name + '(=([^&#]*)|&|#|$)'),
6
results = regex.exec(url);
7
if (!results) return null;
8
if (!results[2]) return '';
9
return decodeURIComponent(results[2].replace(/\+/g, ' '));
10
}
11
โ€‹
12
var utms = ['utm_source', 'utm_medium', 'utm_campaign'];
13
utms.forEach(function(utm) {
14
utm && UST.addTag(utm + ':' + getParameterByName(utm));
15
});
16
})();
17
</script>
Copied!
Once you have stored the utm parameters as tags you can create segments and filter sessions based on those tags.
Copy link