Set up First-party mode

This document is for users who want to deploy the Google tag in first-party mode. We recommend First-party mode for the most durable tag configuration.

Overview

First-party mode lets you deploy a Google tag using your own first-party infrastructure, hosted on your website's domain. This infrastructure sits between your website and Google's services. The setup in this documentation will help you better measure your website. You can set it up using your existing Content Delivery Network (CDN), load balancer, or web server.

In standard Google tag setups, your web page requests a Google tag from a Google domain. When the tag fires, it sends measurement requests directly to the Google product. In First-party mode, your website loads the Google tag from your first-party domain. When the tag fires, it sends measurement requests to your first-party domain, where they are forwarded to the relevant Google product.

This diagram represents the information flow in First-party mode:

First-party mode architecture information flow.

Before you begin

This guide assumes that your website is already configured with:

To get started, pick your setup type.

1. How it works

This feature adds the Google tag or Tag Manager container to the very top of your web page, before all other scripts, which may affect how your tag interacts with on-page code like gtag('set'), gtag('consent'), and scripts such as other tag managers or consent management platforms. This is particularly important for privacy settings such as consent or personalization settings.

If you rely on on-page code to set consent defaults, you will need to set the default consent state using the override consent defaults setting in every Google tag you load on the page, or add a consent mode template to your Tag Manager container. Ensure your consent management platform sends consent updates using the consent mode API.

If you rely on on-page code to set personalization settings, you will need to configure those settings using the Google tag or Tag Manager product settings.

Fill in the following to populate the examples throughout this document.

Your domain: example.com
Measurement path: /metrics

2. Setup steps

a. Navigate to the First-party mode settings in your Google tag

  1. Access your Google tag screen
  2. Go to the Admin tab
  3. Under Google tag management open the First-party mode settings

b. Choose a Measurement Path

By default the measurement path is a combination of four alphanumeric characters to reduce the likelihood of conflicting with a path already on your website.

To customize the measurement path:

  1. Expand the measurement path slat by clicking the arrow icon
  2. Enter your custom path in the input field - /metrics

c. Sign in with Cloudflare

After choosing a measurement path, click the Sign into Cloudflare button. Log into your Cloudflare account to grant the Google tag access to deploy First-party mode.

Granting access allows the Google tag to:

  1. See your account info (e.g. account details, analytics, and memberships)
  2. Read your account zones
  3. Read, edit, and publish Google tags in First-party mode on your site
  4. Perform authorized actions in the background without your presence
    • Note: other users with Publish permission on your Google tag can update the first-party settings.

d. Enable First-party mode

Before enabling First-party mode, check that that the Cloudflare zones listed match your expectations and that your measurement path is not already in use.

After verifying your setup, click the Complete setup button at the bottom of the card to enable First-party mode for all of your Cloudflare zones.

3. Managing First-party mode

Once enabled, you can manage First-party mode using the Configure button found in the top-right card header.

Clicking the button gives you the following options:

  1. Pause or Activate
    • Disables or enables First-party mode for all the domains in your Cloudflare account
  2. Configure in Cloudflare
    • Opens the Cloudflare dashboard, allowing you to configure each domain independently

Test the measurement set up

To test the measurement set up, configure your container to have at least one tag that fires.

  1. Go to Tag Assistant and preview your container. Navigate through your site to trigger events.

  2. In the Summary > Output > Hits Sent tab, verify that the hits are routed to /metrics.

    Screenshot verifying the setup