Last active
April 1, 2025 23:24
-
-
Save vhsu/6c4ec03bc809d11246376eb501721abb to your computer and use it in GitHub Desktop.
GTM Mutation Event
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
<script> | |
var contentDiv = document.querySelector(".et-pb-contact-message"); | |
var MutationObserver = window.MutationObserver || window.WebKitMutationObserver; | |
var observer = new MutationObserver(function(mutations) { | |
mutations.forEach(function(mutation) { | |
if(mutation.type==="childList"&& contentDiv.innerHTML.indexOf("Merci pour votre e-mail") !=-1) { | |
dataLayer.push({'event': 'contactFormSent'}); | |
observer.disconnect(); | |
} | |
}); | |
}); | |
var config = { attributes: false, childList: true, characterData: true } | |
observer.observe(contentDiv, config); | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment