Effects
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.
Tags htag produces
Section titled “Tags htag produces”htag registers these itself and clears them at the point named below. Use them to hook your own cleanup onto the same moment; do not reuse them for anything else.
| Tag | Cleared when |
|---|---|
ad:{element ID} |
That placement reloads, refreshes, or is removed with removePlacement. This is also the value htag writes to data-adnz-effect-tag, so an effect saved from inside a creative inherits it. |
htag:refresh-page |
A page transition — that is, refreshAds called without elementIds, or with pageTransition: true. Not cleared when named placements are refreshed. |
htag:scheduled-reload |
cancelDelayedReloads cancels every pending reload. |
htag:scheduled-reload:{element ID} |
cancelDelayedReloads({ elementIds }) cancels that placement’s pending reload. |
raw-script:all |
Any refresh that actually runs — refreshAds() with an unchanged URL, no elementIds and no force returns early and clears nothing. Carries the effects of RawJS snippets that are not runOnce. |
Tags by convention
Section titled “Tags by convention”htag never produces these — a caller picks the tag and clears it itself. They are listed because they are established across our own apps and you will meet them in the wild.
| Tag | Used for |
|---|---|
waiting-for-element:{element ID} |
Waiting for an element or a specific state of it, for example the completion of hydration. |
yaleo:parent-document-styles-{random string} |
Styles a Yaleo app injected into the parent document. |
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 — clears
ad:{element ID}for that placement, together withraw-script:all - During page transitions — additionally clears
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