> [!NOTE]
> **Note:** The `gtag('config')` command is deprecated. We recommend managing destinations and tag settings in the Google Tag Manager UI (for example, by [adding a destination tag](https://support.google.com/tagmanager/answer/17326492)), or using `gtag('set')` for in-page parameters. **If you are using gtag.js today and use `gtag('config')` commands, you do not need to retag your website. Your setup will continue working as it does today.**
> **Why are we making this change?**
>
> Various parts of the gtag API were designed for a time when the Google tag had no UI, and all configuration had to come as in-page code. This forced you to hard-code your preferred configuration and data routing decisions directly onto your website, making it harder to change your settings later. Hard-coding also locks these settings into a specific point in the page or event lifecycle, which adds complexity and introduces the risk of race conditions.
>
> Now that the Google tag and Google Tag Manager platforms are unified, every tag now has an interface. You no longer need to make setup decisions upfront or hard-code them on your website.

This page is for developers who need to configure the Google tag using
gtag.js. To adjust settings in the user interface instead, see
[Configure your Google tag settings](https://support.google.com/tagmanager/answer/12131703).

After installing the Google tag, you can call `gtag()` commands anywhere in your
code *after* the Google tag snippet.

This page shows you how to:

1. Send events to your Google products using the `event` command
2. Set values that are sent with every event using the `set` command

> [!TIP]
> **Tip:** For an overview of all available commands, refer to the [gtag.js
> reference](https://developers.google.com/tag-platform/gtagjs/reference).

## Before you begin

This guide assumes you have done the following:

- Made yourself familiar with [how the Google tag works](https://developers.google.com/tag-platform/gtagjs)
- Installed the [Google tag](https://developers.google.com/tag-platform/gtagjs/install)

To set up the data flow, you need:

- Access to the website code where you installed the Google tag
- The tag ID of the Google product you want to connect to the Google tag

<br />

**What is a tag ID and where to find it?** A tag or container ID identifies the Google Tag Manager container or Google destination configuration loaded by your Google tag snippet. New installations use a Google Tag Manager container ID (**GTM-** ) by default, while destination-specific IDs identify individual Google products. The following table provides an overview of supported ID prefixes:

| Prefix | ID type | Description |
|---|---|---|
| **GTM**-XXXXXX | Google Tag Manager container ID (default) | Default ID for Google Tag Manager containers. Supports all Google, third-party, and custom tags. |
| **G**-XXXXXX | Destination-specific ID | Identifies a Google Analytics destination (Measurement ID). |
| **AW**-XXXXXX | Destination-specific ID | Identifies a Google Ads destination (Conversion ID). |
| **DC**-XXXXXX | Destination-specific ID | Identifies a Floodlight destination (Advertiser ID). |
| **MC**-XXXXXX | Destination-specific ID | Identifies a Google Merchant Center destination. |
| **GT**-XXXXXX | Google tag ID | Identifies a Google tag created in prior versions. |

**Find your tag ID**:

- [Google Ads](https://ads.google.com/aw/tagsettings)
- [Google Analytics](https://support.google.com/analytics/answer/9539598)
- [Google Floodlight](https://support.google.com/searchads/answer/2466080)

<br />

<br />

<br />

## Step 1: Connect Google products to your tag

Use the `config` command to establish data flow to Google products.

### About the `config` command

The `config` command specifies Google products you want to send event data to.
The command has the following format:

    gtag('config', 'TAG_ID', {<additional_config_params>});

#### Additional configuration parameters

You can adjust and extend a `config` command by specifying parameters in the
optional `{<additional_config_params>}` object. For example, adding the following
parameter will prevent a Google Analytics pageview from being automatically
sent:

```
gtag('config', 'TAG_ID', {'send_page_view': false});
```

### Set up data collection

To set up data collection for a Google product, add the `config` command with a
tag ID.

> [!IMPORTANT]
> **Important:** You should call the `config` command only once per Google tag. Every subsequent call should use the `set` command.

#### Example

The Google tag (`GT-XXXXXX`) sends data to the
[destinations](https://support.google.com/tagmanager/answer/12324388) you
defined for it, for example Google Ads and Google Analytics.

The following example shows how to update your code to load a second Google tag
that is connected to a Floodlight destination.

To send data to Floodlight (tag ID `DC-ZZZZZZ`), add another `config` command
after initializing the first Google tag (tag ID `GT-XXXXXX`):

    <head>
     ...
    <!-- Google tag (gtag.js) -->
    <script async src="https://www.googletagmanager.com/gtag/js?id=G-XXXXXX"></script>
    <script>
      window.dataLayer = window.dataLayer || [];
      function gtag(){dataLayer.push(arguments)};
      gtag('js', new Date());
      gtag('config', 'GT-XXXXXX');gtag('config', 'DC-ZZZZZZ');
    </script>
    </head>

### Product-specific `config` behavior

Depending on the product specified in `TAG_ID`, the `config` command may also
initiate certain behavior for that product. For example, in some cases the
`config` command tells gtag.js to initiate a pageview event.

To learn more about how the `config` command behaves in relation to individual
products, read the product-specific documentation:

- [Google Ads conversions](https://support.google.com/google-ads/answer/1722022) and [remarketing](https://support.google.com/google-ads/answer/2454000)
- [Campaign Manager and Display \& Video 360](https://support.google.com/dcm/partner/answer/7568534)
- [Search Ads 360](https://support.google.com/searchads/answer/7550511)
- [Google Analytics](https://developers.google.com/analytics/devguides/collection/gtagjs)

## Step 2: Send data with `event`

After you configure connections to Google products, you need to use the `event`
command to send data.

### About the `event` command

The `event` command lets you send event data to the products you specified with
`config`. The command has the following format:

    gtag('event', 'event_name', {
      'key': 'value',
    });

#### About event names and key-value pairs

**Recommended events** : [Recommended events](https://developers.google.com/tag-platform/gtagjs/reference/events) are events that
you implement, but that have [predefined key-value pairs](https://developers.google.com/tag-platform/gtagjs/reference/parameters). These events unlock
existing and future reporting capabilities.

**Custom events**: To define your own events and
data structures, you can enter custom values to send a custom event.

### Set up events

You can call the `event` method anywhere in your code **after** initializing the
Google tag.

1. Define an event. If you are using a recommended event, make sure you use the
   [standardized event names](https://developers.google.com/tag-platform/gtagjs/reference/events) and [predefined key-value pairs](https://developers.google.com/tag-platform/gtagjs/reference/parameters).

2. Define when the event will be triggered, for example if it gets sent with a
   page load or when someone clicks on a button.

#### Example

The following example illustrates **one** possible way to measure newsletter
signups when a user clicks a button. The example uses a custom event and sends
it to a Google Analytics property.

    <head>
       ...
       /* 1. Initialize the Google tag and gtag.js library */
       <!-- Google tag (gtag.js) -->
       <script async src="https://www.googletagmanager.com/gtag/js?id=TAG_ID"></script>
       <script>
         window.dataLayer = window.dataLayer || [];
         function gtag(){dataLayer.push(arguments)};
         gtag('js', new Date());
         gtag('config', 'TAG_ID');
       </script>
    </head>

    <body>
       <script>
         let date = Date.now();
         /* 2. Define your event. */
         function newsletterSignup() {
           gtag('event', 'newsletter_signup', {
    'time': date,
    });
       }
       </script>
       ...
       /* 3. Trigger your event */
       <button type="submit" onclick="newsletterSignup()">Sign me up!</button>
       ...
    </body>

## Optional: Send data with every event using `set`

The `set` command lets you define parameters that will be associated with every
subsequent event on the page.

For example, you can share
[campaign](https://developers.google.com/analytics/devguides/collection/ga4/reference/config#campaign)
parameters so that they can be accessed by multiple tags on the same page.

The command has the following format:

    gtag('set', 'parameterName');

## Step 3: Validate your setup

To make sure that your event data is sent properly:

1. Open the Google product you expect to see data in.
2. Check if data is coming in. Each product has a different place where you can check if data is being received:
   - Google Analytics: Check the [Realtime
     report](https://support.google.com/analytics/answer/9271392).
   - Google Ads: Check your [Conversion actions](https://ads.google.com/aw/conversions) table and look at the **Status** column (it may take up to 24 hours to update).
   - Floodlight: Use [Tag Assistant](https://tagassistant.google.com/) to verify that Floodlight tags are firing.

### Next steps

After setting up your Google products and events, you are done with the basic
Google tag configuration.

If you are managing multiple products and want to manage their data flow in more
detail, see [Group and route data](https://developers.google.com/tag-platform/gtagjs/routing).