Support » Plugin: Google Analytics for WordPress by MonsterInsights » Bug Fix – Author with apostrophe in name

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


    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:


    which is correctly processed by Google.

  • The topic ‘Bug Fix – Author with apostrophe in name’ is closed to new replies.