Get Confluence Logged In User's Email

Alok Nath Saha October 5, 2015

Hi,

I was wondering if there's a way to get the logged in user's email address in confluence and pass it as a dimension to Google Analytics ?
I know there's a field in the AJS.params called "remoteUserEmail: "$action.remoteUser.getEmail()" ", but I'm not sure how to fetch the user's email from that. 
mentions how to get the user's email, but none of the methods seems to work.
If you know of any way, it'd be helpful.
Regards,
Alok Nath Saha

2 answers

1 accepted

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

2 votes
Answer accepted
Stephen Deutsch
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
October 5, 2015

This should be able to help you at least get started:

$.ajax({
    url: contextPath + "/rest/prototype/1/user/non-system/" + AJS.params.remoteUser + ".json",
    success: function(response) {
        console.log(response.displayableEmail);
    }
});

You should know that AJS.params and $action are different.  AJS.params is a javascript object which has some details about the current session, but does not have e-mail information (which is why you have to do a REST API request as shown above to get "response.displayableEmail").  $action is an Apache Velocity object (a scripting language that Confluence uses on the backend) so it can be used inside of a user macro or plugin, but not on the frontend using Javascript.

Alok Nath Saha October 6, 2015

Thanks Stephen !

2 votes
TtheB
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
October 5, 2015

As an alternate approach, you could edit your main decorator layout file and add the line

<!DOCTYPE html>
<html>
<head>
    #putMetadata("remote-user-email", $action.remoteUser.getEmail())
</head>

in the head section. Afterwards you can get the value in JavaScript with

AJS.Meta.get("remote-user-email")
Stephen Deutsch
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
October 5, 2015

Nice, I like it!

TAGS
AUG Leaders

Atlassian Community Events