Created
September 9, 2020 19:19
-
-
Save maestrojed/c21009654e7115d46b2cd7c6398c8fc1 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
// Default to an empty string | |
var source = ""; | |
var medium = ""; | |
var campaign = ""; | |
// Look for and use UTM Source, Medium, and Campaign parameters | |
var sourceParam = new RegExp('[\?&]utm_source=([^&#]*)').exec(window.location.href); | |
if (sourceParam !== null){ | |
source = decodeURI(sourceParam[1]) || 0; | |
} | |
var mediumParam = new RegExp('[\?&]utm_medium=([^&#]*)').exec(window.location.href); | |
if (mediumParam !== null){ | |
medium = decodeURI(mediumParam[1]) || 0; | |
} | |
var campaignParam = new RegExp('[\?&]utm_campaign=([^&#]*)').exec(window.location.href); | |
if (campaignParam !== null){ | |
campaign = decodeURI(campaignParam[1]) || 0; | |
} | |
// Look for and use Linkwell Source, Medium, and Campaign parameters. Override any UTM data | |
sourceParam = new RegExp('[\?&]source=([^&#]*)').exec(window.location.href); | |
if (sourceParam !== null){ | |
source = decodeURI(sourceParam[1]) || 0; | |
} | |
mediumParam = new RegExp('[\?&]medium=([^&#]*)').exec(window.location.href); | |
if (mediumParam !== null){ | |
medium = decodeURI(mediumParam[1]) || 0; | |
} | |
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