Thiết lập thẻ Google bằng gtag.js
Sử dụng bộ sưu tập để sắp xếp ngăn nắp các trang
Lưu và phân loại nội dung dựa trên lựa chọn ưu tiên của bạn.
Thẻ Google là một thẻ mà bạn có thể thêm vào trang web của mình để sử dụng
Các sản phẩm đo lường và quảng cáo của Google như Google Ads, Google
Analytics, Campaign Manager, Hiển thị và Video 360 và Search Ads 360. Thay vì
quản lý nhiều thẻ cho các sản phẩm khác nhau của Google, bạn có thể sử dụng
Thẻ Google trên toàn bộ trang web của bạn và kết nối thẻ này với nhiều đích đến.
Tìm hiểu thêm về thẻ Google
Trang này giải thích cách thiết lập và triển khai thẻ Google trên trang web của bạn bằng cách sử dụng
khung gtag.js. Nếu không quen với javascript, chúng tôi khuyên bạn nên sử dụng
Trình quản lý thẻ của Google thay vì gtag.js.
Lợi ích
Cách tốt nhất để đo lường lượt chuyển đổi và tối ưu hoá giá trị của
Phương pháp đầu tư vào hoạt động tiếp thị của Google là đặt thẻ trên mọi trang trong trang web của bạn. Theo
triển khai thẻ Google trên trang web của mình, bạn sẽ có quyền truy cập vào
lợi ích:
- Đo lường lượt chuyển đổi phù hợp trong tương lai. Hưởng lợi từ các tính năng mới nhất
và tích hợp ngay khi có để bạn có trang bị tốt hơn
để tiếp tục đo lường chính xác lượt chuyển đổi nếu có thay đổi.
- Quản lý thẻ mà không dùng mã. Bật các tính năng đo lường trong Google
mà không cần phải thay đổi thẻ trên trang theo cách thủ công.
- Tích hợp nhanh hơn và dễ dàng hơn. Tinh tế, đơn giản hơn
triển khai và tích hợp với các sản phẩm khác của Google, chẳng hạn như
Analytics và Google Ads.
- Đo lường lượt chuyển đổi chính xác hơn. Thẻ Google giúp bạn đạt được
đo lường lượt chuyển đổi chính xác hơn khi không có cookie và
khôi phục các lượt chuyển đổi không ghi nhận được hôm nay do các yếu tố trong ngành.
Thêm thẻ Google vào trang web của bạn
Cách thu thập dữ liệu bằng thẻ Google:
Mở một sản phẩm của Google mà bạn sử dụng rồi truy cập vào màn hình thẻ Google.
Cách tìm mã thẻ trong:
Sao chép mã thẻ Google.
Dán mã thẻ Google vào đoạn mã mẫu sau. Đặt thẻ Google
đoạn mã ngay sau thẻ HTML <head>
mở trên mỗi trang bạn muốn
để đo lường.
<!-- 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>
Cần có lệnh config
để gửi dữ liệu đến các sản phẩm quảng cáo của Google.
Nhiều tính năng yêu cầu bạn phải đặt lệnh config
trên trang web, chẳng hạn như
sự kiện được thu thập tự động và liên kết lượt chuyển đổi.
Tìm hiểu thêm về lệnh config
Xác minh thẻ Google
Cách xác minh rằng thẻ của bạn đang gửi dữ liệu:
- Truy cập vào tagassistant.google.com/.
- Nhấp vào Thêm miền.
- Nhập URL của trang web mà bạn muốn gỡ lỗi, bắt đầu bằng "https://" hoặc "http://".
- Nhấp vào Kết nối.
Khi bạn kết nối Tag Assistant với trang web của mình, hãy kiểm tra xem mã thẻ Google của bạn có phải là
xuất hiện trong tiêu đề Thẻ Google được tìm thấy. Nếu Tag Assistant không nhận dạng được thẻ của bạn, hãy tìm mẹo gỡ lỗi trong Trung tâm trợ giúp của Trình quản lý thẻ
Bạn cũng có thể truy cập vào bản tóm tắt mức độ phù hợp của thẻ để biết thông tin tổng quan về
trạng thái gắn thẻ.
Các bước tiếp theo
Bây giờ, bạn đã thiết lập thẻ Google, hãy thiết lập các sản phẩm của Google và gửi dữ liệu sự kiện.
Trừ phi có lưu ý khác, nội dung của trang này được cấp phép theo Giấy phép ghi nhận tác giả 4.0 của Creative Commons và các mẫu mã lập trình được cấp phép theo Giấy phép Apache 2.0. Để biết thông tin chi tiết, vui lòng tham khảo Chính sách trang web của Google Developers. Java là nhãn hiệu đã đăng ký của Oracle và/hoặc các đơn vị liên kết với Oracle.
Cập nhật lần gần đây nhất: 2025-07-25 UTC.
[null,null,["Cập nhật lần gần đây nhất: 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)."]]