Title: [Plugin: Google Analytics for WordPress] Custom Code: _setSiteSpeedSampleRate()
Last modified: August 20, 2016

---

# [Plugin: Google Analytics for WordPress] Custom Code: _setSiteSpeedSampleRate()

 *  [wolfy_](https://wordpress.org/support/users/wolfy_/)
 * (@wolfy_)
 * [13 years, 8 months ago](https://wordpress.org/support/topic/plugin-google-analytics-for-wordpress-custom-code-_setsitespeedsamplerate/)
 * Hi,
 * When I inser the Custom Code:
    _gaq.push([‘_setSiteSpeedSampleRate’, 100]);
 * and the I save it change it for:
    _gaq.push([\’_setSiteSpeedSampleRate\’, 100]);
 * and this is breaking my analytics, is there any solucion?
 * Thanks
 * [http://wordpress.org/extend/plugins/google-analytics-for-wordpress/](http://wordpress.org/extend/plugins/google-analytics-for-wordpress/)

Viewing 5 replies - 1 through 5 (of 5 total)

 *  [nsgundy](https://wordpress.org/support/users/nsgundy/)
 * (@nsgundy)
 * [13 years, 2 months ago](https://wordpress.org/support/topic/plugin-google-analytics-for-wordpress-custom-code-_setsitespeedsamplerate/#post-3049474)
 * Hi,
 * Just came across the same issue, some additional information:
    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.
 * So current workaround is to remove any backslashes from the custom code setting
   whenever you are saving the settings.
 *  [nsgundy](https://wordpress.org/support/users/nsgundy/)
 * (@nsgundy)
 * [13 years, 2 months ago](https://wordpress.org/support/topic/plugin-google-analytics-for-wordpress-custom-code-_setsitespeedsamplerate/#post-3049475)
 * Alright, found a fix for this.
 * Looking at version 4.3.2 of Google Analytics for WordPress.
    Change line 561 
   in wp-content/plugins/google-analytics-for-wordpress/admin/class-admin.php 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.
 *  [nsgundy](https://wordpress.org/support/users/nsgundy/)
 * (@nsgundy)
 * [13 years, 1 month ago](https://wordpress.org/support/topic/plugin-google-analytics-for-wordpress-custom-code-_setsitespeedsamplerate/#post-3049484)
 * Can this please be implemented? The update to 4.3.3 did not include a fix.
 *  [David Hunt](https://wordpress.org/support/users/dvd3141/)
 * (@dvd3141)
 * [13 years, 1 month ago](https://wordpress.org/support/topic/plugin-google-analytics-for-wordpress-custom-code-_setsitespeedsamplerate/#post-3049486)
 * I just found there are at least two [other](http://wordpress.org/support/topic/custom-code-field-mask-error-cut-data)
   [threads](http://wordpress.org/support/topic/custom-code-problem) about this 
   bug.
 * I just tried this fix but it did not work for me, using version 4.3.3 of the 
   plugin with WordPress 3.5.1. The custom code string is still truncated and contains
   backslashes.
 * Joost, is there any chance a fix can be incorporated into the next update?
 *  [Erik Hos](https://wordpress.org/support/users/erik-hos/)
 * (@erik-hos)
 * [12 years, 11 months ago](https://wordpress.org/support/topic/plugin-google-analytics-for-wordpress-custom-code-_setsitespeedsamplerate/#post-3049494)
 * Having the same problem when adding the custom code for pagespeed tracking. A
   fix would be appreciated, as I’d rather not modify the plugin files after each
   update.

Viewing 5 replies - 1 through 5 (of 5 total)

The topic ‘[Plugin: Google Analytics for WordPress] Custom Code: _setSiteSpeedSampleRate()’
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/)

 * 5 replies
 * 4 participants
 * Last reply from: [Erik Hos](https://wordpress.org/support/users/erik-hos/)
 * Last activity: [12 years, 11 months ago](https://wordpress.org/support/topic/plugin-google-analytics-for-wordpress-custom-code-_setsitespeedsamplerate/#post-3049494)
 * Status: not resolved