Dynamically disable Advertising Features or Advertising Personalization in Google Analytics

If you have activated Google signals, then disabling Advertising Features will deactivate Google signals.

The preferred method of enabling and disabling Advertising Features, including Remarketing and Advertising Reporting Features, or Advertising Personalization is to modify your property settings.

However, there may be times when you want to disable these features dynamically for a given page load or session, for example, when users have indicated they do not want their data used for the purpose of personalizing ads. You can accomplish this by modifying any version of the Analytics tracking code for which Advertising Features are available.

The following sections explain how to programmatically disable these features regardless of whether you've enabled them via your property settings or via your tracking code. The corresponding programmatic enablement instructions, also available elsewhere in our documentation, are provided here for reference.

Disable with Google Tag Manager

To disable advertising features or advertising personalization when your Google Analytics tags are configured in Google Tag Manager, set the allowAdFeatures or allowAdPersonalizationSignals field to false in Fields to Set in your tag or settings variable:

  1. Open any relevant Universal Analytics tags or Google Analytics Settings variables. If your tag uses a Google Analytics Settings variable, you only need to make this change in the settings variable unless you want to override it on a tag by tag basis.
  2. Under More Settings > Fields to Set, select + Add Field.
  3. As the Field Name, enter allowAdFeatures.
  4. As the Value, enter false (or select a variable that returns false conditionally).
Enable with Google Tag Manager

It is not currently possible to enable Display Remarketing and the Advertising Reporting Features via code using gtag.js. If you use gtag.js and want to enable Display Remarketing and the Advertising Reporting Features, modify your property settings in Analytics.

If you enabled the toggle in your property settings but have disabled Advertising features in the tag, and then you want to re-enable them (for example after consumer consent is given), you can simply cease the disablement at a tag level. This will effectively "re-enable" Advertising features for that customer.

Disable with gtag.js

To disable all advertising features with gtag.js, set allow_google_signals to false. This code must appear before any config statements:

gtag('set', 'allow_google_signals': false);

To disable only advertising personalization with gtag.js, set allow_ad_personalization_signals to false. This code must appear before any config statements:

gtag('set', 'allow_ad_personalization_signals': false );

Note that if you’ve configured Connected Site Tags, you’ll need to follow these instructions if you wish this signal to propagate to your Connected Site Tags.

Enable with gtag.js

It is not currently possible to enable Display Remarketing and the Advertising Reporting Features via code using gtag.js. If you use gtag.js and want to enable Display Remarketing and the Advertising Reporting Features, modify your property settings in Analytics.

If you enabled the toggle in your property settings but have disabled Advertising features in the tag, and then you want to re-enable them (for example after consumer consent is given), you can simply cease the disablement at a tag level. This will effectively "re-enable" Advertising features for that customer.

Disable with analytics.js

To disable all advertising features with analytics.js, set allowAdFeatures to false:

Add ga('set', 'allowAdFeatures', false); after the create command, and before the hit is sent.

To disable only advertising personalization with analytics.js, set allowAdPersonalizationSignals to false:

Add ga('set', 'allowAdPersonalizationSignals', false); after the create command, and before the hit is sent.

Enable with analytics.js

To enable these features for Universal Analytics, insert the bold line into your existing tracking code between the 'create' and 'send' commands, as in this example:

<script>
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','//www.google-analytics.com/analytics.js','ga');
ga('create', 'UA-XXXXXX-XX', 'example.com');

ga('require', 'displayfeatures');
ga('send', 'pageview');
</script>

Disable with ga.js

To override the property settings to turn off Advertising Reporting Features:

Add _gaq.push(['_set', 'displayFeatures', false]); after the create command, and before the hit is sent.

Enable with ga.js

If you're still using ga.js, you can enable Remarketing and Advertising Reporting Features for Standard Analytics by replacing the bold text in this example:

Standard tracking code

<script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-xxxxx-y']);
_gaq.push(['_trackPageview']);
(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;


ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';

var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();
</script>

 

with the bold text in the example below:

Code modified to enable these features

<script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-xxxxx-y']);
_gaq.push(['_trackPageview']);
(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;


ga.src = ('https:' == document.location.protocol ? 'https://' : 'http://') + 'stats.g.doubleclick.net/dc.js';

var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();
</script>
Was this helpful?
How can we improve it?