โหลดสคริปต์โฆษณาแบบคงที่
จัดทุกอย่างให้เป็นระเบียบอยู่เสมอด้วยคอลเล็กชัน
บันทึกและจัดหมวดหมู่เนื้อหาตามค่ากำหนดของคุณ
ภาพรวม
การตรวจสอบนี้จะตรวจสอบว่ามีการแทรกสคริปต์โฆษณาลงในหน้าเว็บหรือไม่
ทรัพยากรอื่นๆ ในหน้าเว็บอาจทำให้การดึงข้อมูลและโหลดข้อมูลที่แทรกได้ล่าช้า
สคริปต์ ซึ่งทำให้การโหลดโฆษณาล่าช้า ในบางสถานการณ์ เหตุการณ์เหล่านี้
สคริปต์อาจไม่ถูกดึงข้อมูลเลย ทำให้ไม่สามารถโหลดโฆษณาได้
คำแนะนำ
โหลดสคริปต์ผ่านแท็กสคริปต์แบบไม่พร้อมกันเพื่อเพิ่มความเร็ว ตัวสแกนการโหลดล่วงหน้าของเบราว์เซอร์
สามารถดึงข้อมูลแท็กสคริปต์ก่อนหน้านี้ แม้ว่าทรัพยากรที่บล็อกการแสดงผลจะบล็อกอยู่
การทำงานของสคริปต์
ไม่ถูกต้อง |
<script>
var el = document.createElement('script');
el.src = 'https://securepubads.g.doubleclick.net/tag/js/gpt.js';
var node = document.getElementsByTagName('script')[0];
node.parentNode.insertBefore(el, node);
</script>
|
ถูกต้อง |
<script async src="https://securepubads.g.doubleclick.net/tag/js/gpt.js"></script>
|
ระบุแหล่งที่มาของสคริปต์โฆษณาที่แทรก
บางครั้งอาจไม่ชัดเจนว่าสคริปต์โฆษณาถูกแทรกลงในหน้าเว็บอย่างไร
หรือแม้กระทั่งสิ่งที่กำลังถูกแทรกอยู่เลย เช่น เมื่อตรวจสอบแหล่งที่มา
ของหน้าเว็บหลังจากโหลด แท็กสคริปต์ที่แทรกอาจปรากฏขึ้น
แยกแยะจากแท็กที่โหลดแบบคงที่ไม่ได้
ในกรณีเหล่านี้ ให้ใช้แท็บ "เครือข่าย" ใน Chrome DevTools เพื่อระบุซอร์ส
ของสคริปต์โฆษณาที่แทรก
- เปิดเครื่องมือสำหรับนักพัฒนาเว็บโดยกด
Control+Shift+J
หรือ Command+Option+J
(Mac)
- ไปที่แท็บเครือข่าย
- หากไม่เห็น ให้คลิกตัวกรอง
เพื่อเปิดแถบตัวกรองและพิมพ์
ชื่อสคริปต์ที่การตรวจสอบนี้แจ้งว่าไม่เหมาะสมในช่องข้อความ
- หากไม่เห็น ให้คลิกขวาที่ส่วนหัวของตารางใดก็ได้แล้วเลือก
ตัวเริ่มเพื่อรวมคอลัมน์ตัวเริ่มต้นในคำขอเครือข่าย
ตาราง Waterfall
- โหลดหน้านี้ซ้ำเพื่อบันทึกการจราจรของข้อมูลในเครือข่าย

