Last active
April 25, 2022 20:26
-
-
Save ericakfranz/acca7ef27f2ab3a2737a5ed1507aca8e to your computer and use it in GitHub Desktop.
Creates a {{referrer}} custom smart tag in OptinMonster to output the referrer URL, or if it is empty redirect to another specific URL. Typically used in the "redirect to a URL" success action for an optin form or button element.
This file contains hidden or 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
function myReferrer() { | |
var ref = document.referrer; | |
if(!ref) { | |
// redirect to a specific URL if referrer doesn't exist | |
var redirect = 'https://optinmonster.com'; | |
} else var redirect = ref; | |
// Let's print what referrer is being passed into the dev tools console, remove this in production | |
console.log(ref); | |
// And return our referrer variable. | |
return ref; | |
} | |
myReferrer(); | |
const addRef = myReferrer(); | |
// custom smart tag in OM | |
document.addEventListener('om.Dtr.init', function (event) { | |
event.detail.Dtr.setCustomVariable('referrer', addRef); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment