• Resolved brianmcculloh

    (@brianmcculloh)


    Within my ajax success function i have access to the window.advads object and all of its methods. I want to load ads in the new html markup I dynamically added to the page because they’re not loading automatically. I’m assuming I need to manually trigger the ads. Do I use one of the methods on the window.advads object, or is there a different way of triggering the ads within my ajax success function?

Viewing 11 replies - 1 through 11 (of 11 total)
  • Plugin Support Henning

    (@henningaa)

    Hi Brian,

    Thanks for reaching out.

    This article may provide additional information on what to test in your AJAX function.
    If possible, please provide more context about the function you’re using and the website you want to use it on. I would be happy to take a closer look.

    Best regards,
    Henning

    Thread Starter brianmcculloh

    (@brianmcculloh)

    Thank you for your response. I have already read through that article and implemented the recommendations, and I’m still not able to get it to work. The site in mind is here: https://ambcrypto.com/blog/chat-gpt-for-fitness-management/

    You can see as. you scroll to the end of the article, another article automatically loads in, but the in-content ads and sidebar ads, all of which use Advanced Ads for placement, do not appear. After I load the next article, I’m executing this code:

    // Trigger Advanced Ads after new content is appended
    if (typeof window.advads !== 'undefined') {
    console.log('content loaded');
    console.log(window.advads);
    window.advads.checkAds();
    }

    This is what I see in the console:

    content loaded
    mvpcustom.js?ver=1702299603:67 {supports_localstorage: ?, max_per_session: ?, count_up: ?, set_cookie_exists: ?, get_cookie: ?,?…}center_fixed_element: ? (e)center_vertically: ? (e)close: ? (e)cookie_exists: ? (e)count_up: ? (e,t)find_wrapper: ? (e,t)fix_element: ? (e,t)get_cookie: ? (e)max_per_session: ? (e,t)move: ? (e,t,o)privacy: {state: 'not_needed', state_executed: true, get_state: ?, is_adsense_npa_enabled: ?, dispatch_event: ?,?…}set_cookie: ? (e,t,o,a,n,i)set_cookie_exists: ? (e)set_cookie_sec: ? (e,t,o,a,n,i)set_parent_relative: ? (e,t)supports_localstorage: ? ()wait_for_images: ? (e,t)Prototype: Object
    mvpcustom.js?ver=1702299603:80 Error loading next article: TypeError: window.advads.checkAds is not a function
    at mvpcustom.js?ver=1702299603:68:20

    Note the TypeError that is being triggered from the call to window.advads.checkAds();

    So, window.advads exists in the context of my ajax call, but it does not have a method called checkAds(). I’m assuming there’s a method I need to call at this point to load in the new ads, I just don’t know what it is.

    • This reply was modified 11 months, 2 weeks ago by brianmcculloh.
    Plugin Support Henning

    (@henningaa)

    Hi Brian,

    Thanks for the link and code examples.

    Please ensure your AJAX loading articles also contain ad placements by utilizing the general tips from here “Single post not using the loop” and “the_content filter missing”.

    Best regards,
    Henning

    Thread Starter brianmcculloh

    (@brianmcculloh)

    Regarding “the_content filter missing” I can confirm I’m using the_content() rather than get_the_content() for my ajax loaded content using this code:

    ob_start();
    the_content();
    $content_output = ob_get_clean();

    Regarding “single post not using the loop” I do not have this option recommended by the FAQ: “Advanced Ads > Settings > General > Unlimited ad injection” Do I need to have the pro version to see that or something?

    Also, I’m wondering if it’s because of duplicate IDs. This is the code I have in my sidebar widget that loads initially on the page:

    <div id="6633386f-1bee-4b64-997e-3c060893ed52" class="_ap_apex_ad" style="width: 336px; height: 280px;">
    
    <script>
    
    var adpushup = window.adpushup = window.adpushup || {};
    
    adpushup.que = adpushup.que || [];
    
    adpushup.que.push(function() {
    
    adpushup.triggerAd("6633386f-1bee-4b64-997e-3c060893ed52");
    
    });
    
    </script>
    
    </div>

    Then in my infinite scroll loading, I’m calling that same widget again, which would obviously result in the same div id being reused. Is that perhaps what’s causing this?

    Plugin Support schmidt25

    (@schmidt25)

    Hi @brianmcculloh

    Thanks for your reply.

    Regarding “single post not using the loop” I do not have this option recommended by the FAQ: “Advanced Ads > Settings > General > Unlimited ad injection” Do I need to have the pro version to see that or something?

    This mistake comes from our side because we did not update this manual after renaming the function.

    Please navigate to Advanced Ads > Settings > General and search for the option “Content placement in post lists”.

    Best regards,

    Joachim

    Thread Starter brianmcculloh

    (@brianmcculloh)

    I have this enabled already. I tried setting it to 1, 10, and all, and none of the options worked. I also have Disable level limitation checked. The Priority setting is set to 100. Ads load fine in the first article on the page, but still do not load in ajax loaded subsequent posts.

    Could it be the id issue I mentioned previously?

    Plugin Support schmidt25

    (@schmidt25)

    Hi @brianmcculloh,

    Thanks for your reply. The problem might also be connected with the ad code, that throws multiple errors in the browser console. Can you please test if assigning an image ad makes any change?

    Best regards,

    Joachim

    Thread Starter brianmcculloh

    (@brianmcculloh)

    Yes, images work fine. That is what I’ve been trying to say, it’s not that the ad code is not being generated in ajax loaded content, it’s that the javascript code is not being executed in ajax loaded content. There are no errors with the javascript code because it’s the exact same code that loads correctly upon page load. Here is one of the ad spots for reference:

    <div id="6633386f-1bee-4b64-997e-3c060893ed52" class="_ap_apex_ad" style="width: 336px; height: 280px;">
    
    <script>
    
    var adpushup = window.adpushup = window.adpushup || {};
    
    adpushup.que = adpushup.que || [];
    
    adpushup.que.push(function() {
    
    adpushup.triggerAd("6633386f-1bee-4b64-997e-3c060893ed52");
    
    });
    
    </script>
    
    </div>
    Plugin Support schmidt25

    (@schmidt25)

    Sorry, I misunderstood you. I’m afraid only AdPushup will be able to answer that question because Advanced Ads embeds them correctly, and there are now hidden settings to disable JS on AJAX-loaded content that you could change.

    Thread Starter brianmcculloh

    (@brianmcculloh)

    I see, yes that makes sense, thank you.

    Plugin Support schmidt25

    (@schmidt25)

    You are welcome, Brian.

    I am curious if this issue is fixable and I would appreciate it if you could add a follow up message later.

    Best regards,

    Joachim

Viewing 11 replies - 1 through 11 (of 11 total)
  • The topic ‘How to trigger ads in AJAX content’ is closed to new replies.