Integrating the Google Publisher Tag (GPT) library into your website is in many ways the same as integrating any other third-party script. However, there are some unique aspects of working with GPT that must be considered to ensure you make the most of your ad space with minimal impact to site performance. After all, fast ads matter.
Below we'll cover some best practices you should keep in mind when working on your own integration.
Load GPT from an official source
Always request the GPT library from an official source:
You shouldn't serve versions of gpt.js, pubads_impl.js, or any libraries they load from your own server or load them from an unofficial source.
Using a locally cached version of the GPT may not always work in newer versions of browsers or operating systems and may not be updated with new features and improvements. Older versions of the GPT library can be discontinued at any time and may lead to loss of ad revenue if ads stop serving to your tags.
This also applies to service workers. If you use service
workers to cache or modify responses to HTTP requests coming from your site, use
a network-only strategy when handling requests for
order to fetch an up-to-date version.
Load GPT early
The GPT library (
gpt.js) contains only a small fraction of
the code necessary to load ads. The majority of that code is contained in
separate files (such as
pubads_impl_XX.js), which are loaded by
By loading the core GPT library early, these dependent scripts are also able to be loaded earlier. This avoids any extra latency related to fetching these scripts (if uncached) and allows for ads to be loaded more quickly. All of this contributes to lowering the time to render first ad metric, which in turn increases the viewability of your ads.
Use preload when appropriate
Sometimes you may not be in direct control of when or how GPT
is loaded. For example, when using a third-party ads script which loads
GPT on your behalf. In these cases, it may be appropriate to
preload the request for
gpt.js. Preloading a request instructs the
browser to immediately download a specified asset that is critical to the
contents are fetched immediately but execution is deferred until the script is
Example preload request for standard integrations
<link rel="preload" href="https://securepubads.g.doubleclick.net/tag/js/gpt.js" as="script">
Example preload request for limited ads integrations
<link rel="preload" href="https://pagead2.googlesyndication.com/tag/js/gpt.js" as="script">
Use GPT on prerendered pages
Prerendering instructs the browser to preemptively download and render pages that users have yet to request, but are likely to visit. When loaded on a prerendered page, the GPT library only requests ads if and when the page is made visible.
Load GPT statically
Avoid injecting the GPT library into your page dynamically or
loading it from an external script. Instead, load the library statically in the
<head> of your page as illustrated in
Get Started with Google Publisher Tags. This prevents other
resources from delaying the fetching and loading of the GPT
library, which in turn would delay the loading of ads.
For more details, see the Publisher Ads Audits for Lighthouse load ad scripts statically audit documentation.
Load GPT asynchronously
async keyword in your script tag definition, as illustrated in
Get Started with Google Publisher Tags. This instructs the
browser to load the GPT library in parallel with other
resources and page content, rather than blocking execution until the script is
For more details, see the Publisher Ads Audits for Lighthouse load ad tag asynchronously audit documentation.
Load GPT securely
Always load the GPT library over HTTPS, as illustrated in Get Started with Google Publisher Tags. This not only provides better security for your users, it also improves performance. Since ad requests issued by GPT always use HTTPS, loading the library itself via HTTPS ensures that the browser only needs to open 1 connection for all requests related to ad serving.
Practice good page performance
While the best practices in this guide focus specifically on optimizing your GPT integration, many other factors contribute to the overall performance of your page. When making changes to your site (especially those based on broad recommendations, such as the ones in this guide), it's important to evaluate the impact of those changes on all aspects of your page's performance. It's recommended that you regularly run tools like Lighthouse and Publisher Ads Audits for Lighthouse to identify and address performance issues, and find the right balance of optimizations for your site.