self.xpln_targeting = function(debug) { var slots = googletag.pubads().getSlots(); for (var i = 0; i < slots.length; i++) { var slot = slots[i]; var unitPath = slot.getAdUnitPath(); var position = slot.getTargeting("pos"); if (position) unitPath = unitPath + ":" + position; var keyValues = get_xpln_targeting(unitPath, debug); for (var key in keyValues) { if (keyValues.hasOwnProperty(key)) { slot.setTargeting(key, keyValues[key]); if (debug) console.log("slot=",unitPath, ", for key=",key,", value=",keyValues[key]); } } } }; self.get_xpln_targeting = function(unitPath, debug) { const data = {}; var getDevice = function() { var w = self.screen.width; if (w<=767) return "Mobile"; if (w<=999) return "Tablet"; return "Desktop"; }; var device = getDevice(); unitPath = unitPath.toLowerCase().replace(/^\//, ''); var targeting = data[device] ? data[device][unitPath] : {}; if (debug) console.log("unitPath=",unitPath, ", device=",device, ", targeting=",targeting); return targeting || {}; }