var mutationObserver = new MutationObserver(function(mutations) { mutations.forEach(function(mutation) { if(mutation.target.innerText.includes(textMessage) && mutation.type === 'attributes') { while(checker) { gtag('event', 'Invio', { 'event_category': 'Form' }); checker = false; } mutationObserver.disconnect(); } }); }); mutationObserver.observe(document.documentElement, { attributes: true, characterData: true, childList: true, subtree: true, attributeOldValue: true, characterDataOldValue: true }); var textMessage = "Grazie...Inizia il Divertimento";