Last active
August 11, 2022 17:54
-
-
Save nikosantis/a8514134e957fa72b3b9faf45401371e to your computer and use it in GitHub Desktop.
This file contains 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
var parentBody = document.getElementsByClassName("bodyclass")[0]; | |
var observer = new MutationObserver(function (mutations, myObserver) { | |
var _iteratorNormalCompletion = true; | |
var _didIteratorError = false; | |
var _iteratorError = undefined; | |
try { | |
for (var _iterator = mutations[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) { | |
var mutation = _step.value; | |
mutation.addedNodes.forEach(function (x) { | |
if (x.childNodes.length === 2) { | |
dataLayer.push({ | |
event: 'formSent' | |
}); | |
myObserver.disconnect(); | |
} else { | |
myObserver.disconnect(); | |
} | |
}); | |
} | |
} catch (err) { | |
_didIteratorError = true; | |
_iteratorError = err; | |
} finally { | |
try { | |
if (!_iteratorNormalCompletion && _iterator.return) { | |
_iterator.return(); | |
} | |
} finally { | |
if (_didIteratorError) { | |
throw _iteratorError; | |
} | |
} | |
} | |
}); | |
document.getElementById("boton-enviar").addEventListener('click', function () { | |
observer.observe(parentBody, { | |
childList: true, | |
subtree: true, | |
attributeOldValue: true | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment