Stay organized with collections
Save and categorize content based on your preferences.
This article is for developers who want to host server-side tagging in the
same first-party context as their website. Same-origin serving is a best
practice that lets you leverage the security and durability benefits of
server-set cookies. The below instructions apply for setting up same-origin
serving regardless of the Google tag deployed on your site (gtag.js or
gtm.js).
When you first set up a tagging server, it is hosted on a domain provided by the
cloud provider. When you use the default endpoint, it delivers data to the
server container, but runs in a third-party context. To unlock the benefits of a
first-party context, such as more durable cookies, your tagging server and your
website have to run on the same domain.
The table below illustrates how you can host a tagging server when the parent
website is hosted on www.example.com:
Same origin (best practice)
Subdomain
Default domain
Example URL
https://www.example.com/metrics
https://metrics.example.com
https://metrics.run.app
Server-set cookie access
Full access to security and durability benefits.
Full access to security and durability benefits.
None. Can only set Javascript cookies.
Setup complexity
Configure a CDN or load balancer to forward requests. May need to update DNS entries.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2024-10-09 UTC."],[[["This article guides developers on hosting server-side tagging in a first-party context for enhanced security and cookie durability."],["Achieving same-origin serving involves configuring your tagging server and website to run on the same domain, which can be done using a subdomain or by forwarding requests to a specific path on your main domain."],["Server-side tagging hosted on the default domain lacks access to crucial server-set cookie benefits, unlike same-origin setups."],["Setting up same-origin serving requires updating DNS entries or configuring a CDN/load balancer, depending on the chosen method."],["Before implementing same-origin serving, ensure you've established a server container in Tag Manager and set up a tagging server."]]],["To leverage server-set cookie benefits, host your tagging server in the same first-party context as your website. Options include using the same origin (e.g., `www.example.com/metrics`) or a subdomain (e.g., `metrics.example.com`). Both allow full cookie access, unlike the default provider-hosted domain. Implementing same-origin requires a CDN/load balancer and potential DNS updates, while subdomains only need DNS adjustments. Pre-setup of a server container and tagging server is required.\n"]]