Dynamic Placements
Overview
Section titled “Overview”Dynamic Placements is a feature that automatically creates div elements for ad placements on the fly. It’s particularly useful for scenarios like infinite scroll pages where you don’t know in advance how many ad slots you’ll need.
How It Works
Section titled “How It Works”Dynamic Placements use XPath expressions to find elements on the page that match certain criteria. When a matching element is found, Htag creates a new div element after it. The system continuously monitors the page for new elements that match the configured XPath expressions.
Monitoring and Refresh
Section titled “Monitoring and Refresh”Dynamic Placements continuously monitor the page for new matching elements. This monitoring happens at regular intervals, allowing Htag to respond to changes in the page structure.
You can pause this monitoring with stopDynamicPlacements. To resume it, use a page-transition refresh: either call refreshAds({ pageTransition: true }), or call refreshAds() for a new URL. A placement-only refresh with elementIds does not resume monitoring by itself.
Note that you still need to create placement definitions matching those dynamically created div elements.
Related Methods
Section titled “Related Methods”- createDynamicPlacement: Define rules for automatically creating div elements
- stopDynamicPlacements: Stop the monitoring loop
- definePlacement: Define ad placements that will be used for dynamically created elements