• How can I add my own custom variable? I want to track who logged in $current_user. I added this code to functions.php and it shows up in the <head> but below the yoast script?

    function jt_gatrackuser() {
    global $current_user;
    get_currentuserinfo();
    echo “\n”;
    echo ‘<script type=”text/javascript”>’ . “\n”;
    echo ‘//![CDATA[‘ . “\n”;
    echo ‘var _gaq=_gaq || [];’;
    echo ‘_gaq.push([\’_setCustomVar\’,4,\’username\’,\”;
    echo $current_user->user_login;
    echo ‘\’,2]);’ . “\n”;
    echo ‘//]]’ . “\n” . ‘</script>’;
    echo “\n”;
    }
    add_action(‘wp_head’, ‘jt_gatrackuser’);

    ?>

    This is what get generated below the Yoast script
    <script type=”text/javascript”>
    //![CDATA[
    var _gaq=_gaq || [];_gaq.push([‘_setCustomVar’,4,’username’,’Jim’,2]);
    //]]
    </script>

    http://wordpress.org/extend/plugins/google-analytics-for-wordpress/

Viewing 2 replies - 1 through 2 (of 2 total)
  • Did you ever find a solution for this? I want to do the same thing…

    I figured it out… You can use something like the code below:

    add_filter('yoast-ga-custom-vars','add_ga_custom_vars',10,2);
    
    function add_ga_custom_vars($push, &$customvarslot) {
       $my_custom_val = "whaterver";
    $push[] = "'_setCustomVar',".$customvarslot.",'My_Custom_Variable','".$my_custom_val."',3";
       $customvarslot++;
       return $push;
    }

    This worked for me. Hope it helps someone else.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘[Plugin: Google Analytics for WordPress] How can I add my own custom variable’ is closed to new replies.