Dynamically disable Advertising Features in Google Analytics
The preferred method of enabling and disabling Advertising Features, including Remarketing and Advertising Reporting Features, 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 when your Google Analytics tags are configured in Google Tag Manager, set the allowAdFeatures
field to false in Fields to Set in your tag or settings variable:
- 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.
- Under More Settings > Fields to Set, select + Add Field.
- As the Field Name, enter allowAdFeatures.
- As the Value, enter false (or select a variable that returns false conditionally).
Disable with gtag.js
To disable display features using gtag.js, set the parameter allow_display_features
to false in your property's config:
gtag('config', 'GA_TRACKING_ID', { 'allow_ad_personalization_signals': false });
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.
Disable with analytics.js
To override the property settings to turn off Advertising Reporting Features:
Add ga('set', 'allowAdFeatures', false);
after the create
command, and before the hit is sent.
If you enabled Advertising Features via your tracking code:
Remove the line ga('require', 'displayfeatures');
.
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:
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
with the bold text in the example below:
Code modified to enable these features
* Nguồn: Google Analytics