Advertising Features

This guide describes how to use the advertising features plugin for analytics.js.

Overview

Google Analytics advertising features (including Remarketing Lists for Search Ads) can be enabled in Google Analytics from Property Settings > Data Collection. The advertising features plugin for analytics.js can be used to programmatically enable advertising features, as well as to override and disable all advertising reporting and remarketing features established in the Google Analytics UI.

Implementation

The recommended method is to enable advertising reporting features from Google Analytics' property settings.

To enable the advertising features plugin, add a require call and specify the displayfeatures plugin.

ga('create', 'UA-XXXXX-Y', 'auto');
ga('require', 'displayfeatures');
ga('send', 'pageview');

The plugin sends a request to stats.g.doubleclick.net that is used to enable advertising features. The plugin creates a new cookie named _gat that has a one minute timeout. This cookie does not store any user information; it's just used to limit the number of requests that have to be made to doubleclick.net.

The default cookie name is _gat. You can change it by setting the cookieName option when you require the plugin:

ga('require', 'displayfeatures', {cookieName: 'display_features_cookie'});

Note that the third argument is normally used to specify the script location. Since the this plugin is included in analytics.js, you can simply pass undefined.

Use Multiple Trackers

To use the advertising features plugin with multiple trackers, prepend the require call with the tracker name:

// create a tracker named 'foo' for property UA-XXXXX-Y
ga('create', 'UA-XXXXX-Y', {name: 'foo'});
ga('foo.require', 'displayfeatures');
ga('foo.send', 'pageview');

// create a second tracker named 'bar' for a different property UA-XXXX-Z
ga('create', 'UA-XXXXX-Z', {name: 'bar'});
ga('bar.require', 'displayfeatures');
ga('bar.send', 'pageview');

When the advertising features plugin for a named tracker is loaded, the tracker name is appended to the cookie name. The above example creates the cookies _gat_foo and _gat_bar.

Disable advertising features

Since advertising features can be enabled through your Google Analytics admin settings, there may be cases where you need to disable it programmatically.

To disable all advertising features with analytics.js, set allowAdFeatures to false after the create command, and before the send command.

ga('create', 'UA-XXXXX-Y', 'auto');
ga('set', 'allowAdFeatures', false);
ga('send', 'pageview');

When set to true (the default value), allowAdFeatures allows the displayfeatures plugin and the advertising features settings in Google Analytics to function. This field does not itself turn on these features.

Set allowAdFeatures to false to disable beacons for Google Analytics advertising features, whether they have been enabled via the displayfeatures plugin or from within Google Analytics.

To disable only advertising personalization features, set allowAdPersonalizationSignals to false after the create command, and before the send command.

ga('create', 'UA-XXXXX-Y', 'auto');
ga('set', 'allowAdPersonalizationSignals', false);
ga('send', 'pageview');