Configure products and send data

You can invoke gtag() commands anywhere on your page after the global snippet. There are three commands you can use: config and set are used to establish general properties; event is used to send data.

Initialize products with config

Use the config command to initialize and configure settings for a particular product account. The config command takes the following format:

gtag('config', '<target_ID>', {<additional_config_info>});

where <target_ID> is the ID of the product-account to which you want to send data, and the <additional_config_info> is an optional object used to specify additional configuration options.

The config command enables you to specify which products and accounts gtag.js should handle, and to specify associated configuration. Depending on the product specified in the target_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 hit. To learn more about how the config command behaves in relation to individual products, read the product-specific documentation:

The most basic example consists of just the config command and a target_id:

gtag('config', 'GA-TRACKING_ID');

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

gtag('config', 'GA-TRACKING_ID', {'send_page_view': false});

Send data with event

The event command is how you send event data. For example, you can use the event command to send a login event with a method value of "Google":

gtag('event', 'login', {
  'method': 'Google'

There is a set of recommended events, along with recommended parameters, that are useful in specific contexts. You can also send custom events that are not included in the list of recommended events.

Send data on every event with set

The set command allows you to set parameters that will be associated with every subsequent event on the page. For example, if all transactions on your site use the same currency, you can use the set command to specify the currency field:

gtag('set', {'currency': 'USD'});

You can set multiple attributes with a single set command:

gtag('set', {
  'country': 'US',
  'currency': 'USD'