[null,null,["最后更新时间 (UTC):2023-10-27。"],[[["\u003cp\u003eThis article outlines methods for sending data to a server-side container in Google Tag Manager from websites and other sources like mobile apps and server-to-server applications.\u003c/p\u003e\n"],["\u003cp\u003eIt explains how to configure clients within your server-side container to receive and process incoming data, including optional settings for customization.\u003c/p\u003e\n"],["\u003cp\u003eThe guide covers sending additional parameters alongside events and utilizing the Measurement Protocol for non-website data sources.\u003c/p\u003e\n"],["\u003cp\u003eIt assumes prior setup of a server container and tagging server in Tag Manager.\u003c/p\u003e\n"],["\u003cp\u003eTo enhance first-party data collection, the article encourages serving Google scripts directly from your servers, linking to further instructions.\u003c/p\u003e\n"]]],["Data can be sent to a server-side container from websites via Tag Manager or gtag.js, including optional configuration and event-level parameters. The server container receives data through clients, which must claim the HTTP requests. Additional data requires setting up the GA4 client and creating event data variables. Data can also be sent from mobile apps or server-to-server applications using the Measurement Protocol with a corresponding Measurement Protocol client setup in the server container.\n"],null,["# Send data to server-side Tag Manager\n\nThis article describes the different ways to send events to a server-side\ncontainer. If you need more background information, take a look at\n[how server-side tagging works](/tag-platform/learn/sst-fundamentals/2-what-is-sst#how-server-side-tagging-works).\n\nThis article discusses how to:\n\n- Send data from a website to your server-side container\n- Send additional data to a server container\n- Receive data in your server-side container\n- Send data from sources other than websites\n\nBefore you begin\n----------------\n\nThis guide assumes that you already have:\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\n1. Send data from a website to your server-side container\n---------------------------------------------------------\n\nYou can route data through a server-side implementation via Tag Manager or\ngtag.js. Pick your implementation option. \nTag Manager gtag.js\nChoose your implementation option.\n\n### Optional: Send additional parameters with each event\n\nYou can send additional two types of additional parameters: Configuration-level\nparameters and event-level parameters. Configuration parameters influence how\nyour Google tag behaves and can only be set on the Google tag level.\n\nEvent parameters specify additional information about an event and can be set\nfor all events, select events, or `page_view` events.\nChoose your implementation option.\n\n### Setup recommendations\n\nWe recommend using GA4 tag on a web page to send data to the server container.\nThis tag can use different transport methods to ensure the best delivery rate of\nthe events. Such methods include but not limited to\n\n- Image pixel\n- Fetch API\n- XHR\n- Service worker that runs in an iframe loaded from your server container domain.\n\nTo ensure that all methods are supported check the following:\n\n***Content-security policy (CSP)***\n\n|---------------|--------------------------|-------------------------------|\n| **Directive** | **Content** | **Purpose** |\n| img-src | \\[SERVER_CONTAINER_URL\\] | Measurement requests |\n| connect-src | \\[SERVER_CONTAINER_URL\\] | Measurement requests |\n| frame-src | \\[SERVER_CONTAINER_URL\\] | Service worker implementation |\n\nIn addition, **X-Frame-Options** must not restrict iframes from being loaded\nfrom the server container URL.\n\nConsult with\n\u003chttps://developers.google.com/tag-platform/security/guides/csp\u003e\nfor specific policies per product.\n\n2. Receive data in your server-side container\n---------------------------------------------\n\nWhen you send HTTP request to a server container, a client has to claim that\nrequest.\n| **Key Term:** \"Clients\" are adapters between the software running on a user's device and your server-side Tag Manager container. They receive measurement data from a device, transform that data into one or more events, process the data in the container, and package the results to be sent back to the device.\n\nTo view the list of available clients:\n\n1. [Open\n Google Tag Manager](https://tagmanager.google.com/#/home)\n\n2. Open your server container.\n\n3. In the navigation bar on the left, click **Clients**. The GA4 client is\n pre-installed on your server-side container by default.\n\n4. Click the name of the client to view or edit details.\n\n### Optional client settings\n\nIn most cases, the client will require no modifications. However, your use case\nmight be different and you might want to edit one of the following settings:\n\n- **Priority:** Determines the order in which clients will run. Higher numbers\n run first, and the first client that matches the incoming request will\n become the active client for that request.\n\n- **Activation Criteria:** Activation criteria define when the client will\n respond to requests:\n\n - **Default gtag.js paths for specific IDs:** Use this setting to enable gtag.js JavaScript serving through your server container URL. When enabled, this client will activate in response to requests to the default gtag.js request paths, e.g. `/gtag/js?id=TAG_ID`. Click **Add\n Measurement ID** to add one or more [destination IDs](https://support.google.com/tagmanager/answer/12324787).\n\n### Optional: Receive additional data in server-side Tag Manager\n\nIf you are sending [additional parameters](#additional-parameters), you need to\nset up the **Google Analytics 4** client in your server container to parse the\nadditional parameters and create event data out of them.\n\nSome server tags will include the additional parameters in their outbound\nrequests with no setup. To exclude those parameters, create a [Transformation](/tag-platform/tag-manager/server-side/transformations)\nto remove the value.\n\nTo use additional parameters in other tags:\n\n1. In your server container, click on **Variables** in the left navigation.\n2. Create a **New User-defined Variable**.\n3. In **Variable Configuration** , select the variable type **Event Data**.\n4. In **Key Path**, enter the name of the parameter.\n5. Give your variable a name and **Save**.\n\nNow you can use the event parameter in any other tag within your server\ncontainer.\n\n3. Optional: Send data from sources other than websites\n-------------------------------------------------------\n\nThe Google Analytics [Measurement Protocol](/analytics/devguides/collection/protocol/ga4) can be used to enable server-side\ntagging support from sources such as mobile apps and server-to-server\napplications. This option lets you send events to your container in the\nMeasurement Protocol format. The container sends those events to Google\nAnalytics using the same mechanism as all other SGTM events.\n| **Note:** This option doesn't send events to the Measurement Protocol endpoint.\n\nThis option doesn't support all the features of the Measurement Protocol\nendpoint, like deriving [geographic and device information](/analytics/devguides/collection/protocol/ga4#geo_device) from\ntagging events.\n\n### Mobile apps\n\nTo get your Android or iOS app to send data to your server container, you will\ncreate a custom image tag and configure it to use the Measurement Protocol:\n\n1. In your mobile container (Android or iOS), click **Tags \\\u003e New**.\n2. In **Tag Configuration** select the **Custom Image** tag type.\n3. Set the value of **Image URL** to a pixel image on the server container at the path in the Measurement Protocol client that you specified earlier. Append any desired Measurement Protocol parameters to the end of your pixel URL: \n `https://custom.example.com/app`**?v=1&tid=TAG_ID&cid=555&t=screenview&an=myApp&version=1.6.2&aid=com.foo.myapp&cd=home**\n4. Deselect **Enable Cache Busting**.\n5. Save the tag and publish the container.\n6. In your server-side container, click **Clients \\\u003e New**.\n7. In **Client Configuration** , select the **Measurement Protocol** client type.\n8. Set **Activation Path** to the path of your app's collection endpoint.\n9. Save the client configuration and publish the server-side container.\n\n### Server-to-server apps\n\nTo send measurement protocol data to your server container, replace the\n`www.google-analytics.com` hostname with the domain name of your server\ncontainer. For example: \n\n POST /batch HTTP/1.1\n Host: collection.example.com\n\n v=1&tid=TAG_ID&cid=555&t=screenview&an=myApp&version=1.6.2&aid=com.foo.myapp&cd=home\n\nTo receive Measurement Protocol hits, configure your server-side Tag Manager\ninstallation with a Measurement Protocol client:\n\n1. In your server-side container, click **Clients \\\u003e New**.\n2. In **Client Configuration** , select the **Measurement Protocol** client type.\n3. Set **Activation Path** to the path of your server's endpoint.\n4. Save the client configuration and publish the container.\n\nNext steps\n----------\n\nTo send data in a true first-party context, you need to serve Google scripts,\nsuch as the Google Analytics library, from your own servers.\n\n[Load\nGoogle scripts through my\nserverarrow_forward](/tag-platform/tag-manager/server-side/dependency-serving)"]]