ดังที่เห็นในภาพหน้าจอด้านบน คอลัมน์ตัวเริ่มต้นจะมีข้อมูล
เกี่ยวกับแหล่งที่มาของสคริปต์ที่เป็นปัญหา คุณสามารถคลิกลิงก์แหล่งที่มาเพื่อ
ข้ามไปที่โค้ดที่ทำหน้าที่ออกคำขอสคริปต์โฆษณาโดยตรง หรือ
ให้วางเมาส์เหนือลิงก์แหล่งที่มาเพื่อดูการโทรทั้งหมดที่นำไปสู่คำขอ
การตรวจสอบนี้ดําเนินการกับรายการสคริปต์โฆษณาที่อนุญาตไว้ซึ่งทราบแล้วว่าปลอดภัย
เพื่อโหลดแบบคงที่ โดยรายการในปัจจุบันมีดังนี้
คลัง |
สคริปต์ |
AdSense |
pagead2.googlesyndication.com/pagead/js/adsbygoogle.js
|
บริการสำหรับผู้เผยแพร่โฆษณา Amazon |
amazon-adsystem.com/aax2/apstag.js
|
ผู้เสนอราคาโดยตรงของ Criteo |
static.criteo.net/js/*/publishertag.js
|
แท็กผู้เผยแพร่โฆษณาผ่าน Google |
googletagservices.com/tag/js/gpt.js
securepubads.g.doubleclick.net/tag/js/gpt.js
|
Index Exchange |
js-sec.indexww.com/ht/p/*.js
|
การแทรกแซง document.write()
"สคริปต์อะซิงโครนัส" ที่มีการแทรกสคริปต์ ถือว่าเป็นอันตราย
การเพิ่มข้อมูลโค้ดแบบไม่พร้อมกัน
เนื้อหาของหน้าเว็บนี้ได้รับอนุญาตภายใต้ใบอนุญาตที่ต้องระบุที่มาของครีเอทีฟคอมมอนส์ 4.0 และตัวอย่างโค้ดได้รับอนุญาตภายใต้ใบอนุญาต Apache 2.0 เว้นแต่จะระบุไว้เป็นอย่างอื่น โปรดดูรายละเอียดที่นโยบายเว็บไซต์ Google Developers Java เป็นเครื่องหมายการค้าจดทะเบียนของ Oracle และ/หรือบริษัทในเครือ
อัปเดตล่าสุด 2024-08-22 UTC
[null,null,["อัปเดตล่าสุด 2024-08-22 UTC"],[[["\u003cp\u003eThis audit identifies ad scripts injected into the page that may delay or prevent ad loading.\u003c/p\u003e\n"],["\u003cp\u003eUse async script tags to improve loading speed, enabling the browser to fetch scripts earlier.\u003c/p\u003e\n"],["\u003cp\u003eIf the source of an injected ad script is unclear, Chrome DevTools' Network tab can be used to identify it.\u003c/p\u003e\n"],["\u003cp\u003eA list of safe-to-load ad scripts is provided, including those from AdSense, Amazon, Criteo, Google Publisher Tag, and Index Exchange.\u003c/p\u003e\n"]]],["Ad scripts injected into a page can delay or prevent ad loading. To improve speed, load scripts using `async` script tags, allowing the browser to fetch them earlier. To identify injected scripts, use Chrome DevTools' Network tab: filter by the script name and enable the \"Initiator\" column to find the source. The document provides examples of correct and incorrect code for loading scripts and includes a list of ad scripts from AdSense, Amazon, Criteo, Google Publisher Tag, and Index Exchange.\n"],null,["# Load ad scripts statically\n\nOverview\n--------\n\nThis audits checks whether or not ad scripts are being injected into the page.\nOther resources on the page may delay the fetching and loading of injected\nscripts, which will in turn delay the loading of ads. In some situations these\nscripts may not be fetched at all, preventing ads from being loaded all\ntogether.\n\nRecommendations\n---------------\n\nLoad scripts via async script tags to improve speed. The browser preload scanner\ncan fetch script tags earlier, even if render blocking resources are blocking\nthe script execution.\n\n|---------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| **Incorrect** | ```html \u003cscript\u003e var el = document.createElement('script'); el.src = 'https://securepubads.g.doubleclick.net/tag/js/gpt.js'; var node = document.getElementsByTagName('script')[0]; node.parentNode.insertBefore(el, node); \u003c/script\u003e ``` |\n| **Correct** | ```html \u003cscript async src=\"https://securepubads.g.doubleclick.net/tag/js/gpt.js\"\u003e\u003c/script\u003e ``` |\n\n### Identify the source of injected ad scripts\n\nSometimes it may not be obvious how an ad script is being injected into a page,\nor even that it's being injected at all. For example, when examining the source\nof a page after it's loaded, a script tag that has been injected may appear\nindistinguishable from a tag that was loaded statically.\n\nIn these cases, use the Network tab in Chrome DevTools to determine the source\nof injected ad scripts.\n\n1. Open DevTools by pressing `Control+Shift+J` or `Command+Option+J` (Mac).\n2. Navigate to the **Network** tab.\n3. If not already visible, click **Filter** to open the filter bar and type the name of the script flagged by this audit into the text box.\n4. If not already visible, right-click on any table header and select **Initiator** to include the Initiator column in the network request waterfall table.\n5. Reload the page to capture network traffic.\n\nAs seen in the above screenshot, the initiator column will contain information\nabout the source of the script in question. You can click on the source link to\njump directly to the code responsible for issuing the ad script request, or\nhover over the source link to see all of the calls leading up to the request.\n\nMore information\n----------------\n\nThis audit operates against a allowlist of ad scripts which are known to be safe\nto load statically. The current list is:\n\n| Library | Script(s) |\n|---------------------------|--------------------------------------------------------------------------------------|\n| AdSense | `pagead2.googlesyndication.com/pagead/js/adsbygoogle.js` |\n| Amazon Publisher Services | `amazon-adsystem.com/aax2/apstag.js` |\n| Criteo Direct Bidder | `static.criteo.net/js/*/publishertag.js` |\n| Google Publisher Tag | `googletagservices.com/tag/js/gpt.js` `securepubads.g.doubleclick.net/tag/js/gpt.js` |\n| Index Exchange | `js-sec.indexww.com/ht/p/*.js` |\n\n[Intervening against document.write()](https://developers.google.com/web/updates/2016/08/removing-document-write) \n\n[Script-injected \"async scripts\" considered harmful](https://www.igvita.com/2014/05/20/script-injected-async-scripts-considered-harmful/) \n\n[Speeding Up Async Snippets](https://csswizardry.com/2022/10/speeding-up-async-snippets/) \n[View audit source](https://github.com/googleads/publisher-ads-lighthouse-plugin/tree/HEAD/lighthouse-plugin-publisher-ads/audits/script-injected-tags.js) [Improve this article](https://github.com/googleads/publisher-ads-lighthouse-plugin/tree/HEAD/docs/audits/script-injected-tags.md) [Report an issue](https://github.com/googleads/publisher-ads-lighthouse-plugin/issues/new?labels=documentation&template=documentation-feedback.md&title=Documentation+feedback%3A+script-injected-tags.md)\n\n\u003cbr /\u003e"]]