Skip to content

Instantly share code, notes, and snippets.

@maestrojed
Created September 2, 2020 20:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save maestrojed/bd21fd8edd515a4657fdb4da1a78625e to your computer and use it in GitHub Desktop.
Save maestrojed/bd21fd8edd515a4657fdb4da1a78625e to your computer and use it in GitHub Desktop.
var source = "";
var medium = "";
var campaign = "";
const sourceParam = new RegExp('[\?&]source=([^&#]*)').exec(window.location.href);
if (sourceParam !== null){
source = decodeURI(sourceParam[1]) || 0;
}
const mediumParam = new RegExp('[\?&]medium=([^&#]*)').exec(window.location.href);
if (mediumParam !== null){
medium = decodeURI(mediumParam[1]) || 0;
}
const campaignParam = new RegExp('[\?&]campaign=([^&#]*)').exec(window.location.href);
if (campaignParam !== null){
campaign = decodeURI(campaignParam[1]) || 0;
}
ga('set', 'campaignSource', source);
ga('set', 'campaignMedium', medium);
ga('set', 'campaignName', campaign);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment