Skip to content

createDynamicPlacement

Define rules for automatically creating ad placements based on page content. This is particularly useful for content that loads dynamically, such as infinite scroll pages or user-generated content.

window.htag.api('1').createDynamicPlacement({
name: 'article-end-ad',
xpath: '//article',
minDistanceToSimilarAds: 500,
});
  • placementConfig (required): An object with the following properties:
    • name: A unique identifier for the dynamic placement
    • xpath: An XPath expression that identifies where to insert the ad
    • numberOfPlacements (optional): For multiple placements of the same type
    • minDistanceToSimilarAds (optional): Minimum distance in pixels to other ads
    • urlPattern (optional): A regex pattern to match against the current URL

Returns the Htag API object, allowing for method chaining.

When you call createDynamicPlacement, Htag will:

  1. Start monitoring the page for elements matching the XPath expression
  2. When a matching element is found, create a new element after it
  3. Continue monitoring for new matching elements at regular intervals