Support » Plugin: Google Tag Manager for WordPress » postCountOnPage update value with infinite scroll

  • Resolved js100


    I am using a plugin called Ajax Pagination and Infinite Scroll for showing posts with infinite scroll, so a new set of them are triggered when the scrollbar reaches at the very bottom of the page.
    The plugin integrates a field at backend for a custom Callback, so I would like to update the value of the dataLayer postCountOnPage

    I tried using the code below, but I’m sure I’m missing something.

    dataLayer.push({‘google_tag_params’:{‘event’ : ‘postCountOnPage’}});

    What am I doing wrong?

Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Author Thomas Geiger



    Thanks for letting me know about your issue.

    In that case you will need another JS command. I checked the plugin’s page and this might be the solution although I haven’t tested it and success could depend on the HTML tags in your theme:

    document.addEventListener('malinkyLoadPostsComplete', function(e) {
        "event": "malinkyLoadPostsComplete",
        "postCountOnPage": jQuery("#content .post").length

    The selector “#content .post” might need to be adjusted to fit into your theme’s HTML code.
    With the code above you will need to create a GTM trigger with the type of “Custom Event” and enter malinkyLoadPostsComplete as the event name. You may want to create a virtual pageview tag attached to this event or you might want to add this new trigger to your existing GA pageview tag.

    I hope that helps,
    Thomas Geiger

    Awesome. Works like a charm!

    Thank you very much Thomas!

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘postCountOnPage update value with infinite scroll’ is closed to new replies.