virtualPageView and the virtual DOM

AI-generated summary

The discussion revolves around using Google Tag Manager (GTM) to inject ads into the DOM through the virtualPageView event. However, Terrapop faces an issue where ads between posts have not rendered yet when evaluating the ad div containers on virtualPageView, likely due to the virtual DOM not being fully rendered.

A workaround using a timeout has been implemented, but Terrapop seeks a more robust solution, suggesting the need for a “virtualPageLoaded” event that signals when the initial virtual DOM has been fully rendered. This is particularly important due to GDPR and CCPA compliance requirements, which necessitate the use of GTM and a cookie CMP for ad injection, as mentioned by Terrapop.

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?

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.