Dynamically disable Advertising Features or Advertising Personalization in Google Analytics

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.

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

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. If you’ve enabled Advertising Features in an app, you can also control whether Advertising Features or Advertising Personalization are enabled by following these instructions.

Before July 16, 2020, setting allow_ad_personalization_signals to false disables all advertising features. After July 16th, 2020, setting allowAdPersonalizationSignals to false for Universal Analytics properties or allow_ad_personalization_signals to false for App + Web properties will no longer affect the advertising reporting features turned on in your Google Analytics property. This setting will mark relevant hits with a field that tells Google Analytics to omit the associated data from Ads Personalization features.

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.

Disable advertising personalization

Universal Analytics implementations

  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. For Field Name, enter allowAdPersonalizationSignals.
  4. For Value, enter false (or select a variable that returns false conditionally).

App + Web implementations

  1. Open any relevant App + Web Configuration tag.
  2. Under More Settings > Fields to Set, select + Add Field.
  3. For Field Name, enter allow_ad_personalization_signals.
  4. For Value, enter false (or select a variable that returns false conditionally).

Disable all advertising features

Universal Analytics implementations

  1. Open any relevant Universal Analytics tag. 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. For Field Name, enter allowAdFeatures.
  4. For Value, enter false (or select a variable that returns false conditionally).

App + Web implementations

  1. Open any relevant App + Web Configuration tag.
  2. Under More Settings > Fields to Set, select + Add Field.
  3. For Field Name, enter allow_google_signals.
  4. For Value, enter false (or select a variable that returns false conditionally).
Enable with Google Tag Manager

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 only advertising personalization with gtag.js, set allow_ad_personalization_signals to false before any config commands:

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

To disable all advertising features with gtag.js, set allow_google_signals to false before any config commands:

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

Read the developer documentation for more information, including how to disable advertising personalization only for specific products.

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 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.

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.

Enable with analytics.js

To enable these features for Universal Analytics, insert the highlighted 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 highlighted code 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 highlighted code 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>

Disable with Measurement Protocol

If you use Measurement Protocol to send data into Google Analytics, you may flag that data as not to be used for advertising personalization. Learn more in Developer Documentation for Measurement Protocol.

Was this helpful?
How can we improve it?