Skip to content

Instantly share code, notes, and snippets.

@NHinternesch
Last active October 10, 2019 16:28
Show Gist options
  • Save NHinternesch/9ddeae12ba1cb426212dfccf4788558e to your computer and use it in GitHub Desktop.
Save NHinternesch/9ddeae12ba1cb426212dfccf4788558e to your computer and use it in GitHub Desktop.
Tracking Honey
var honeyObserver;
var callback = function(mutations){
// look through all mutations that have just occurred
for (var i = 0; i < mutations.length; i++){
// look through all added nodes of this mutation
for (var j = 0; j < mutations[i].addedNodes.length; j++){
var node = mutations[i].addedNodes[j];
// Look for created elements and check whether they have the right ID
if ((node.nodeType === Node.ELEMENT_NODE) && (node.id === "honeyContainer")){
// DO SOMETHING; send a tracking-event hit etc.
console.log('Honey was active');
// Optional: Stop observing and return when Honey-div has been detected
honeyObserver.disconnect();
return;
}
}
}
}
honeyObserver = new MutationObserver(callback);
//optional: select the relevant top container element; defaults to document.body
var container = $(document.body);
honeyObserver.observe(document.body, {
childList: true,
subtree: true
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment