First-party mode: Load Google scripts through server-side tagging

This article is for developers who use server-side tagging and want to serve Google scripts from their own servers.

Server-side tagging allows you to load Google scripts, such as gtm.js or gtag.js, directly from your tagging server instead of from Google's servers. This allows you to serve data within a first-party context.

Before you begin

This guide assumes that you have done the following:

To get started, pick your implementation option.

Step 1: Configure the client

To establish a first-party context between your web container and your tagging server, Google scripts need to be loaded through your server.

To load Google scripts through your server container:

Pick an implementation option to see instructions.

Step 2: Update the script source domain

By default, Tag Manager or gtag.js loads their dependencies from Google-owned servers, such as https://example.com/metrics. You need to update the script URL on your website to load dependencies through your own server.

Pick an implementation option to see instructions.

Step 3: Verify the source of your scripts

The following instructions show how to test using Google Chrome. You can use any browser of your choice, but the steps might differ.

To test if your server container is loading the dependencies:

  1. Open your website in a new browser tab.
  2. Open the browser's developer tools. In Google Chrome, you can right-click anywhere on the page and select Inspect.
  3. In the developer tools, open the Sources tab. This window displays all dependencies that were loaded when you opened the website.

    • ✅ Your implementation is correct if gtm.js is loaded from the source you specified.

    Screenshot of the developer tools with your own server as the source for Google scripts

    • ❌ If the Sources tab displays www.googletagmanager.com as the source for gtm.js, the dependencies are still loaded from Google servers.

    Screenshot of the developer tools with www.googletagmanager.com as the source for Google scripts

    • Check if you've modified the source URL in your code, see step 2.
    • Check if the code is live.

Next steps

If you are using consent mode, you can set up region-specific tag behavior for even more control.