GoSquared People integration - how to get user name and email in Javascript at <head> customization?

I will do something like this :

  1. get username with the current session
  2. get the rest now you have the username with the API

$(document).ready(function() {
    $.ajax({
        type: 'GET',
        cache: false,
        url: 'https://discoruse.forum.com/session/current.json',
        dataType: 'json',
        xhrFields: {
            'withCredentials': true
        },
        success: function(result){
            // you get the username
            result = result.current_user;
            var user_name = result.username;
            var user_id = result.id;
            var user_avatar = result.avatar_template;
            $.ajax({
                type: 'GET',
                cache: false,
                url: 'https://forum.com/users/' + user_name + '/activity.json',
                dataType: 'json',
                xhrFields: {
                    'withCredentials': true
                },
                success: function(result){
                    // you get the email and date of registration
                    result = result.user;
                    var user_email = result.email;
                    var user_registation = result.created_at

                },
                error: function(result){
                    console.log('Error: '+result);
                }
            });
        },
        error: function(result){
            console.log('Error: '+result);
        }
    });

});

You can insert this code into the body from the admin panel → cutomization