Cloud Retail 代码
使用集合让一切井井有条
根据您的偏好保存内容并对其进行分类。
本文面向希望将其 Cloud Retail 代码从客户端迁移到服务器容器的开发者。请参阅有关 Cloud Retail 网络容器代码的 Google Cloud 文档。
准备工作
本指南假定您已经:
设置 Cloud Retail 代码
打开 Google 跟踪代码管理器
在服务器容器中,打开代码菜单,并创建一个新代码。
在代码配置中,选择 Cloud Retail 代码。
设置 Cloud Retail 代码:
- 在 API 密钥下,输入支持
projects.locations.catalogs.userEvents.collect
方法的有效 Cloud Retail API 密钥。
- 在项目编号下,为您的 Cloud Retail 项目输入 Google Cloud 项目编号。
- 在要覆盖的字段下,设置访问者 ID:
- 字段选择器:
visitorId
- 字段值:输入一个从 GA4 事件解析为唯一身份访问者 ID 的变量,例如客户端 ID。
- 可选:若要衡量搜索事件,请执行以下操作:
- 字段选择器:
searchQuery
- 字段值:输入一个用于提取搜索查询数据的变量。搜索事件是通过将搜索事件查询与该查询的展示次数(在
view_item_list
中发送)相结合构建而成。
在触发条件中,选择何时应触发代码。请参阅有关 Google Analytics(分析)4 触发事件与 Cloud Retail 事件之间的映射的 Google Cloud 文档。
为您的代码命名并保存。
如未另行说明,那么本页面中的内容已根据知识共享署名 4.0 许可获得了许可,并且代码示例已根据 Apache 2.0 许可获得了许可。有关详情,请参阅 Google 开发者网站政策。Java 是 Oracle 和/或其关联公司的注册商标。
最后更新时间 (UTC):2024-11-15。
[null,null,["最后更新时间 (UTC):2024-11-15。"],[[["\u003cp\u003eThis guide helps developers move the Cloud Retail tag from client-side to a server-side container in Google Tag Manager.\u003c/p\u003e\n"],["\u003cp\u003eBefore starting, ensure you have set up a server container, a tagging server, and the data flow between web and server containers in Tag Manager.\u003c/p\u003e\n"],["\u003cp\u003eThe setup involves creating a new Cloud Retail tag in your server container, configuring it with your API key and project details, and mapping it to relevant triggers based on Google Analytics 4 events.\u003c/p\u003e\n"],["\u003cp\u003eIt's crucial to provide a unique visitor ID and optionally include search queries for enhanced tracking in your Cloud Retail tag configuration.\u003c/p\u003e\n"]]],["Developers moving Cloud Retail tags to a server container should first ensure they have a server container, tagging server, and data flow from web to server containers established. In the server container, create a new Cloud Retail tag, configuring it with a valid API key, project number, and a visitor ID variable (e.g., client ID). Optionally, configure search event measurement using a search query variable. Finally, select appropriate triggers based on GA4 event mappings and save the tag.\n"],null,["# Cloud Retail tag\n\n\u003e This article is for developers who want to move their Cloud Retail tag off\n\u003e of the client and into a server container. Refer to the Google Cloud\n\u003e documentation for the [Cloud Retail web container tag](https://cloud.google.com/retail/docs/record-events#gtm-tag).\n\nBefore you begin\n----------------\n\nThis guide assumes that you have done the following:\n\n- [Set up a server container in Tag Manager](/tag-platform/tag-manager/server-side/overview#create_a_tag_manager_server_container)\n- [Set up a tagging server](/tag-platform/tag-manager/server-side/overview#set_up_a_tagging_server)\n- [Set up the data flow from the web container to the server container](/tag-platform/tag-manager/server-side/send-data)\n\nSet up the Cloud Retail tag\n---------------------------\n\n1. [Open Google Tag Manager](https://tagmanager.google.com/)\n\n2. In your server container, open the **Tags** menu and create a **New** tag.\n\n3. In **Tag Configuration** , select the **Cloud Retail** tag.\n\n4. Set up the Cloud Retail tag:\n\n - Under **API Key** , enter a valid Cloud Retail API key that supports the [`projects.locations.catalogs.userEvents.collect` method](https://cloud.google.com/retail/docs/reference/rest/v2/projects.locations.catalogs.userEvents/collect).\n - Under **Project Number**, enter the Google Cloud Project number for your Cloud Retail project.\n - Under **Fields to Overwrite** , set up a visitor ID:\n - **Field Selector** : `visitorId`\n - **Field Value**: Enter a variable that resolves into a unique visitor ID from a GA4 event, for example, the client ID.\n - Optional: To measure search events:\n - **Field Selector** : `searchQuery`\n - **Field Value** : Enter a variable that extracts the search query. The search event is constructed by combining the search event query with the impressions for the query, which are sent in `view_item_list`.\n5. In **Triggering** , select when the tag should trigger. Refer to the Google\n Cloud documentation for [mappings between Google Analytics 4 trigger events\n and Cloud Retail events](https://cloud.google.com/retail/docs/record-events#ee-triggers).\n\n6. Name and **Save** your tag."]]