function render_12331(nativeObj, targetId, _apnTargetDivCache) {
    var _apnTargetDivCache = _apnTargetDivCache || [];
function standardizeNativeObj (nativeObj) {
    return {
        type: nativeObj.type,
        title: nativeObj.title,
        body: nativeObj.body || nativeObj.desc,
        desc2: nativeObj.desc2,
        fullText: nativeObj.fullText || nativeObj.full_text,
        icon: nativeObj.icon,
        image: nativeObj.image || nativeObj.main_img,
        cta: nativeObj.cta || nativeObj.ctatext,
        sponsoredBy: nativeObj.sponsoredBy || nativeObj.sponsored,
        impressionTrackers: nativeObj.impressionTrackers || nativeObj.impression_trackers,
        clickTrackers: nativeObj.clickTrackers || (nativeObj.link && nativeObj.link.click_trackers),
        clickUrl: nativeObj.clickUrl || (nativeObj.link && nativeObj.link.url),
        clickFallbackUrl: nativeObj.clickFallbackUrl || (nativeObj.link && nativeObj.link.fallback_url),
        javascriptTrackers: nativeObj.javascriptTrackers || nativeObj.javascript_trackers,
        video: nativeObj.video,
        privacyLink: nativeObj.privacyLink || nativeObj.privacy_link,
        rating: nativeObj.rating,
        displayUrl: nativeObj.displayUrl || nativeObj.displayurl,
        likes: nativeObj.likes,
        downloads: nativeObj.downloads,
        price: nativeObj.price,
        salePrice: nativeObj.salePrice || nativeObj.saleprice,
        phone: nativeObj.phone,
        address: nativeObj.address,

        customTitle1: nativeObj.customTitle1 || nativeObj.title1,
        customTitle2: nativeObj.customTitle2 || nativeObj.title2,
        customTitle3: nativeObj.customTitle3 || nativeObj.title3,
        customTitle4: nativeObj.customTitle4 || nativeObj.title4,
        customTitle5: nativeObj.customTitle5 || nativeObj.title5,

        customBody1: nativeObj.customBody1 || nativeObj.body1,
        customBody2: nativeObj.customBody2 || nativeObj.body2,
        customBody3: nativeObj.customBody3 || nativeObj.body3,
        customBody4: nativeObj.customBody4 || nativeObj.body4,
        customBody5: nativeObj.customBody5 || nativeObj.body5,

        customCta1: nativeObj.customCta1 || nativeObj.ctatext1,
        customCta2: nativeObj.customCta2 || nativeObj.ctatext2,
        customCta3: nativeObj.customCta3 || nativeObj.ctatext3,
        customCta4: nativeObj.customCta4 || nativeObj.ctatext4,
        customCta5: nativeObj.customCta5 || nativeObj.ctatext5,

        customDisplayUrl1: nativeObj.customDisplayUrl1 || nativeObj.displayurl1,
        customDisplayUrl2: nativeObj.customDisplayUrl2 || nativeObj.displayurl2,
        customDisplayUrl3: nativeObj.customDisplayUrl3 || nativeObj.displayurl3,
        customDisplayUrl4: nativeObj.customDisplayUrl4 || nativeObj.displayurl4,
        customDisplayUrl5: nativeObj.customDisplayUrl5 || nativeObj.displayurl5,

        customSocialUrl1: nativeObj.customSocialUrl1 || nativeObj.socialurl1,
        customSocialUrl2: nativeObj.customSocialUrl2 || nativeObj.socialurl2,
        customSocialUrl3: nativeObj.customSocialUrl3 || nativeObj.socialurl3,
        customSocialUrl4: nativeObj.customSocialUrl4 || nativeObj.socialurl4,
        customSocialUrl5: nativeObj.customSocialUrl5 || nativeObj.socialurl5,

        customImage1: nativeObj.customImage1 || nativeObj.image1,
        customImage2: nativeObj.customImage2 || nativeObj.image2,
        customImage3: nativeObj.customImage3 || nativeObj.image3,
        customImage4: nativeObj.customImage4 || nativeObj.image4,
        customImage5: nativeObj.customImage5 || nativeObj.image5,

        customIcon1: nativeObj.customIcon1 || nativeObj.icon1,
        customIcon2: nativeObj.customIcon2 || nativeObj.icon2,
        customIcon3: nativeObj.customIcon3 || nativeObj.icon3,
        customIcon4: nativeObj.customIcon4 || nativeObj.icon4,
        customIcon5: nativeObj.customIcon5 || nativeObj.icon5,

        customSocialIcon1: nativeObj.customSocialIcon1 || nativeObj.socialicon1,
        customSocialIcon2: nativeObj.customSocialIcon2 || nativeObj.socialicon2,
        customSocialIcon3: nativeObj.customSocialIcon3 || nativeObj.socialicon3,
        customSocialIcon4: nativeObj.customSocialIcon4 || nativeObj.socialicon4,
        customSocialIcon5: nativeObj.customSocialIcon5 || nativeObj.socialicon5
    };
}

nativeObj = standardizeNativeObj(nativeObj || {});

var content = '';
var targetContainer = document.getElementById(targetId);
var _getField = function(prop){
    return prop.split('.').reduce(function(a, b) { return a ? a[b] : undefined; }, nativeObj) || '';
};

content += '\x3C!--Entire Ad--\><div class=\"xandr-basic-img-left\">\x3C!--All assets are links--\>\x3C!--Icon--\>    <img class=\"xandr-icon\" src=\"'+ _getField('icon.url') + '\"/>    \x3C!--AdChoices--\>    <div class=\"adchoices\"> <img class=\"xandr-adchoices\" src=\"https://choices.trustarc.com/get?name=admarker-full-tl.png\"/> <\/div>    \x3C!--Image--\>    <img class=\"xandr-image\" src=\"'+ _getField('image.url') + '\"/>    \x3C!--Text Section--\>    <div class=\"xandr-txt-wrapper\">        \x3C!--Sponsored By--\>        <span class=\"xandr-sponsoredBy\">Sponsored by: '+ _getField('sponsoredBy') + '<\/span>        \x3C!--Title--\>        <h1 class=\"xandr-title\">'+ _getField('title') + '<\/h1>        \x3C!--Body Text--\>        <p class=\"xandr-body\">'+ _getField('body') + '<\/p>    <\/div><\/div>\x3C!--Trackers--\>';

content += '<style>\/* Entire Ad */.xandr-basic-img-left {  font-family: Helvetica Neue, Helvetica, Arial, sans-serif;  max-width: 728px;  max-height: 90px;  position: relative;  cursor: pointer;}/* Icon */.xandr-basic-img-left .xandr-icon {    position: absolute;    top: 5px;    left: 5px;    width: 20px;}/* AdChoices */.xandr-basic-img-left .xandr-adchoices {    position: absolute;    top: 0px;    right: 0px;    background: rgba(255, 255, 255, 0.65);}/* Image */.xandr-basic-img-left .xandr-image {  float: left;  margin-right: 15px;  max-width: 24%;}/* Text Wrapper */.xandr-basic-img-left .xandr-txt-wrapper {  overflow: hidden;}/* Sponsored By */.xandr-basic-img-left .xandr-sponsored-by {  color: gray;  font-size: 12px;  font-weight: bold;}/* Title */.xandr-basic-img-left .xandr-title {  font-weight: bold;  color: black;  font-size: 18px;  margin: 4px 0 7px 0;}/* Body Text */.xandr-basic-img-left .xandr-body {  color: gray;  font-size: 12px;  margin: 0;}</style>';

var _apnNewNodesContainer = document.createElement('div');
_apnNewNodesContainer.innerHTML = content;

var _apnChildren, _apnI;   // temp vars

if (_apnTargetDivCache.length > 0) {
    _apnChildren = Array.prototype.slice.call(targetContainer.childNodes);  // Duplicate children to avoid multiple live-DOM operations
    for (_apnI = _apnTargetDivCache.length - 1; _apnI >= 0; _apnI--) {
        var _apnRef = _apnTargetDivCache[_apnI];
        var _apnIdx = _apnChildren.indexOf(_apnRef);
        if (_apnIdx >= 0) {
            targetContainer.removeChild(_apnChildren[_apnIdx]);
        }
        // we want to mutate the original adNodeCache[currentTag.targetId] array (aka _apnTargetDivCache) instead of redefining it
        _apnTargetDivCache.pop();
    }
}

// Slice children so that the childNodes.length doesn't get updated as we remove nodes from the container and append
// it to targetContainer (note: appendChild removes nodes from newNodesContainer).
_apnChildren = Array.prototype.slice.call(_apnNewNodesContainer.childNodes);
while(_apnChildren.length) {
    targetContainer.appendChild(_apnChildren[0]);
    _apnTargetDivCache.push(_apnChildren[0]);
    _apnChildren.shift();
}

const container = document.getElementById(targetId);
container.addEventListener('click', () => {
    window.open(nativeObj.clickUrl, '_blank');
});

document.getElementsByClassName('adchoices')[0]
        .addEventListener('click', function (event) {
           window.open(nativeObj.privacyLink, '_blank'); 
           event.stopPropagation();
        });

// If winning creative doesn't have the optional field privacy link,
// remove corresponding section from the HTML
if(nativeObj.privacyLink === null || nativeObj.privacyLink === undefined || nativeObj.privacyLink === "") {
  container.querySelector('.xandr-adchoices').style.display = "none";
}
;

(function(impTrackers){
    for(var i = 0; i < impTrackers.length; i++) {
        var url = impTrackers[i];
        var img = document.createElement('img');

        img.src = url;
        img.height = 1;
        img.width = 1;
        img.style.display = 'none';

        document.body.appendChild(img);
    }
})(nativeObj.impressionTrackers || []);
(function(javascriptTrackers){
    var parseJsTrackers = function(str) {
        var urls = [], regex = /(?:<script.+?)(?:src=\")(.+?)\".*?>(?:(?:<\/script>|<\/scr' \+ 'ipt>))/g, result;
        while((result = regex.exec(str)) !== null) {
            urls.push(result[1]);
        }
        return urls;
    };

    var jsTrackers = parseJsTrackers(javascriptTrackers) || [];

    for(var i = 0; i < jsTrackers.length; i++) {
        var d = document, scr = d.createElement('script'), tar = d.getElementsByTagName('head')[0];
        scr.type = 'text/javascript'; scr.async = true;
        scr.src = jsTrackers[i];
        tar.insertBefore(scr, tar.firstChild);
    }
})(nativeObj.javascriptTrackers || '');
(function(clickTrackers){
    var fireRequest = function(url) {
        var request = new XMLHttpRequest();
        request.open('GET', url);
        request.withCredentials = true;
        request.send();
    };
    targetContainer.addEventListener('click', function() {
        for(var j = 0; j < clickTrackers.length; j++) {
            fireRequest(clickTrackers[j]);
        }
    });
})(nativeObj.clickTrackers || []);
}

if (window.apntag && window.apntag.registerRenderer) {
    var adNodeCache = window.apnanc = (window.apnanc || {});
    apntag.registerRenderer('12331', {
        renderAd: function(currentTag, handleEventCallback){
            var _apnTargetDivCache = adNodeCache[currentTag.targetId] = (adNodeCache[currentTag.targetId] || []);
            var handler = function handler(adObj) {
                render_12331(adObj['native'], adObj.targetId, _apnTargetDivCache);
                apntag.offEvent('adLoaded', currentTag.targetId, handler);
            }
            apntag.onEvent('adLoaded', currentTag.targetId, handler);
            handleEventCallback(currentTag.targetId, 'adLoaded');
        }
    });
}