Archived

Google Analytics for WordPress Remarketing Code

Updated

Written by

Dave Warfel

Reading Time

3 minutes

If you buy something from one of our links, we may earn a commission.

We’ve seen a lot of WordPress users asking how to add Google’s remarketing code to their site to enable Google Analytics’s demographics & interests data in their reports. The remarketing code also gives advertisers more options when setting up AdWords campaigns.

The best Google Analytics plugin for WordPress is the one by Yoast, and we fully recommend you use it on every site you build. We’ll show you how to add Google’s remarketing code using Google Analytics for WordPress by Yoast.

There are other Google Analytics plugins for WordPress that might make this seem easier, but they don’t provide the same functionality that Yoast’s plugin does, nor are they backed by one of the most popular plugin developers in the entire community.

Default Analytics Code

After you’ve activated Google Analytics for WordPress, and connected your web property, you’ll see source code in the <head> section of your site that looks like this:

Google Analytics - View Source Standard

ga.src

The value assigned to the ga.src variable is what we’ll need to change to enable remarketing & demographics reporting.

Google states that we need to replace the default value of ga.src with this:

ga.src = ('https:' == document.location.protocol ? 'https://' : 'http://') + 'stats.g.doubleclick.net/dc.js';

Host ga.js Locally

  • In your WordPress admin, navigate to “Settings” > “Google Analytics”
  • Scroll down until you see “Host ga.js locally”
  • Check the box, and then enter the following value into the input field:
    http://stats.g.doubleclick.net/dc.js

If your site is loaded securely via https, use https instead. https://stats.g.doubleclick.net/dc.js

  • Click the button to update your settings

Google Analytics for WordPress - Host ga.js Locally

Because this is an advanced setting, you need to check the box that says “Show advanced settings” in order to see the Host ga.js locally option.

Now view your source code and you should see this:

Google Analytics - View Source Remarketing Code

Enable Remarketing in Google Analytics

Once you have your new code in place, you need to login to Google Analytics, and enable the Remarketing feature.

  • Login to your Google Analytics account
  • Navigate to the “Admin” area
  • Select the Account & Property of your site
  • Scroll down until you see Enable Demographics and Interest Reports. It’s under Display Advertiser Features.
  • Switch the option to ON, and save your changes

Google Analytics Remarketing Settings

View Demographic & Interest Reports

Google Analytics Demographics/Interests Menu

  • Switch over to the Reporting tab in Google Analytics
  • In the left menu, open up Audience, and click on one of the options under Demographics or Interests
  • It may take a day or two before you start to see data

Demographics & Interests will give you even more data to analyze within your Google Analytics account, and you can set it all up with the most popular Google Analytics plugin for WordPress.

Yoast is currently re-writing his plugin to add support for Universal Analytics. As of Dec 16, 2013, remarketing is not available if you’re using Universal Analytics. You must be using the ga.js analytics code.

 

Dave Warfel

LinkedIn  •  X (Twitter)
Dave has been working with WordPress since 2011. He's built 100s of client sites and almost a dozen of his own. He's tested almost every plugin you can think of, hosted with at least 10 different companies, and gone down every SEO rabbit hole you can imagine. When's he's not tinkering with new software, you'll find him in the mountains of Colorado, trail running, summiting peaks, and rippin' downhills on his mountain bike. 🏔️🏃🚴🤸

10 responses to “Google Analytics for WordPress Remarketing Code”

  1. 153351 Avatar
    153351

    I don’t see the option to “Host ga.js Locally” in the Yoast SEO options. I’m using the most updated version of the plugin: 4.3.5. Was this removed? Or is this somewhere else?

    1. 153351 Avatar
      153351

      I mean in the Analytics plugin, not SEO.

  2. Dave Warfel Avatar

    @153351 – You need to check the “Show advanced settings” checkbox. It will then appear down near the bottom of the page. (screenshot)

  3. Scott Avatar

    Great Example. I changed the code and put it in the php file, but your way is much better, because it won’t break with future updates. Thanks for sharing.

    1. Dave Warfel Avatar

      Sure thing, Scott. And I’m sure I don’t have to remind you that it’s never a good idea to edit plugin files directly… especially not ones as popular (and frequently updated) as Yoast’s plugins.

  4. Mathan Avatar
    Mathan

    You saved my 2 hours due to this article. Thxs
    The top 6 ranking on Google doesn’t solve my issue, but Yours helped.

  5. Linton Avatar

    Hey Dave,

    Thanks for writing the guide. I’ve followed your instructions exactly, (enabled demographics etc), but when I get to demographics –> overview, there is a yellow pop up at the top saying “Some data in this report may have been removed when a threshold was applied. Learn more”

    I’m using a classic analytics account.

    Did I do something wrong?

  6. Ben Avatar

    I followed all of the steps outlined in this article and I am still having problems. I enter in the ga.js URL, but rather than displaying in the layout that Google expects:

    ga.src = (‘https:’ == document.location.protocol ? ‘https://’ : ‘http://’) + ‘stats.g.doubleclick.net/dc.js’;

    It displays in this format:

    ga.src = ‘http://stats.g.doubleclick.net/dc.js’;

    I can’t figure out any other way to work around this. Any help would be appreciated. Thanks!

  7. Scott Frangos Avatar

    Great article. Any word on when Yoast will add Universal Analytics?

  8. Oliver Avatar

    Question about this article:
    i’m using v5.0.6 and the option to host ga.js locally is nolonger in the plugin settings? What is the current solution for this problem?

Leave a Comment