Skip to content

Instantly share code, notes, and snippets.

View agarbund's full-sized avatar

Adrian Ślipko agarbund

  • Wrocław, Poland
View GitHub Profile
// script which reads UTM params from the URL and adds them to all links on the current page
$(document).ready(function() {
var utms = ['medium', 'source', 'campaign', 'term', 'content'], utmStrings = [];
var domain = ''; // add domain here, only links to given domain will be siffixed with utm params
var domainRegexp = new RegExp(domain.replace(/\./g, '\\.'));
utms.forEach(function(utm) {
var match = window.location.search.match(new RegExp('utm_' + utm + '=([^&]+)'));
if(match) {
utmStrings.push('utm_' + utm + '=' + match[1]);
}