• How do I adjust the site speed sample rate in the yoast plugin. Normally, it is done by changing this line ga(‘create’, ‘UA-XXXXX-1’, ‘auto’); to ga(‘create’, ‘UA-XXXXX-1’, {‘siteSpeedSampleRate’: 100}). Is there any way I can add this code using their advanced “add a line of code” function or some other method?

    I tried adding ga({‘siteSpeedSampleRate’: 100}) but that did not work

    https://wordpress.org/plugins/google-analytics-for-wordpress/

Viewing 3 replies - 1 through 3 (of 3 total)
  • Hi,

    just bumping this up as I would also need to knwo.
    As said by anaderi, just trying to set the parameter doesn’t work.
    also tried _gaq.push([‘_setSiteSpeedSampleRate’, 100]); and it just breaks all the tracking.

    Anyone knows how to do this?

    As far as I understand this should be done in the creation, so it would have to be an option of the plugin, as just adding extra code wouldn’t work.

    if anyone knows how to do it, I would be greatly appreciated.

    cheers,
    Miguel

    Hey, sorry, I forgot about this post, but I have a solution.

    Go here: /wp-content/plugins/google-analytics-for-wordpress/frontend

    and change the code block that starts with the comment “//set tracking code here”. You can see where I changed it for the “else” statement, but you can do it for any of the “ifs” as well.If you need to add the sample rate code where there is already curly bracket code, just add a comma follow by the code snippet. e.g. if there is already {‘allowAnchor’: true} then just add {‘allowAnchor’: true, siteSpeedSampleRate:100}

    ***Note on syntax: Anything you put in between quotes “” will end up getting written into the GA code.

    // Set tracking code here
    			if ( ! empty( $ua_code ) ) {
    				if ( $this->options['add_allow_linker'] && ! $this->options['allow_anchor'] ) {
    					$gaq_push[] = "'create', '" . $ua_code . "', '" . $domain . "', {'allowLinker': true}";
    				} else {
    					if ( $this->options['allow_anchor'] && ! $this->options['add_allow_linker'] ) {
    						$gaq_push[] = "'create', '" . $ua_code . "', '" . $domain . "', {'allowAnchor': true}";
    					} else {
    						if ( $this->options['allow_anchor'] && $this->options['add_allow_linker'] ) {
    							$gaq_push[] = "'create', '" . $ua_code . "', '" . $domain . "', {'allowAnchor': true, 'allowLinker': true}";
    						} else {
    							$gaq_push[] = "'create', '" . $ua_code . "', {siteSpeedSampleRate:100}";
    						}
    					}
    				}
    			}

    Hi anaderi,

    Thanks for coming back and sharing.

    I was trying to avoid changing the plugin code as it will be lost with updates.
    However, it seems to be the only way…

    cheers,
    miguel

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Site Speed Sample Rate’ is closed to new replies.