On a Rocket.Chat cloud hosted instance, is there a way to use Admin>Layout>Custom Scripts to retrieve the userID, email, user name, or custom field of a user during that (logged-in) user’s session?
The API can provide this information of course, but I don’t know how I’d authenticate (using custom JS on client side). As a work around, there might be some way to pull username off the DOM (would have to be on each page load), but I haven’t found it.
Background
My company has several “campuses” and I’ve successfully used “custom fields” + the API to assign a campus to each user profile.
I’ve also implemented Google Tag Manager, and I would like to track users by “campus” using Google Tag Manager. To do this, during each user’s session, I want to access that user’s custom field so I can push that value (eg. “New York City”) to Google Tag Manager’s data layer. (I have tried pushing test strings to the data layer using JS in “custom scripts”, so I know that part works)
If it’s not possible to access the custom field directly, if I can access the user’s UserID, email, or user name, I can use that information to call a database elsewhere and get the information.
Server Setup Information
Version of Rocket.Chat Server: 3.2
Hosted on the Rocket.Chat cloud
Answering my own question here, in case it’s helpful to others.
The root of the problem was that I didn’t know how to log into the API from within a user session.
The userID and Token are stored in the Local Session under meteor.UserID and meteor.loginToken. Easy to see in the Chrome Debugger: