This sample showcases a basic single-page application (SPA) implementation utilizing Google Publisher Tag (GPT), React, and Next.js.
Some important points to be aware of when working with GPT in SPAs:
- Ensure that GPT is only loaded once.
- Use
disableInitialLoad()
andrefresh()
to control when ad requests are made. See Control ad loading and refresh for details. - Use
setTargeting()
andclearTargeting()
to control the targeting applied to ad slots. See Key-value targeting for details. - Use
destroySlots()
to clean up ad slots that are no longer needed (for example, when ad slot containers are removed due to a component being unloaded).