Title: Bug with Custom Code
Last modified: August 21, 2016

---

# Bug with Custom Code

 *  [nsgundy](https://wordpress.org/support/users/nsgundy/)
 * (@nsgundy)
 * [12 years, 5 months ago](https://wordpress.org/support/topic/bug-with-custom-code/)
 * There is still this quite old bug in the with the custom code preference. I’ll
   be copy and pasting from one of my older posts on this:
 * **Description of the issue:**
 * > When adding
   >  _gaq.push([‘_setSiteSpeedSampleRate’, 100]); to the custom code
   > section, _gaq.push([\’_setSiteSpeedSampleRate\’, 100]); is stored in the database
   > and this is reflected by looking at this option again after adding it for the
   > first time. The result when loading the page however is _gaq.push([‘_setSiteSpeedSampleRate’,
   > 100]); and that is working well.
   > Now when you just hit save on the analytics settings page for the second time,
   > the following will be stored in the database:
   >  _gaq.push([\\\’_setSiteSpeedSampleRate\\\’,
   > 100]); When loading the page again _gaq.push([\’_setSiteSpeedSampleRate\’, 
   > 100]); will be the result and that’s where the analytic code breaks and stops
   > recording.
   > So there seems to be an issue with escaping special characters when storing
   > this value. The first time the ‘ will get escaped to \’ and that just seems
   > to be fine. But on a subsequent save both the escaping character as well as
   > the original ones will be escaped again, resulting in the \\\’ which breaks
   > it. Assuming that each subsequent save will add a lot of backslashes.
 * **Here is the fix:**
 * > Look for the following line in wp-content/plugins/google-analytics-for-wordpress/
   > admin/class-admin.php and change it from
   >  ‘content’ => $this->textinput( ‘customcode’),
   > to ‘content’ => stripslashes($this->textinput( ‘customcode’ )),
   > This adds the same function call for reading the customcode variable as used
   > by the code that actually inserts the variable into the tracking code when 
   > building a page.
 * [https://wordpress.org/plugins/google-analytics-for-wordpress/](https://wordpress.org/plugins/google-analytics-for-wordpress/)

Viewing 1 replies (of 1 total)

 *  [mingis](https://wordpress.org/support/users/mingis/)
 * (@mingis)
 * [12 years, 2 months ago](https://wordpress.org/support/topic/bug-with-custom-code/#post-4626356)
 * nice fix – this should be updated in the plugin, I’ve lost data from a few accounts
   after adding custom code snippets!

Viewing 1 replies (of 1 total)

The topic ‘Bug with Custom Code’ is closed to new replies.

 * ![](https://ps.w.org/google-analytics-for-wordpress/assets/icon.svg?rev=2976619)
 * [MonsterInsights - Google Analytics Dashboard for WordPress (Website Stats Made Easy)](https://wordpress.org/plugins/google-analytics-for-wordpress/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/google-analytics-for-wordpress/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/google-analytics-for-wordpress/)
 * [Active Topics](https://wordpress.org/support/plugin/google-analytics-for-wordpress/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/google-analytics-for-wordpress/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/google-analytics-for-wordpress/reviews/)

 * 1 reply
 * 2 participants
 * Last reply from: [mingis](https://wordpress.org/support/users/mingis/)
 * Last activity: [12 years, 2 months ago](https://wordpress.org/support/topic/bug-with-custom-code/#post-4626356)
 * Status: not resolved