Skip to content

Instantly share code, notes, and snippets.

@karolk
Last active April 26, 2019 08:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save karolk/75c3e205f0af6f42c74985e9f5d33c53 to your computer and use it in GitHub Desktop.
Save karolk/75c3e205f0af6f42c74985e9f5d33c53 to your computer and use it in GitHub Desktop.
Click and impression tracking code for espots
if (typeof handleTrackableClickEvent !== "function") {
var handleTrackableClickEvent = function(event) {
var trackableSelector = '.trackable';
if (event.target) {
// msMatches is for IE
var matches = event.target.matches || event.target.msMatches;
if (matches && matches.call(event.target, trackableSelector)) {
var et = event.target;
dLayer = {
"promo_spot_id": et.getAttribute("promo_spot_id"),
"promo_spot_name": et.getAttribute("promo_spot_name"),
"promo_spot_creative": et.getAttribute("promo_spot_creative"),
};
postMessageToHost({
type: "trackContentEspotClick",
otherData: dLayer
})
}
}
}
// set up click tracking
document.addEventListener(
'click',
handleTrackableClickEvent,
{ capture: true, passive: true }
);
}
// send impression tracking
postMessageToHost({
type: "trackContentEspotImpression",
otherData: {
"promo_spot_id": "promo_spot_id",
"promo_spot_name": "promo_spot_name",
"promo_spot_creative": "promo_spot_creative"
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment