How can I track user data with Google Analytics?

I want to remain using Universal Google Analytics outside of Confluence (rather than using a plugin).

My wiki is for employees and requires login, so I am in compliance with the User-ID policy as far as I can tell. My users login via an LDAP directory.

I'd love to be able to track who has viewed what.

I think I need to add a USER_ID to this code, but I'm not sure which one to use. I've tried global variables: $current_user_email and current_user_email

ga(‘set’, ‘&uid’, {{USER_ID}}); // Set the user ID using signed-in user_id.

Additionally, the &uid portion of the GA tracking code is throwing an error in my theme.

3 answers

This is not currenty possible while complying with Google Analytics terms of service.

In your example, the {{USER_ID}} variable must be set using valid JavaScript. For example like so:

var userId = 'some value'; // you need to populate this
ga('set', '&uid', userId);

David Simpson discusses how to achieve this (and importantly how not to achieve this) in Identifying your users in Google Analytics while complying with section 7 of the terms of service.

He is currently suspended from Atlassian Answers, so perhaps ask your question out in the open at Stack Overflow instead.

Also, don't add this into your theme. Stick it in the Custom HTML instead.

The following code works for me (userId represented by 32-digits key):

ga('create', 'UA-xxxxxxxx-1', 'auto', {
userId:  '$userAccessor.getUserIfAvailable($req.remoteUser).getKey()'

Suggest an answer

Log in or Sign up to answer
Community showcase
Published Mar 12, 2019 in Confluence

Confluence Admin Certification now $150 for Community Members

More and more people are building their careers with Atlassian, and we want you to be at the front of this wave! Important Dates Start the Certification Prep Course by 2 April 2019 Take your e...

1,633 views 4 13
Read article

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you