GPT and React

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:

  1. Ensure that GPT is only loaded once.
  2. Use disableInitialLoad() and refresh() to control when ad requests are made. See Control ad loading and refresh for details.
  3. Use setTargeting() and clearTargeting() to control the targeting applied to ad slots. See Key-value targeting for details.
  4. 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).

Sample implementation