Handling responsive ads
-
Hi!
So… I’m building a site which utilizes ads but they need to be responsive. A top banner cannot be visible for mobile.
It’s easy enough to put a widget in i.e. “Header” and hide it with media-queries, but the ads still loads and the stats will still increase.
By adding, to sam.pro.layout.min.js, a condition in the each-loop, we could avoid this. You’ll see it by searching for the lines with:
if(n("#" + this.id).is(':hidden')) { return true; }In the file:
(function(n) { n(document).ready(function() { var t = samProOptions, u = t.doStats == "1", i = t.wap, o = 1 == parseInt(t.jsStats, 10), l = t.mailer == "1", h = t.load == "1", r = t.au, c = t.clauses, f = [], s = [], e; h ? (u && (n("div." + t.place + ", span." + t.place).each(function(t, u) { var s = this.id.split("_") , e = s[1] , o = s[2]; f.push({ aid: e, pid: o }); n(u).find("a").bind("click", function() { n.post(r, { action: "sam_click", aid: e, pid: o, wap: i }) }); n(u).find("iframe").iframeTracker({ blurCallback: function() { n.post(r, { action: "sam_click", aid: e, pid: o, wap: i }) } }) }), o && n.post(r, { action: "sam_hits", hits: f, wap: i })), e = [], n("div." + t.ad + ", span." + t.ad).each(function(t, i) { if(n("#" + this.id).is(':hidden')) { return true; } var r = n(i).data("spc"); "undefined" == typeof r && (r = 0); var u = this.id.split("_") , f = u[1] , o = u[2]; e.push({ pid: o, aid: f, codes: r, eid: this.id }) }), e.length > 0 && n.post(r, { action: "load_ads", ads: e, data: c, wap: i }).done(function(t) { t.success && n.each(t.data, function(t, f) { if (n("#" + f.eid).replaceWith(f.ad), u) { var e = n("#" + f.cid); e.find("a").bind("click", function() { n.post(r, { action: "sam_click", aid: f.aid, pid: f.pid, wap: i }) }); e.find("iframe").iframeTracker({ blurCallback: function() { n.post(r, { action: "sam_click", aid: f.aid, pid: f.pid, wap: i }) } }); s.push({ pid: f.pid, aid: f.aid }) } }); u && o && n.post(r, { action: "sam_hits", hits: s, wap: i }) })) : u && (n("div." + t.container + ", span." + t.container).each(function(t, u) { var s = this.id.split("_") , e = s[1] , o = s[2]; f.push({ aid: e, pid: o }); n(u).find("a").bind("click", function() { n.post(r, { action: "sam_click", aid: e, pid: o, wap: i }) }); n(u).find("iframe").iframeTracker({ blurCallback: function() { n.post(r, { action: "sam_click", aid: e, pid: o, wap: i }) } }) }), o && n.post(r, { action: "sam_hits", hits: f, wap: i }) ) }) })(jQuery)I’m going to build a small plugin which removes a hit from the ad if it’s in a <div class=”ad banner”> as a temporary solution.
The topic ‘Handling responsive ads’ is closed to new replies.