WordPress.org

Ready to get started?Download WordPress

Forums

Google Analytics for WordPress
Bug Fix - Author with apostrophe in name (1 post)

  1. Scott Selikoff
    Member
    Posted 2 years ago #

    Found a bug in reporting 'Author Name' for Google Analytics that breaks if the author has an apostrophe in their name. Let's say the author's name is John O'Smith. The resulting PHP generated JavaScript code read by the browser is then:

    _gaq.push(['_setCustomVar',1,'author','john-o'smith',3],...

    which does not properly process the data nor show this user on the Google Analytics page.

    Fix: Replace the body of ga_str_clean() around Line 814 of googleanalytics.php with the following code that wraps the ga_str_clean() method with regex that replaces ' with \' as follows:

    return remove_accents(str_replace('\'','\\\'',str_replace('---','-',str_replace(' ','-',strtolower(html_entity_decode($val))))));

    Because the code is written in PHP, it must be escaped in PHP before translated into Javascript, therefore the literal is \' to \\\'. The resulting generated code is then:

    _gaq.push(['_setCustomVar',1,'author','john-o\'smith',3]

    which is correctly processed by Google.

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic