Can I add User-ID to the Analytics code?
-
Hi, I see it’s easy to add the User-ID as specified by Google, I adapted this code.
and added it to my child theme via functions.php, like this:
//* Add User-ID for Analytics for logged in users add_action( 'wp_head', 'ux_userID', 99 ); function ux_userID() { if (is_user_logged_in()) { $user = wp_get_current_user(); $userName = $user->user_login; } if (isset($userName)) : ?> <!-- User-ID for Analytics --> <script type="text/javascript"> ga('set', 'userId', <?php echo(json_encode($userName)); ?>); // Set the user ID using signed-in user_id. </script> <!-- End User-ID for Analytics --> <?php endif; }
However, it is not much use for the MonsterInsights since it’s is separate from the generated Analytics code.
I see you can add code to MonsterInsights via Settings > Tracking > Compatability however you can’t add php code there.
So how can this be done? It looks like either pay $99 USD per annum or add Analytics manually without a plugin?
Viewing 4 replies - 1 through 4 (of 4 total)
Viewing 4 replies - 1 through 4 (of 4 total)
- The topic ‘Can I add User-ID to the Analytics code?’ is closed to new replies.