Viewing 5 replies - 1 through 5 (of 5 total)
  • I am also having this exact issue, since the same date in Sept., and it’s a big problem for me. Can this be fixed?

    This plugin change really burned me… all the custom variable tracking was removed in version 5. I was able to re-enable the features that I use however, by adding the following code to my functions.php file.

    function yoast_str_clean( $val ) {
    	return remove_accents( str_replace( '---', '-', str_replace( ' ', '-', strtolower( html_entity_decode( $val ) ) ) ) );
    }
    function fix_yoast_GA_JS( $gaq_push ) {
    	global $wp_query, $current_user;
    	// Make sure $current_user is filled
    	get_currentuserinfo();
    	// pop & store the trackPageView action, which will be the last item in the array
    	$gaq_push_tail = array_pop( $gaq_push );
    	// record logged in user info
    	if ( $current_user && $current_user->ID != 0 ) {
    		array_push( $gaq_push, "'_setCustomVar',1,'logged-in','" . $current_user->roles[0] . "',1" );
    	}
    	// record post author name
    	array_push( $gaq_push, "'_setCustomVar',2,'author','" . yoast_str_clean( get_the_author_meta( 'display_name', $wp_query->post->post_author ) ) . "',3" );
    	// record category
    	if ( is_single() ) {
    		$cats = get_the_category();
    		if ( is_array( $cats ) && isset( $cats[0] ) )
    			array_push( $gaq_push, "'_setCustomVar',3,'category','" . $cats[0]->slug . "',3" );
    	}
    	// restore the trackPageView action to the end of the array
    	array_push( $gaq_push, $gaq_push_tail );
    	return $gaq_push;
    }
    add_action('yoast-ga-push-array-ga-js', 'fix_yoast_GA_JS');

    This code will re-enable logged-in role, post author name, and post category custom variable tracking. Note that I hard-coded my custom variable slot numbers and it might not match the slot numbers that you were previously using. Log in to GA and check out your Custom Variables dashboard to see which slot number you should be using for each of these.

    If you really need these features and you don’t feel like messing with the code, I guess you could always downgrade to v4.3.5.

    I should have used add_filter instead of add_action but functionally it’s the same since add_action is an alias to add_filter anyway…

    is there any update to this from Yoast? I would very much like to re-enable.

    I assume you used Custom Variables. Unfortunately, they have been deprecated by Google in favor of GA’s new feature: Custom Dimensions.

    You can read all about it in this blogpost by Thijs.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Stats by author’ is closed to new replies.