Created
June 16, 2017 11:48
-
-
Save piatra/15e0b3e145ebc4a147fa679a15281d09 to your computer and use it in GitHub Desktop.
track clicks on tiles
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
this._linksReporterMod = new PageMod({ | |
attachTo: ["existing", "top"], | |
contentScript: `links = document.querySelectorAll('.newtab-site') | |
function log_events(pos) { | |
return function log(e) { | |
var target = e.target; | |
var type; | |
while (target) { | |
if (target.tagName === 'a' || target.href) { | |
type = target.parentNode.getAttribute('type'); | |
self.port.emit("tile-click", { | |
action: "CLICK", | |
position: pos, | |
source: type | |
}); | |
break; | |
} | |
target = target.parentNode; | |
} | |
e.preventDefault(); | |
return false; | |
} | |
} | |
for (var i = 0; i < links.length; i++) { | |
links[i].addEventListener("click", log_events(i)); | |
}`, | |
include: "about:newtab", | |
onAttach(worker) { | |
worker.port.on("tile-click", e => reportSitesAction(e)); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment