Skip to content

Instantly share code, notes, and snippets.

@vhsu
Last active March 13, 2020 03:02
Show Gist options
  • Save vhsu/6c4ec03bc809d11246376eb501721abb to your computer and use it in GitHub Desktop.
Save vhsu/6c4ec03bc809d11246376eb501721abb to your computer and use it in GitHub Desktop.
GTM Mutation Event
<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