Google Analytics for WordPress Remarketing Code

Google Analytics for WordPress - Remarketing Code

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


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://') + '';

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:

If your site is loaded securely via https, use https instead.

  • 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.


10 Commentson "Google Analytics for WordPress Remarketing Code"

  1. /

    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?

    → Reply
    1. /

      I mean in the Analytics plugin, not SEO.

  2. (Author) /

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

    → Reply
  3. /

    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.

    → Reply
    1. (Author) /

      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. /

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

    → Reply
  5. /

    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?

    → Reply
  6. /

    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://’) + ‘’;

    It displays in this format:

    ga.src = ‘’;

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

    → Reply
  7. /

    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?

    → Reply

What Are Your Thoughts?

All fields are required. Your email will not be published.

You can use standard <code> and <pre> tags to post code examples, or a service like