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 widget could not be displayed.

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.

This widget could not be displayed.

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
Posted Sep 17, 2018 in Confluence

Why start from scratch? Introducing four new templates for Confluence Cloud

Hi my Community friends!  For those who don't know me, I'm a product marketer on the Confluence Cloud team - nice to meet you! For those of you who do, you know that I've been all up in your Co...

569 views 7 6
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