Created
September 2, 2020 20:26
-
-
Save maestrojed/bd21fd8edd515a4657fdb4da1a78625e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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