[null,null,["最后更新时间 (UTC):2024-04-22。"],[[["\u003cp\u003eThis page outlines methods for tracking website activity and sending data to Google Analytics, primarily using Google Tag, Tag Manager, and gtag.js.\u003c/p\u003e\n"],["\u003cp\u003eGoogle recommends using Tag Manager for streamlined tag management and deployment without manual code editing.\u003c/p\u003e\n"],["\u003cp\u003eWhile gtag.js offers direct website tagging, it's limited to Google products and requires coding proficiency; Tag Manager supports broader tag types and simplifies tag updates.\u003c/p\u003e\n"],["\u003cp\u003eFor data transmission to Google Analytics using the Google tag, agreeing to Google Analytics Terms of Service is necessary.\u003c/p\u003e\n"],["\u003cp\u003eTag Manager provides a centralized platform for managing web and app tags, offering version control and collaboration features.\u003c/p\u003e\n"]]],["The document details options for measuring website activity and sending data to Google Analytics. The **Google tag** is a single tag for measuring organic and ad performance, configurable for various Google products. **Google Tag Manager** is recommended for managing tags without code editing, supporting Google, third-party, and custom tags. **gtag.js** is a JavaScript framework for adding Google tags, requiring coding skills, and is limited to Google services. The gtag.js sets cookies, such as `_ga`, to distinguish users and sessions. Tag Manager is more flexible and feature rich than gtag.js.\n"],null,["# Tagging for Google Analytics\n\nThis page provides an overview of the tagging options you can use to measure\nactivity on your site and send the data to Google Analytics. The Google tag is\ndesigned for measurement across many Google products, including Google Ads. We\nrecommend [using Tag Manager to get\nstarted](//support.google.com/tagmanager/answer/14842164).\n\nFor details on the Google tag, Tag Manager and gtag.js products, see the [Tag\nplatform documentation](/tag-platform/devguides).\n\nThe Google tag\n--------------\n\nThe Google tag is a single tag you can add to your website to measure organic\nand ad performance. You can configure a Google tag for Google Analytics, and\nsend the data from that tag to other products, like Google Ads, by adding\n[destinations](//support.google.com/tagmanager/answer/12324388) to your tag.\n\nTo send data from a Google tag to your Google Analytics account, you need to\naccept the Google Analytics Terms of Service (ToS).\n\nTo get started with the Google tag for Google Analytics, we recommend using\n[Google Tag Manager](//support.google.com/tagmanager/answer/9442095).\n| **Note:** The **Google Analytics: GA4 Configuration tag** is now the Google tag. If you were using Google Analytics configuration tags, they have been automatically upgraded to the Google tag. Your measurement and capabilities haven't changed, and you don't need to take any action. Your Google Analytics event tags stay the same.\n\nGoogle Tag Manager\n------------------\n\n[Google Tag Manager](//support.google.com/tagmanager/answer/6102821) is a\nweb-based tag management system, that lets you create Google tags and install\nthem on your website, without manually adding JavaScript snippets to your site.\nYou can also update the settings for tags that are already in use on your site\nin Tag Manager, without needing to re-deploy your site each time.\n\nGoogle Tag Manager supports the Google tag you need for Google Analytics, a wide\narray of third-party tags, and even custom tags.\n\n[Set up and install Tag Manager](//support.google.com/tagmanager/answer/14842164)\n\ngtag.js\n-------\n\nIf you already use Google Tag Manager, you don't need to use gtag.js.\n\ngtag.js is a JavaScript framework you can use to add Google tags to web pages.\nTo use gtag.js effectively, you need to be proficient in HTML, CSS, and\nJavaScript.\n| **Note:** gtag.js doesn't support third-party or custom tags, and can only send data to Google services.\n\nYou can [migrate](/tag-platform/tag-manager/web/migrate) your tags to Google Tag\nManager from gtag.js if needed.\n\n### gtag.js cookie usage\n\nFor the latest information on cookie usage in Google Analytics, see [Cookie\nusage on websites](//support.google.com/analytics/answer/11397207).\n\nThe gtag.js JavaScript library uses\n*first-party* cookies to do the following:\n\n- Distinguish unique users.\n- Distinguish sessions for a user.\n\nWhen using the recommended JavaScript snippet, cookies are set at the highest\npossible domain level. For example, if your website address is\n`blog.example.co.uk`, gtag.js sets the cookie domain to `.example.co.uk`.\nSetting cookies on the highest level domain possible lets measurement occur\nacross subdomains without extra configuration.\n| **Note:** gtag.js doesn't require setting cookies to transmit data to Google Analytics.\n\ngtag.js sets the following cookies:\n\n| Cookie name | Default expiration time | Description |\n|----------------------|-------------------------|--------------------------------|\n| `_ga` | 2 years | Used to distinguish users. |\n| `_ga_\u003ccontainer-id\u003e` | 2 years | Used to persist session state. |\n\n### Customization\n\nTo learn how you can customize the default cookie settings using gtag.js, see\n[Cookies and user identification\nguide](/tag-platform/security/concepts/cookies).\n\nGoogle Tag Manager versus gtag.js\n---------------------------------\n\nHere's an overview of the differences between gtag.js and Tag Manager for Google\nAnalytics. \n\nThe following table highlights the differences between gtag.js and Tag Manager\nfor Google Analytics.\n\n| `gtag.js` (code deployment) | Google Tag Manager (Tag Management System) |\n|-------------------------------------------------------------------------------------------------------------------------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| You need to write code to deploy tags and customize your web collection | Deploy and modify both tags from Google and third-parties on the fly **without editing code** . [See all supported tags](//support.google.com/tagmanager/answer/6106924) |\n| Can only send data for Google products. | Can send data for Google tags, third party tags, and custom tags. |\n| You need to manage your tags from within your code, and may need to duplicate code for different outlets, for example, web and app. | Manage tags for your website and apps all from [tagmanager.google.com](https://tagmanager.google.com) |\n| Version control depends on how you manage your code. | Collaborate with others using workspaces, and version control tags. |\n| Server-side tagging is possible. You still need to use Google Tag Manager to deploy and interact with your server container. | Tag Manager helps you deploy tags on a server. If you are exploring this option, read [Client-side and server-side tagging](//support.google.com/tagmanager/answer/13387731). |\n| Compatible with static-site generators, CMSs, website builders or manually authored HTML pages that support JavaScript. | Compatible with many CMSs and website builders. If your system doesn't support Tag Manager, use the Google tag (`gtag.js`) instead. |\n| Cost: Free | Cost: Free |"]]