Skip to content

Instantly share code, notes, and snippets.

@ericakfranz
Last active April 25, 2022 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 ericakfranz/acca7ef27f2ab3a2737a5ed1507aca8e to your computer and use it in GitHub Desktop.
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.
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