Get Free Quote
« Lifetime Achievement... | Blog home | How to Leverage... »
October 17, 2013

Code Typo In Google Analytics Demographics and Interests Reports Snippet

  • Print Friendly, PDF & Email

Ah. The old apostrophe that looks like a single quote catastrophe all code monkeys dread.

Warning! If you have it on your to-do list to get your Google Analytics account up and running with the new Google Analytics Demographics and Interests reports be aware that there is a sneaky apostrophe in the DC.js code snippet supplied on the Enable Demographics and Interests Google Analytics Help page that should be a single quote.

To get demographic and interests data flowing into your GA account, Google Analytics Help instructs you to:

ga.src = (‘https:’ == document.location.protocol ?’https://ssl’ : ‘http:// www’) + ‘’;

ga.src = (‘https:’ == document.location.protocol ? ‘https://’ : ‘http://’) + ‘’;

Note to innocent copy-pasters that the before ‘’; is typed as an apostrophe on the help page (and here because WordPress keeps changing the HTML…) and needs to be changed to a single quote in order to avoid a frustrating GA crash and a long-winded troubleshooting session.

GA Demographic reports DC.js code

Questions? Ask away in the comments section!

  • Print Friendly, PDF & Email

6 responses to “Code Typo In Google Analytics Demographics and Interests Reports Snippet”

  1. Shad writes:

    For those of us using Universal Analytics – the code will not allow for demographic data – anyone know how to fix this?

    Here is a sample of Universal Analytics code that will not validate for the demographic data.

    (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),

    ga(‘create’, ‘UA-12345678’, ‘’);
    ga(‘send’, ‘pageview’);

  2. phil writes:

    just an update…

    the business with ‘.’ – your article is correct.

    also, after trolling around and trying a few things, i found a 30oct2013 link that makes me think this is all a bit early:!topic/analytics/4hQJLrojd38

  3. phil writes:

    Thanks for your article. I looked on Yoast but didn’t find anything mentioning this, so far.

    Here’s the real plugin code [below] – a bit more involved than the example.

    Isn’t there a missing ‘.’ in ‘’?
    Should read ‘’?

    And correspondingly, should
    ‘’ read

    Do you happen to know ramifications (if any) for current_user_can ‘manage_options’ in the suggested changes for demographics? Is the value ‘u/ga_debug.js’ still a valid $script value?

    (function () {
    var ga = document.createElement(‘script’);
    ga.type = ‘text/javascript’;
    ga.async = true;

    ga.src = options[‘gajslocalhosting’] && !empty( $this->options[‘gajsurl’] ) )
    {echo “‘” . $this->options[‘gajsurl’] . “‘;”; } else {
    $script = ‘ga.js’;
    if ( current_user_can( ‘manage_options’ ) && $this->options[‘debug’] )
    $script = ‘u/ga_debug.js’;

    echo “(‘https:’ == document.location.protocol ? ‘https://ssl’ : ‘http://www’) + ‘” . $script . “‘”;}
    var s = document.getElementsByTagName(‘script’)[0];
    s.parentNode.insertBefore(ga, s);

  4. Chelsea Adams writes:

    Hi, Abinash!

    1) When you go into Google Analytics, can you see data in the Demographics left column pulldown? If you can, that means that Joost has automatically updated the HTML in your plugin and you don’t have to worry about adding the code snippet mentioned in this blog post. You’re good to go.

    2) If you don’t see demographic metrics being pulled into the Demographics portion of your GA account that means you need help from Joost… or someone who knows how to update code.
    With this scenario you have two options:
    a) Email Joost and ask him to help you! (Like this guy did:
    b) Do it yourself like this:
    (Based on the instruction for inserting AdWords Retargeting in this blog post:

    Go to the Plugins > Editor section of your WordPress admin and choose Google Analytics for WordPress from the “Select plugin to edit:” menu on the right.

    From the list of files that appears below, click “google-analytics-for-wordpress/frontend/class-frontend.php”.

    Use the browser’s find function to search for this code snippet
    ga.src = (‘https:’ == document.location.protocol ?’https://ssl’ : ‘http:// www’) + ‘’;

    Replace that snippet with this snippet:
    ga.src = (‘https:’ == document.location.protocol ? ‘https://’ : ‘http://’) + ‘’;

    and update the file.

    NOTE! IF YOU ARE NOT AWESOME AT CODE THERE IS A CHANCE YOU COULD BREAK THE PLUGIN IF YOU GO CHANGING THINGS WILLY NILLY….. SO PLEASE ENTER WITH CAUTION! For real. Email Joost first and ask before taking matters into your own hands if you don’t know what you’re doing because it is really, really inconvenient to have your GA crash.

  5. Abinash Mohanty writes:

    Hi Chelsea, Thanks for the suggestions. I am running analytics code via “Analytics for WordPress” plugin by Joost. However, there is no option for the code as you mentioned here to update via “Analytics for WordPress” plugin. Do you have any idea how to do that? Thanks in advance.

  6. J. Otis writes:

    Any word on how to collect demographics and interest data for sites using Universal Analytics? (

Get Started
Learn SEO

Be a Blog Subscriber

Save a trip! Get Bruce Clay's latest digital marketing strategy delivered to your inbox for free.

We respect your privacy and never share your email address

Free Executives Guide To SEO
By continuing to use the site, you agree to the use of cookies. AcceptDo Not Accept