Monday, November 2 2015

JavaScript - decoding the url to get value from traffic source campaign - Universal Analytics

/* get value by name from the url */

function getParameterByName(name) {

 name = name.replace(/[/, "\[").replace(/]/, "\]");
 var regex = new RegExp("\\?&" + name + "=(^&#*)"),
       results = regex.exec(location.search);
 return results == null ? null : decodeURIComponent(results1.replace(/\+/g, " "));

}

/* assign global variables with the values of "traffic source" from url */

var campaign = getParameterByName('utm_campaign');

var medium = getParameterByName('utm_medium');

var source = getParameterByName('utm_source');

var content = getParameterByName('utm_content');

Page top