Display 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

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, including remarketing and advertising reporting features, set displayFeaturesTask to null:

ga('create', 'UA-XXXXX-Y', 'auto');
ga('set', 'displayFeaturesTask', null);
ga('send', 'pageview');

Note that in the above code the advertising features plugin isn't required because advertising features has been turned on in Google Analytics.