Save Effect
The saveEffect function is used to save the cleanup function of the side effect produced by ads.
Save effect
Section titled “Save effect”The following example saves the cleanup function to the side effect of the ad produced by div1 placement.
window.htag.api('1').saveEffect( () => { // Cleanup function console.log('Cleanup effect'); }, { tags: ['ad:div1'] });Tag automatic detection
Section titled “Tag automatic detection”As we usually can have multiple placements where the specific creative can be shown, saveEffect function has the feature to detect the correct tags on its own. If called without implicit tags, it will try to find correct tags by searching for a placement structure marked by htag.
window.htag.api('1').saveEffect(() => { // Cleanup function console.log('Cleanup effect');});If this code is executed inside the window context of the ad, it will iterate the DOM up from the frame element in search of <div data-adnz-effect-tag="ad:div1">...</div> structure (marked by htag) and will get the [div1] as tags. If it fails to find the structure, the tags will be ['htag:refresh-page] (which will be refreshed on the next page transition).