This section contains a collection of examples and related resources for the Google Publisher Tag (GPT) library.
Much of the content in this section can also be found in our GitHub repository. Sample code and associated documentation is released as open source under the Apache License 2.0.
Try building you own custom sample with the GPT sample builder (beta)!
Control SRA batching
Precisely control which ad slots are requested when in Single Request Architecture (SRA) mode.
- JavaScript
- TypeScript
Display ads in the shadow DOM
Use GPT to request and render ads in the shadow DOM.
- TypeScript
- JavaScript
Display an H5 gaming interstitial ad
Display a GPT-managed gaming interstitial ad.
- JavaScript
- HTML
- TypeScript
Display a limited ad
Display an ad in the absence of consent for the use of cookies or other local identifiers.
- TypeScript
- JavaScript
Collapse empty ad slots
Automatically show/hide ad slots when certain criteria are met.
- TypeScript
- JavaScript
Key-value targeting
Use key-value targeting to control the ads eligible to serve to specific ad slots.
- JavaScript
- TypeScript