You can set custom campaign data in Google Analytics 4. Campaign data values can be set via parameters in gtag.js and via Google Tag Manager.
Note that if you have auto-tagging enabled, gtag.js cannot be used to override gclid information.
Set campaign values in gtag.js
To set campaign values globally, use gtag('set', ...)
and add fields prefixed with campaign_
:
gtag('set', {
'campaign_id': 'google_1234',
'campaign_name': 'Summer_fun',
'campaign_source': 'google',
'campaign_medium': 'cpc',
'campaign_term': 'summer+travel',
'campaign_content': 'logolink',
});
'campaign_id': 'google_1234',
'campaign_name': 'Summer_fun',
'campaign_source': 'google',
'campaign_medium': 'cpc',
'campaign_term': 'summer+travel',
'campaign_content': 'logolink',
});
You can add campaign values in gtag.js for a specific Google Analytics ID with gtag('config' ...)
:
gtag('config', 'G-12345', {
'campaign_id': 'google_1234',
'campaign_name': 'Summer_fun',
'campaign_source': 'google',
'campaign_medium': 'cpc',
'campaign_term': 'summer+travel',
'campaign_content': 'logolink',
});
'campaign_id': 'google_1234',
'campaign_name': 'Summer_fun',
'campaign_source': 'google',
'campaign_medium': 'cpc',
'campaign_term': 'summer+travel',
'campaign_content': 'logolink',
});
For a list of all supported campaign fields, refer to the developer documentation.
Set campaign values in Tag Manager
To set campaign values in Google Tag Manager, use Fields to Set.
- In Google Tag Manager, open the relevant workspace.
- Click Tags and then click the name of the Google Analytics 4 Configuration tag you want to work with.
- Click Tag Configuration > Fields to Set.
- Click the Add Row button for each field you want to add. Consider the table below for example values:
Field Name Example value campaign_id google_1234 campaign_name Summer_fun campaign_source facebook campaign_medium cpc campaign_term summer+travel campaign_content logolink - Click Save to save your tag configuration.
- Submit your changes and publish the container.