NativeAd allows you to customize the look and feel of ads to match your app’s design. Native ads are presented to users via UI components that are native to the platform.
const nativeAd = new NativeAd({ adUnitId: 'ca-app-pub-xxx/yyy'})await nativeAd.load()// Position ad over a container elementconst container = document.getElementById('ad-container')await nativeAd.showWith(container)
const nativeAd = new NativeAd({ adUnitId: 'ca-app-pub-xxx/yyy'})await nativeAd.load()// Create container for the ad in your contentconst adContainer = document.createElement('div')adContainer.id = 'native-ad-container'adContainer.style.width = '100%'adContainer.style.height = '250px'adContainer.style.margin = '20px 0'// Insert into content (e.g., after 3rd paragraph)const content = document.getElementById('article-content')const paragraphs = content.getElementsByTagName('p')if (paragraphs.length > 3) { paragraphs[2].after(adContainer)}// Show ad in the containerawait nativeAd.showWith(adContainer)
const nativeAd = new NativeAd({ adUnitId: 'ca-app-pub-xxx/yyy'})await nativeAd.load()// Show the adawait nativeAd.show({ x: 0, y: 0, width: 320, height: 250})// Later, hide the adawait nativeAd.hide()// Show it again at a different positionawait nativeAd.show({ x: 0, y: 500, width: 320, height: 250})
const nativeAd = new NativeAd({ adUnitId: 'ca-app-pub-xxx/yyy'})await nativeAd.load()const adContainer = document.getElementById('ad-container')// Show ad and handle window resizeawait nativeAd.showWith(adContainer)// The ad will automatically reposition when:// - Window is resized// - Page is scrolled// - DOM changes occur// Thanks to the MutationObserver and event listeners in showWith()
const nativeAd = new NativeAd({ adUnitId: 'ca-app-pub-xxx/yyy'})await nativeAd.load()// Insert ad into a feed every N itemsfunction insertAdInFeed() { const feed = document.getElementById('feed') const items = feed.querySelectorAll('.feed-item') if (items.length > 5) { // Create ad container const adItem = document.createElement('div') adItem.className = 'feed-item feed-ad' adItem.style.height = '250px' // Insert after 5th item items[4].after(adItem) // Show ad in container nativeAd.showWith(adItem) }}insertAdInFeed()