ตั้งค่าแท็ก Google ด้วย gtag.js
จัดทุกอย่างให้เป็นระเบียบอยู่เสมอด้วยคอลเล็กชัน
บันทึกและจัดหมวดหมู่เนื้อหาตามค่ากำหนดของคุณ
แท็ก Google คือแท็กที่คุณสามารถเพิ่มลงในเว็บไซต์เพื่อใช้
การวัดผลและผลิตภัณฑ์การโฆษณาของ Google เช่น Google Ads, Google
Analytics, Campaign Manager, Display และ Video 360 และ Search Ads 360 แทนที่จะเป็น
จัดการแท็กหลายแท็กสำหรับผลิตภัณฑ์ต่างๆ ของ Google คุณสามารถใช้
แท็ก Google ทั่วทั้งเว็บไซต์และเชื่อมต่อแท็กกับปลายทางหลายแห่ง
ดูข้อมูลเพิ่มเติมเกี่ยวกับแท็ก Google
หน้านี้จะอธิบายวิธีตั้งค่าและทำให้แท็ก Google ใช้งานได้ในเว็บไซต์โดยใช้
เฟรมเวิร์ก gtag.js หากคุณไม่คุ้นเคยกับ JavaScript เราขอแนะนำให้ใช้
Google Tag Manager แทน gtag.js
ประโยชน์
วิธีที่ดีที่สุดในการวัด Conversion และเพิ่มประสิทธิภาพมูลค่า
การลงทุนด้านการตลาดของ Google คือการวางแท็กในหน้าทุกหน้าของเว็บไซต์ โดย
ติดตั้งแท็ก Google ในเว็บไซต์ คุณจึงมีสิทธิ์เข้าถึงสิ่งต่อไปนี้
ประโยชน์:
- การวัด Conversion ที่ประสบความสำเร็จในระยะยาว ใช้ประโยชน์จากฟีเจอร์ล่าสุด
และการผสานรวมทันทีที่พร้อมให้บริการ คุณจึงพร้อม
เพื่อให้สามารถวัด Conversion ได้อย่างถูกต้องต่อไปหากมีการเปลี่ยนแปลง
- การจัดการแท็กแบบไม่ใช้โค้ด เปิดใช้ฟีเจอร์การวัดผลภายใน Google
ผลิตภัณฑ์โดยไม่ต้องเปลี่ยนแท็กในหน้าเว็บด้วยตนเอง
- การผสานรวมที่ง่ายและรวดเร็วยิ่งขึ้น คล่องตัวและง่ายขึ้น
การนำไปใช้และการผสานรวมกับผลิตภัณฑ์อื่นๆ ของ Google เช่น
Analytics และ Google Ads
- วัด Conversion ได้แม่นยํายิ่งขึ้น แท็ก Google ช่วยให้คุณบรรลุเป้าหมายต่อไปนี้
การวัด Conversion ที่แม่นยำขึ้นเมื่อคุกกี้ไม่พร้อมใช้งาน และ
กู้คืน Conversion ที่สังเกตไม่พบในวันนี้เนื่องจากปัจจัยในอุตสาหกรรม
เพิ่มแท็ก Google ลงในเว็บไซต์
วิธีรวบรวมข้อมูลด้วยแท็ก Google
เปิดผลิตภัณฑ์ของ Google ที่คุณใช้และเข้าถึงหน้าจอแท็ก Google
วิธีค้นหารหัสแท็กใน
คัดลอกรหัสแท็ก Google
วางรหัสแท็ก Google ในตัวอย่างโค้ดต่อไปนี้ วางแท็ก Google
แสดงตัวอย่างทันทีหลังจากแท็ก HTML เปิด <head>
ในทุกหน้าที่คุณต้องการ
ในการวัดค่า
<!-- Google tag (gtag.js) -->
<script async src="https://www.googletagmanager.com/gtag/js?id=TAG_ID"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'TAG_ID');
</script>
ต้องใช้คำสั่ง config
เพื่อส่งข้อมูลไปยังผลิตภัณฑ์โฆษณาของ Google
ฟีเจอร์บางอย่างต้องการการตั้งค่าคำสั่ง config
ในเว็บไซต์ เช่น
เหตุการณ์ที่รวบรวมโดยอัตโนมัติและการลิงก์ Conversion
ดูข้อมูลเพิ่มเติมเกี่ยวกับคำสั่ง config
ยืนยันแท็ก Google
วิธียืนยันว่าแท็กกำลังส่งข้อมูล
- ไปที่ tagassistant.google.com/
- คลิกเพิ่มโดเมน
- ป้อน URL ของเว็บไซต์ที่ต้องการแก้ไขข้อบกพร่อง โดยขึ้นต้นด้วย "https://" หรือ "http://"
- คลิกเชื่อมต่อ
เมื่อเชื่อมต่อผู้ช่วยแท็กกับเว็บไซต์ ให้ตรวจสอบว่ารหัสแท็ก Google
ปรากฏในส่วนหัวที่พบแท็ก Google หากผู้ช่วยแท็กไม่รู้จัก
ให้ดูเคล็ดลับการแก้ไขข้อบกพร่องใน
ศูนย์ช่วยเหลือของ Tag Manager
คุณยังเข้าถึงสรุปความครอบคลุมของแท็กเพื่อดูภาพรวมของแท็ก
สถานะการติดแท็ก
ขั้นตอนถัดไป
เมื่อตั้งค่าแท็ก Google แล้ว ให้กําหนดค่าผลิตภัณฑ์ของ Google และส่งข้อมูลเหตุการณ์
เนื้อหาของหน้าเว็บนี้ได้รับอนุญาตภายใต้ใบอนุญาตที่ต้องระบุที่มาของครีเอทีฟคอมมอนส์ 4.0 และตัวอย่างโค้ดได้รับอนุญาตภายใต้ใบอนุญาต Apache 2.0 เว้นแต่จะระบุไว้เป็นอย่างอื่น โปรดดูรายละเอียดที่นโยบายเว็บไซต์ Google Developers Java เป็นเครื่องหมายการค้าจดทะเบียนของ Oracle และ/หรือบริษัทในเครือ
อัปเดตล่าสุด 2025-07-25 UTC
[null,null,["อัปเดตล่าสุด 2025-07-25 UTC"],[[["\u003cp\u003eThe Google tag is a versatile tag that streamlines the use of various Google products like Google Ads and Analytics, replacing the need for multiple individual tags.\u003c/p\u003e\n"],["\u003cp\u003eImplementing the Google tag offers benefits like future-proof conversion measurement, codeless tag management, easier integration with other Google products, and more accurate conversion tracking.\u003c/p\u003e\n"],["\u003cp\u003eTo use the Google tag, copy your tag ID from a Google product (e.g., Google Ads, Analytics), paste it into the provided code snippet, and place the snippet on every page you want to track.\u003c/p\u003e\n"],["\u003cp\u003eVerify your Google tag implementation using Tag Assistant to ensure it's sending data correctly by checking for your tag ID and consulting the Tag Manager help center for troubleshooting.\u003c/p\u003e\n"]]],["The Google tag, a single tag for Google measurement and advertising products, can be implemented across an entire website via the gtag.js framework. To set up, users need to locate their Google tag ID within Google Ads, Analytics, or Floodlight, copy it, and paste it into the provided code snippet within the `\u003chead\u003e` of each web page. Verification involves using Tag Assistant to confirm tag detection and to ensure data is being sent. Once confirmed, the tag must be configured with the config command.\n"],null,["# Set up the Google tag with gtag.js\n\nThe Google tag is a single tag you can add to your website to use\nGoogle measurement and advertising products like Google Ads, Google\nAnalytics, Campaign Manager, Display \\& Video 360, and Search Ads 360. Instead of\nmanaging multiple tags for different Google products, you can use the\nGoogle tag across your entire site and connect the tag to multiple destinations.\n\n[Learn more about the Google tag](https://support.google.com/tagmanager/answer/11994839)\n\nThis page explains how to set up and deploy a Google tag on your site using\nthe gtag.js framework. If you're unfamiliar with javascript, we recommend using\n[Google Tag Manager](/tag-platform/tag-manager) instead of gtag.js.\n\nBenefits\n--------\n\nThe best way to measure conversions and optimize the value of your\nGoogle marketing investment is to place tags on every page of your site. By\nimplementing the Google tag across your site, you gain access to the following\nbenefits:\n\n- **Future-proof conversion measurement.** Benefit from the latest features and integrations as they become available so that you are better equipped to continue measuring conversions accurately if changes occur.\n- **Codeless tag management.** Turn on measurement features within Google products without having to manually change the tags on your page.\n- **Faster and easier integration.** Streamlined, simpler implementation and integration with other Google products, such as Analytics and Google Ads.\n- **More accurate conversion measurement.** The Google tag helps you achieve more accurate conversion measurement when cookies are not available and recover conversions not observed today due to industry factors.\n\nAdd the Google tag to your website\n----------------------------------\n\nTo collect data with the Google tag:\n\n1. Open a Google product you use and access the Google tag screen.\n How to find your tag ID in:\n\n - [Google Ads](https://ads.google.com/aw/tagsettings)\n - [Google Analytics](https://support.google.com/analytics/answer/9539598)\n - [Google Floodlight](https://support.google.com/searchads/answer/2466080)\n\n \u003cbr /\u003e\n\n2. Copy your Google tag ID.\n\n3. Paste your Google tag ID in the following code sample. Place the Google tag\n snippet immediately after the opening `\u003chead\u003e` HTML tag on every page you want\n to measure.\n\n \\\u003c!-- Google tag (gtag.js) --\\\u003e\n \\\u003cscript async src=\"https://www.googletagmanager.com/gtag/js?id=\u003cvar translate=\"no\"\u003eTAG_ID\u003c/var\u003e\"\\\u003e\\\u003c/script\\\u003e\n \\\u003cscript\\\u003e\n window.dataLayer = window.dataLayer \\|\\| \\[\\];\n function gtag(){dataLayer.push(arguments);}\n gtag('js', new Date());\n gtag('config', '\u003cvar translate=\"no\"\u003eTAG_ID\u003c/var\u003e');\n \\\u003c/script\\\u003e\n\n The `config` command is needed to send data to Google advertisement products.\n Many features require the `config` command to be set on your website, such as\n automatically collected events and conversion linking.\n [Learn more about the config command](https://developers.google.com/tag-platform/gtagjs/reference#config)\n\nVerify the Google tag\n---------------------\n\nTo verify that your tag is sending data:\n\n1. Go to [tagassistant.google.com/](https://tagassistant.google.com/).\n2. Click **Add domain**.\n3. Enter the URL of the website you want to debug, starting with \"https://\" or \"http://\".\n4. Click **Connect**.\n\nWhen you connect Tag Assistant to your website, check if your Google tag ID\nappears in the header **Google tags found** . If Tag Assistant doesn't recognize\nyour tag, find debug tips in the\n[Tag Manager help center](https://support.google.com/tagassistant/answer/10039345)\n\nYou can also access the [tag coverage summary](https://support.google.com/tagmanager/answer/12270036) for an overview of your site's\ntagging status.\n\nNext steps\n----------\n\nNow that you've set up your Google tag, [configure Google products and send event data](/tag-platform/gtagjs/configure)."]]