We want to use GTM to inject ads into the DOM. We installed the ads plugin and set up the various empty house ad types with div containers like <div id="adunit_x"></div>
However, when evaluating the id of all ad div containers on virtualPageView the ads between the posts have not rendered, yet. Probably because the virtual dom has not rendered everything on the virtualPageView event that we’re using to trigger the evaluation.
When adding a timeout e.g. 3000ms before evaluating all ad div containers it works.
Is there any event we could leverage in GTM that signals the initial virtual dom has been rendered after virtualPageView has been fired?
2 Likes
We can’t use any of the other standard ad plugin options, as they’re all not GDPR or CCPA conform. Thus, we have to do this via GTM and a cookie CMP that controls if ads can be injected or not (and when).
The virtualPageView is nice, but what’s really missing is another virtualPageLoaded kind of event that is triggered via appEvents.trigger(“virtualPageLoaded”) once all elements and widgets have been loaded for the page in view. Thus, scripts e.g. in GTM can query the final dom tree. When logged in via admin the mini profiler shows how long it took to render the full page, firing such an virtualPageLoaded event at that time would be nice for example.
We have now established a workaround where we wait for the required elements to be accessible, but I don’t like it this way.