[[["容易理解","easyToUnderstand","thumb-up"],["確實解決了我的問題","solvedMyProblem","thumb-up"],["其他","otherUp","thumb-up"]],[["缺少我需要的資訊","missingTheInformationINeed","thumb-down"],["過於複雜/步驟過多","tooComplicatedTooManySteps","thumb-down"],["過時","outOfDate","thumb-down"],["翻譯問題","translationIssue","thumb-down"],["示例/程式碼問題","samplesCodeIssue","thumb-down"],["其他","otherDown","thumb-down"]],["上次更新時間:2024-11-24 (世界標準時間)。"],[[["\u003cp\u003eAlways load the Google Publisher Tag (GPT) library from an official source to ensure compatibility and access to the latest features.\u003c/p\u003e\n"],["\u003cp\u003eAvoid serving cached or unofficial versions of GPT to prevent potential functionality and revenue loss.\u003c/p\u003e\n"],["\u003cp\u003eImprove ad loading speed by loading the GPT library early in the \u003ccode\u003e<head>\u003c/code\u003e of your page, using preload when appropriate, and enabling asynchronous loading.\u003c/p\u003e\n"],["\u003cp\u003eEnsure optimal security and performance by loading GPT over HTTPS and employing best practices for overall page performance.\u003c/p\u003e\n"],["\u003cp\u003eUse GPT on prerendered pages to preemptively download and render pages while only requesting ads when the page is visible.\u003c/p\u003e\n"]]],["To optimize Google Publisher Tag (GPT) integration, load it from official sources using the provided script tags, with the standard or limited ads URL as appropriate. Avoid cached or unofficial versions, and load GPT early and statically in the page's `\u003chead\u003e` using `async`. Use preload for third-party loading, and ensure HTTPS for security and efficiency. Utilize prerendering, and regularly assess site performance using tools like Lighthouse to ensure minimal impact to site performance.\n"],null,["# General Best Practices\n\nIntegrating the Google Publisher Tag (GPT) library into your website\nis in many ways the same as integrating any other third-party script. However,\nthere are some unique aspects of working with GPT that must be\nconsidered to ensure you make the most of your ad space with minimal impact to\nsite performance. After all, [fast ads matter](//web.dev/fast-ads-matter/).\n\nThe following sections cover the best practices to use when working on your\nintegration.\n\nLoad GPT from an official source\n--------------------------------\n\nAlways request the GPT library from an official source:\n\n| Integration type | Script tag |\n|------------------------------------------------------------------------------------------------------------------------------------------------|------------------------------------------------------------------------------------------------------------------------|\n| **Standard** Including publishers integrated with the [IAB Europe TCF](//support.google.com/admanager/answer/9805023). | ```html \u003cscript src=\"https://securepubads.g.doubleclick.net/tag/js/gpt.js\" crossorigin=\"anonymous\" async\u003e\u003c/script\u003e ``` |\n| **Limited ads** For publishers who want to manually enable [limited ads](/publisher-tag/reference#googletag.PrivacySettingsConfig_limitedAds). | ```html \u003cscript src=\"https://pagead2.googlesyndication.com/tag/js/gpt.js\" async\u003e\u003c/script\u003e ``` |\n\nOnly use the limited ads URL on sites where you intend to manually enable\n[limited ads](/publisher-tag/reference#googletag.PrivacySettingsConfig_limitedAds). Requesting GPT from the limited ads\nURL when this feature is not in use causes the browser to open an\nadditional, unnecessary network connection, which may slow down ad loading.\n| **Important:** When a Consent Management Platform (CMP) is in use, it is not necessary to manually enable limited ads.\n\nTo aid in publisher regulatory compliance needs, GPT may be\nloaded from the standard URL with the [`crossorigin=\"anonymous\"`](//developer.mozilla.org/docs/Web/HTML/Attributes/crossorigin)\nattribute to prevent cookies from being sent with the script request.\n\n### Don't serve cached versions of GPT\n\nNever serve versions of `gpt.js`, `pubads_impl.js`, or any libraries they load\nfrom your own server or load them from an unofficial source.\n\nUsing a locally cached version of the GPT library may not\nalways work in newer versions of browsers or operating systems and may not be\nupdated with new features and improvements. Earlier versions of the\nGPT library may stop working at any time and may lead to\nloss of ad revenue if ads stop serving to your tags.\n\nThis also applies to [service workers](//developer.mozilla.org/docs/Web/API/Service_Worker_API). If you use service\nworkers to cache or modify responses to HTTP requests coming from your site, use\na [network-only strategy](//developer.chrome.com/docs/workbox/caching-strategies-overview/#network-only) when handling requests for `gpt.js` in\norder to fetch an up-to-date version.\n\nLoad GPT early\n--------------\n\nThe GPT library (`gpt.js`) contains only a small fraction of\nthe code necessary to load ads. The majority of that code is contained in\nseparate files (such as `pubads_impl_XX.js`), which are loaded by `gpt.js` as\nneeded.\n\nBy loading the core GPT library early, these dependent scripts\nare also able to be loaded earlier. This avoids any extra latency related to\nfetching these scripts (if uncached) and allows for ads to be loaded more\nquickly. All of this contributes to lowering the\n[time to render first ad metric](/publisher-ads-audits/reference/audits/first-ad-render), which in turn increases\nthe viewability of your ads.\n\n### Use preload when appropriate\n\nSometimes you may not be in direct control of when or how GPT\nis loaded. For example, when using a third-party ads script which loads\nGPT on your behalf. In these cases, it may be appropriate to\npreload the request for `gpt.js`. [Preloading a request](//developers.google.com/web/tools/lighthouse/audits/preload) instructs the\nbrowser to immediately download a specified asset that is critical to the\nloading of your page. When the specified asset is a JavaScript file, the script\ncontents are fetched immediately but execution is deferred until the script is\nneeded.\n\n#### Example preload request for standard integrations\n\n \u003clink rel=\"preload\" href=\"https://securepubads.g.doubleclick.net/tag/js/gpt.js\" as=\"script\"\u003e\n\n#### Example preload request for limited ads integrations\n\n \u003clink rel=\"preload\" href=\"https://pagead2.googlesyndication.com/tag/js/gpt.js\" as=\"script\"\u003e\n\n| **Note:** preload links are not respected by all browsers. See [Can I Use link-rel-preload?](//caniuse.com/#feat=link-rel-preload) for an overview of browser support.\n\n### Use GPT on prerendered pages\n\n[Prerendering](//developer.chrome.com/blog/prerender-pages/) instructs the browser to preemptively download and\nrender pages that users have yet to request, but are likely to visit. When\nloaded on a prerendered page, the GPT library only requests\nads if and when the page is made visible.\n\nLoad GPT statically\n-------------------\n\nAvoid injecting the GPT library into your page dynamically or\nloading it from an external script. Instead, load the library statically in the\n`\u003chead\u003e` of your page as illustrated in\n[Get Started with Google Publisher Tags](/publisher-tag/guides/get-started). This prevents other\nresources from delaying the fetching and loading of the GPT\nlibrary, which in turn would delay the loading of ads.\n\nFor more details, see the Publisher Ads Audits for Lighthouse\n[load ad scripts statically](/publisher-ads-audits/reference/audits/script-injected-tags) audit documentation.\n\nLoad GPT asynchronously\n-----------------------\n\nInclude the `async` keyword in your script tag definition, as illustrated in\n[Get Started with Google Publisher Tags](/publisher-tag/guides/get-started). This instructs the\nbrowser to load the GPT library in parallel with other\nresources and page content, rather than blocking execution until the script is\ndone loading.\n\nFor more details, see the Publisher Ads Audits for Lighthouse\n[load ad tag asynchronously](/publisher-ads-audits/reference/audits/async-ad-tags) audit documentation.\n\nLoad GPT securely\n-----------------\n\nAlways load the GPT library over HTTPS, as illustrated in\n[Get Started with Google Publisher Tags](/publisher-tag/guides/get-started). This not only\nprovides better security for your users, it also improves performance. Since ad\nrequests issued by GPT always use HTTPS, loading the library\nitself using HTTPS ensures that the browser only needs to open 1 connection for\nall requests related to ad serving.\n\nFor more details, see the Publisher Ads Audits for Lighthouse\n[load ad tag over HTTPS](/publisher-ads-audits/reference/audits/loads-ad-tag-over-https) and\n[load GPT from recommended host](/publisher-ads-audits/reference/audits/loads-gpt-from-sgdn)\naudit documentation.\n\nPractice good page performance\n------------------------------\n\nWhile the best practices in this guide focus specifically on optimizing your\nGPT integration, many other factors contribute to the overall\nperformance of your page. When making changes to your site (especially those\nbased on broad recommendations, such as the ones in this guide), it's important\nto evaluate the impact of those changes on all aspects of your page's\nperformance. It's recommended that you regularly run tools like\n[Lighthouse](//developers.google.com/web/tools/lighthouse) and\n[Publisher Ads Audits for Lighthouse](/publisher-ads-audits) to identify and address\nperformance issues, and find the right balance of optimizations for your site."]]