Skip to content

Instantly share code, notes, and snippets.

@piatra
Created June 16, 2017 11:48
Show Gist options
  • Save piatra/15e0b3e145ebc4a147fa679a15281d09 to your computer and use it in GitHub Desktop.
Save piatra/15e0b3e145ebc4a147fa679a15281d09 to your computer and use it in GitHub Desktop.
track clicks on tiles
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