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
Atlassian Community Anniversary

Happy Anniversary, Atlassian Community!

This community is celebrating its one-year anniversary and Atlassian co-founder Mike Cannon-Brookes has all the feels.

Read more
Community showcase
Kesha Thillainayagam
Posted Apr 13, 2018 in Confluence

We want to hear how your non-technical teams are using Confluence!

Hi Community! Kesha (kay-sha) from the Confluence marketing team here! Can you share stories with us on how your non-technical (think Marketing, Sales, HR, legal, etc.) teams are using Confluen...

2,925 views 27 12
Join discussion

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