I’m posting for the first time after having read through as many posts as I could find that seemed applicable. I’m an amateur dev so much of what I found here was over my head. If you have the time and willingness to look at my problem I’d really appreciate it.
I have a image gallery layout on my site. Each time a user views a new image in the gallery I want to re-execute/re-load an ad code on that page.
The ad code on the page looks like this:
<div class="slide-ads row" id="slide-ads-2" style='width: 300px; margin: 0px auto;'>
<div class="ad-tag" data-ad-name="Rectangle2_newformat" data-ad-size="300x250" ></div>
<script src="//tags-cdn.deployads.com/a/mindpause.co.js" async ></script>
<script>(deployads = window.deployads || []).push({});</script>
</div>
On click I update the content and make a call to my moveAds
function, which causes the ad code to re-execute (and thus to produce a new ad impression) through jQuery’s detach
and appendTo
functions. This is the relevant code:
$('.slide-next, .slide-start').on('click', function (e) {
$current = $(this).closest('article');
if ($current && $current.next().length > 0) {
moveAds($current, $current.next());
$current.hide();
$current.next().show();
}
});
function moveAds($src, $dest) {
$ad2 = $src.find("#slide-ads-2");
$elem = $ad2.detach();
$elem.appendTo($dest.find(".slide-content"));
}
At exactly midnight EST on May 6th this approach stopped working, unexpectedly. The detach
and appendTo
functions simply stopped causing the ad codes to re-execute. I haven’t been able to identify any code change, WordPress update, or any other change that might have caused this (nor has the ad network themselves).
I have two core questions:
-
Are there any obvious culprits that might have caused my approach to work one day and break the next (for ex: core jQuery updates)? What should I be looking for as I attempt to de-bug this?
-
In a single page framework in which content updates without full page refreshes, what is the fastest/most efficient way to re-execute ad code scripts like these? I read this thread but I wasn’t sure if this approach was applicable for my use case:
Should I do something along the lines of what @kelly had answered here?