[Google Analytics +] Track logged in users with Google Analytics +

I'm wondering GA+ has the ability to also track logged in users. GA generally seems to have a way to do this, but it isn't clear if GA+ is doing this.

Any thoughts on this from you guys?

  • Adam
    • Support Gorilla

    Hello Saunt Valerian,

    I hope you’re well today and thank you for your question!

    The Google Analytics code is injected to the site’s pages for logged in users too so such visits/pageviews should also be reflected in statistics.

    If I misunderstood your question, let me know please and I’ll be happy to provide you with more adequate answer.

    Best regards,

    Adam

  • Saunt Valerian
    • The Bug Hunter

    I have a client asking about tracking known users across the site. GA has the ability to provide data on the activity related to a user ID, but I’m trying to find out if GA+ sends that data to Google appropriately.

    Here is more reading about what I am talking about:

    https://support.google.com/tagmanager/answer/4565987?hl=en

    https://www.workshopdigital.com/blog/implementing-user-id-tracking-google-tag-manager/

    The site itself needs to push the user ID to Google with the tracking data, so that would be in the realm of GA+ (if it supports it), then it is a matter of configuring GA (I think – I admit that I don’t fully understand this since I don’t spend much time in GA).

  • Adam
    • Support Gorilla

    Hi Saunt Valerian

    Thanks for your response and additional explanation and sorry for misunderstanding your question at first.

    This is something that Google Analytics + plugin won’t do “out of the box”. Furthermore, the GA code that it injects to the site is “hard coded” (though dynamically built) in plugin’s code so at first look, adding such sort of tracking would require some changes in plugin’s core code.

    However, I would like to consult that with our coders to see if we can find a workaround. Please keep an eye on this ticket for further information and I’ll update it for you soon, as soon as I got to know more.

    Best regards,

    Adam

  • Saunt Valerian
    • The Bug Hunter

    Thanks Adam for digging deeper on this.

    Even if it doesn’t support it now, I really think this might be a weak spot in the plugin that would be a nice addition to the roadmap. Maybe as an opt-in setting for site admins to select and choose to push the data to GA so that they can track those users.

  • Saunt Valerian
    • The Bug Hunter

    Adam,

    I wanted to give you more information about this to share with the coders. One of the tech at the client edited google-analytics-async.php and got this piece working and it is now sending the user data to Google Analytics.

    The edit was to add some code at line 212:

    gaplusu('set', 'userId', '<?php echo wp_get_current_user()->user_login; ?>');

    Editing the core is not ideal so we are looking to see if this can be a permanent change in the next version of the plugin. I don’t see that there would be any long-term problems caused by this, but maybe your coders can take this change into consideration.

  • Kostas
    • CTO

    Hi Saunt Valerian !

    Instead of editing the core plugin files it would be for the best to add the code via our Hooks.

    You can add the following code into your functions.php ( preferably the child-themes ) and it will have the same result. You can add as many extra variables for GA in this way.

    add_action( 'ga_plus_network_tracking_code_add_vars', 'add_extra_vars_to_ga' );
    function add_extra_vars_to_ga() {
    $var = "gaplusu( 'set', 'userId', '" . wp_get_current_user()->user_login . "' );";
    echo $var;
    }

    The above would output for example: gaplusu( ‘set’, ‘userId’, ‘tester’ ); if a user with username ‘tester’ was viewing your site.

    This way there’s no need to edit core files + you’re free to update the plugin when a new release happens without losing any changes or having to re-do your customizations.

    Note: I’m not a GA expert so I’m not sure if the correct way is to send an empty userId if there is no user logged in or to not send it at all. If you don’t want the set userId at all you can instead do this to only add the set userId on “logged in” users.

    add_action( 'ga_plus_network_tracking_code_add_vars', 'add_extra_vars_to_ga' );
    function add_extra_vars_to_ga() {
    $var = '';
    if ( is_user_logged_in() ) {
    $var = "gaplusu( 'set', 'userId', '" . wp_get_current_user()->user_login . "' );";
    }
    echo $var;
    }

    I hope this helps a bit more !

    Regards,

    Konstantinos