Thanks for previewing Google's new tag platform documentation! This site is in public beta. (Feedback)

Group and route data

Installations of the Google tag (gtag.js) can be configured to route data to specific groups of accounts or products. Complete measurement solutions for Google measurement products can be configured all from within the same code block. This guide explains how to configure the Google tag to send data to specific products, accounts, and configurations using the send_to and groups parameters.

Default routing

Your Google tag contains a config command to handle routing. For example, when you install the Google tag with a tag ID, the following snippet sends data to your Google Analytics 4, Google Ads accounts, or both:

gtag('config', 'TAG_ID');

You can override the routing that's specified in the Google tag (or any earlier routing instructions on the page) by adding the send_to parameter to event commands.

For example, the following sign_in event is only sent to a Google Analytics property with the destination ID 'G-XXXXXX-2', regardless of which targets were previously configured on the page.

gtag('event', 'sign_in', { 'send_to': 'G-XXXXXX-2' });

Groups

Sometimes you may need to send certain information to a set of accounts or products, and send other pieces of information to another set of accounts or products. For example, you may want to send information about specific marketing campaigns to your ad agency, while retaining more complete data for your organization. This functionality can be organized using groups.

You can create a group of targets (e.g. products, accounts, and properties) and then route events to that group. In the following example, two Google Analytics properties are added to a group named group1. Then, a sign_in event is routed to the two properties in that group.

gtag('config', 'G-XXXXXX-1', { 'groups': 'group1' });
gtag('config', 'G-XXXXXX-2', { 'groups': 'group1' });

// Routes to 'G-XXXXXX-1' and 'G-XXXXXX-2'
gtag('event', 'sign_in', { 'send_to': 'group1' });

Default group

If a send_to parameter is not set, events are routed to the default target group. The default group includes all products and accounts from config commands on the page that have executed prior to the event. Even if the groups parameter is not specified in a config command, the target is assigned to the default group.

// The following two lines are equivalent:
gtag('config', 'G-XXXXXX-1');
gtag('config', 'G-XXXXXX-1', { 'groups': 'default' });

The next example illustrates that events are sent to the default group, regardless of whether {'send_to : 'default'} is specified.

// Configure a target
gtag('config', 'G-XXXXXX-1');

// Since send_to is not specified, this routes to the 'default' group which
// includes 'G-XXXXXX-1', as defined in config, above.
gtag('event', 'sign_in');

// By default, routes to the 'default' groups which includes
// 'G-XXXXXX-1', as defined in config, above.
gtag('event', 'generate_lead', { 'send_to': 'default' });

Route to custom groups

Using groups, you can identify certain pieces of data that should be routed to a specific set of IDs. The following code sample illustrates how to route sign_in event data to a custom group called agency.

// Configure a target
gtag('config', 'G-XXXXXX-1');
gtag('config', 'G-XXXXXX-3', { 'groups': 'agency' });
gtag('config', 'G-XXXXXX-9', { 'groups': 'agency' });

// Routes only to 'G-XXXXXX-3' and 'G-XXXXXX-9' since they
// are both in the 'agency' group
gtag('event', 'sign_in', { 'send_to': 'agency' });

Example: Configure Google Ads, Analytics, Floodlight together

You can create complete configurations for Google Ads, Google Analytics, and Floodlight all from within the same Google tag. This example demonstrates what a combined tag might look like. This example:

  • Sends pageview data to Google Analytics
  • Measures Google Ads and Floodlight conversions
  • Sends information about an item added to a shopping cart to Analytics and Google Ads
<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());

  // Global configs
  gtag('config', 'TAG_ID');
  gtag('config', 'DC-ZZZZZZ');

  // Measure Google Ads conversions
  gtag('event', 'conversion', {
      'send_to': 'AW-YYYYYY/AbC-D_efG-h12_34-567',
      'value': 1.0,
      'currency': 'USD'
  });

  // Measure Floodlight conversions
  gtag('event', 'conversion', {
    'allow_custom_scripts': true,
    'send_to': 'DC-ZZZZZZ/actions/locat304+standard'
  });

  // Route ecommerce add_to_cart event to Google Ads and Analytics
  gtag('event', 'add_to_cart', {
    'send_to': [
      'G-XXXXXX-1',
      'AW-YYYYYY'
    ],
    'items': [
      'id': 'U1234',
      'ecomm_prodid': 'U1234',
      'name': 'Argyle Funky Winklepickers',
      'list': 'Search Results',
      'category': 'Footwear',
      'quantity': 1,
      'ecomm_totalvalue': 123.45,
      'price': 123.45
    ]
  });
</script>