Skip to content

Instantly share code, notes, and snippets.

@maestrojed
Created September 2, 2020 20:29
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/4992390b6083bb45db603be3694c45f2 to your computer and use it in GitHub Desktop.
Save maestrojed/4992390b6083bb45db603be3694c45f2 to your computer and use it in GitHub Desktop.
//get the current query string.
const urlParams = new URLSearchParams(window.location.search);
if( urlParams.has('source') && urlParams.has('medium') && urlParams.has('campaign') ) {
const source = urlParams.get('source');
const medium = urlParams.get('medium');
const campaign = urlParams.get('campaign');
//Before ga("send", "pageview")
//if params were found.
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