Last active
April 26, 2019 08:54
-
-
Save karolk/75c3e205f0af6f42c74985e9f5d33c53 to your computer and use it in GitHub Desktop.
Click and impression tracking code for espots
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
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