Update Analytics to support Display Advertising

You can use one of two methods to support Display Advertising in Analytics:

  • Update your Property Settings (web properties only)
  • Update your tracking code (web properties or apps)

When you enable Display features for a web property, then Google Analytics collects the information that it normally does, as well as the DoubleClick cookie when that cookie is present.

When you enable Display features for an app, then Google Analytics collects the information that it normally does, as well as information associated with advertiser IDs when they are collected for apps.

For more information about the DoubleClick cookie, visit the Google Advertising Privacy FAQ. When you enable support for Display features, you might also need to update your privacy policy.

Update your web Property Settings to enable Display features

This method applies only to web properties, and is supported only for properties that have been upgraded to Universal Analytics. To support Display features in your Android and iOS apps, you need to modify the tracking code in your apps.

To update your web Property Settings:

  1. Sign in to your Google Analytics account.
  2. Open the Account > Property for which you want to enable Display features.
  3. Click Admin at the top of any page.
  4. In the Property column, click Property Settings.
  5. Under Display Advertiser Features, set Enable Display Advertiser Features to ON.
    Property Settings, with Display Advertiser Features enabled.

If you have previously enabled Display features by updating your tracking code, you can still implement this Property Setting and not incur any conflicts.

Keep in mind that this method is only effective for enabling Display features as they relate to your website users. If you want to enable Display features as they relate to your app users, then you need to update your app tracking code per the methods outlined for Android and iOS in the next section.

Update your tracking code

If you choose to enable Display features by updating your tracking code, you need to make only a simple, one-line change to your code as described in the following sections. This modification does not impact any customisation you have previously made to your code.

The changes that you need to make to your web pages depend on which tracking code you’re using. See if you have Classic Analytics (ga.js) or Universal Analytics (analytics.js).

There can be circumstances where you have made these updates to the tracking code on only portions of your site, and then subsequently enabled Display features via the property setting, which then enables collection of the DoubleClick cookie on all your pages. In these circumstances, if you want to disable collection of the DoubleClick cookie for any of the pages that you previously modified, you need to revert the tags to their original states.

The same holds true under circumstances where you have tagged your entire site to enable Display features: to disable Display features for an individual page, you need to revert to the original tracking code.

Tracking code change for Universal Analytics (analytics.js)

To enable Display Advertising features for Universal Analytics, insert the bold line into your existing tracking code between the 'create' and 'send' commands, as seen 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>
To revert the change, simply remove the line ga('require', 'displayfeatures');
Tracking code change for Classic Google Analytics (ga.js)

To enable Display Advertising features for Classic Google Analytics, replace 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 Display 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>

You can also generate an updated basic code snippet that includes the change by going to Admin > property > Tracking Info, and turning on the Display Advertiser Support option.

To revert the change, simply modify your tracking code to match the standard tracking code example in this section.
Tracking code change for Android

To enable Display Advertising features for Android, modify your Google Analytics tracking code to collect the advertising ID. Call the enableAdvertisingIdCollection method on the tracker for which you want to enable display features. For example:

// Get tracker.
Tracker t = ((AnalyticsSampleApp) getActivity().getApplication()).getTracker(
TrackerName.APP_TRACKER);

// Enable Display Features.
t.enableAdvertisingIdCollection(true);

Learn more about supporting Display Advertising on Android

Tracking code change for iOS

To enable Display Advertising features for iOS, collect the IDFA (Identifier for Advertisers). To enable IDFA collection, link the libAdIdAccess.a and AdSupport.framework libraries to your application and set the allowIDFACollection to YES on each tracker that will collect the IDFA. For example:

// Assumes a tracker has already been initialized with a property ID, otherwise
// getDefaultTracker returns nil.
id tracker = [[GAI sharedInstance] defaultTracker];

// Enable IDFA collection.
tracker.allowIDFACollection = YES;

Learn more about supporting Display Advertising on iOS

If you're using Google Tag Manager, follow these instructions to edit the Analytics tag.