Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- (function ($) {
- "use strict";
- $(function () {
- /* this function will render ad slot on first render (the ad that already defined on header) */
- /* Article Ad 1 */
- googletag.cmd.push(function () { googletag.display('div-gpt-ad-1'); });
- /* Article Ad 2 */
- googletag.cmd.push(function () { googletag.display('div-gpt-ad-2'); });
- })
- /* this function will define the new ad slot and render it when new post is rendered on autoload posts*/
- $(document).on('jnews-ajax-load', function (event, $newPost) {
- /* Article Ad 1 */
- var $adPlaceholder1 = $newPost.find('.my-ad-class-1');
- $adPlaceholder1.each(function () {
- var uniqueId = 'gpt-ad-1-' + Date.now() + Math.floor(Math.random() * 100);
- $(this).attr('id', uniqueId);
- console.log('uniqueId is generated ' + uniqueId);
- googletag.cmd.push(function () {
- var slot = googletag.defineSlot('/6499/example/banner', [728, 90], uniqueId).addService(googletag.pubads());
- googletag.display(uniqueId);
- googletag.pubads().refresh([slot]);
- });
- });
- /* Article Ad 2 */
- var $adPlaceholder2 = $newPost.find('.my-ad-class-2');
- $adPlaceholder2.each(function () {
- var uniqueId = 'gpt-ad-2-' + Date.now() + Math.floor(Math.random() * 100);
- $(this).attr('id', uniqueId);
- googletag.cmd.push(function () {
- var slot = googletag.defineSlot('/6499/example/banner', [728, 90], uniqueId).addService(googletag.pubads());
- googletag.display(uniqueId);
- googletag.pubads().refresh([slot]);
- });
- });
- });
- })(jQuery);
Advertisement
Add Comment
Please, Sign In to add comment