Effects
Overview
Section titled “Overview”Some ads leave side effects on the page, such as style additions or elements rendered outside of the placement. The Effects system in Htag helps you clean up these side effects when ads are removed.
How Effects Work
Section titled “How Effects Work”The Effects system provides a way to manage and clean up side effects created by ads. When an ad creates elements, styles, or other changes outside its designated placement, these changes need to be properly removed when the ad is no longer displayed.
Effect Tags
Section titled “Effect Tags”Tags are a powerful feature that allow for selective cleanup. Each effect can be associated with one or more tags, which are used to identify when the effect should be cleaned up.
Known effect tags
Section titled “Known effect tags”| Name | Description |
|---|---|
| The tag is used when it’s necessary to wait for an element or its specific state, for example, the completion of hydration. | |
| Used to track and clean up styles injected into the parent document by Yaleo apps. |
When Effects Are Cleaned Up
Section titled “When Effects Are Cleaned Up”Effects are automatically cleaned up in the following situations:
- When a specific ad is refreshed (cleans up effects tagged with that ad’s ID)
- During page transitions (cleans up effects tagged with
htag:refresh-page) - When explicitly triggered via the clearEffects API
This ensures that side effects don’t persist longer than they should, preventing memory leaks and visual artifacts.
Related Methods
Section titled “Related Methods”- saveEffect: Register a cleanup function
- clearEffects: Manually trigger cleanup of effects