Once gtag.js has been installed, you can configure it to send (or route) data
to groups of accounts or products. Complete measurement solutions for Google Ads
and the Google Marketing Platform can be configured all from within the same tag. This
guide explains how to use gtag.js to send data to specific products, accounts,
and configurations using the send_to
parameter and groups
.
Default routing
Each global snippet contains a config
command to handle routing. For example,
the Google Analytics global snippet configures gtag.js to send data to a
specified Analytics account:
gtag('config', 'GA_MEASUREMENT_ID-1');
You can override the routing that's specified in the global snippet (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 sent only to
Google Analytics property 'GA_MEASUREMENT_ID-2', regardless of which targets were
configured previously on the page.
gtag('event', 'sign_in', { 'send_to': 'GA_MEASUREMENT_ID-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', 'GA_MEASUREMENT_ID-1', { 'groups': 'group1' });
gtag('config', 'GA_MEASUREMENT_ID-2', { 'groups': 'group1' });
// Routes to 'GA_MEASUREMENT_ID-1' and 'GA_MEASUREMENT_ID-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', 'GA_MEASUREMENT_ID-1');
gtag('config', 'GA_MEASUREMENT_ID-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', 'GA_MEASUREMENT_ID-1');
// Since send_to is not specified, this routes to the 'default' group which
// includes 'GA_MEASUREMENT_ID-1', as defined in config, above.
gtag('event', 'sign_in');
// By default, routes to the 'default' groups which includes
// 'GA_MEASUREMENT_ID-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', 'GA_MEASUREMENT_ID-1');
gtag('config', 'GA_MEASUREMENT_ID-3', { 'groups': 'agency' });
gtag('config', 'GA_MEASUREMENT_ID-9', { 'groups': 'agency' });
// Routes only to 'GA_MEASUREMENT_ID-3' and 'GA_MEASUREMENT_ID-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, Analytics, and Floodlight all from within the same global site tag. The following example demonstrates what a combined tag might look like. This example will:
- Send pageview data to Google Analytics.
- Measure Google Ads and Floodlight conversions.
- Send information about an item added to a shopping cart to Analytics and Google Ads.
<script async src="https://www.googletagmanager.com/gtag/js?id=GA_MEASUREMENT_ID-1">
</script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
// Global configs
gtag('config', 'GA_MEASUREMENT_ID-1');
gtag('config', 'AW-CONVERSION_ID');
gtag('config', 'DC-FLOODLIGHT_ID');
// Measure Google Ads conversions
gtag('event', 'conversion', {
'send_to': 'AW-CONVERSION_ID/AbC-D_efG-h12_34-567',
'value': 1.0,
'currency': 'USD'
});
// Measure Floodlight conversions
gtag('event', 'conversion', {
'allow_custom_scripts': true,
'send_to': 'DC-FLOODLIGHT_ID/actions/locat304+standard'
});
// route ecommerce add_to_cart event to Google Ads and Analytics
gtag('event', 'add_to_cart', {
'send_to': [
'GA_MEASUREMENT_ID-1',
'AW-CONVERSION_ID'
],
'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>