Last active
January 31, 2022 20:03
-
-
Save ericakfranz/973cc7d834f3457e436e0dd6989fcc4e to your computer and use it in GitHub Desktop.
Specific use-case for a customer to remove the MonsterLink menu item from the site once the campaign has been seen. This will hide the campaign both on the first instance of seeing and closing the campaign, then on subsequent visits when we check if the cookie exists from previously seeing the campaign.
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
// Related, this approach will change the URL to a non-MonsterLink instead of removing the menu item | |
document.addEventListener("DOMContentLoaded", function() { | |
if (document.cookie.split(';').some((item) => item.trim().startsWith('omSeen-swzorfrz48hzwhrtuzal'))) { | |
// define the monsterlink menu item | |
var monsterlink = document.querySelector("#menu-item-9624 .manual-optin-trigger"); | |
// change the URL and remove data-optin-slug attribute | |
monsterlink.setAttribute('href', 'https://home.cognia.org'); | |
monsterlink.removeAttribute('data-optin-slug'); | |
} | |
}); | |
document.addEventListener('om.Campaign.close', function(event) { | |
if (event.detail.Campaign.id === "swzorfrz48hzwhrtuzal") { | |
// define the monsterlink menu item | |
var monsterlink = document.querySelector("#menu-item-9624 .manual-optin-trigger"); | |
// change the URL and remove data-optin-slug attribute | |
monsterlink.setAttribute('href', 'https://home.cognia.org'); | |
monsterlink.removeAttribute('data-optin-slug'); | |
} | |
} ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment