# User Email

**URL:** <https://community.hubspot.com/t/user-email/127204>\
**Category:** CMS Development\
**Tags:** javascript, email, starter\
**Created:** [March 3, 2025, 1:57pm UTC](https://community.hubspot.com/t/user-email/127204 "2025-03-03T13:57:06Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Hutfuchs](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/hutfuchs/32/204411_2.png) [@Hutfuchs](https://community.hubspot.com/u/Hutfuchs)\
**Post date:** [March 3, 2025, 1:57pm UTC](https://community.hubspot.com/t/user-email/127204/1 "2025-03-03T13:57:06Z")

</div>

Morning Mates,

I try to use the \_hsq.push([‘identify’… Function to track the custom events by user.

But how can I get the email of the current logged in User?

- there is a https cookie with the Data but not for js available

- I also didn’t find any variable in Hubl to get the user info’s

--\> so how can I get the mail of logged in users in Hubspot?

---

<div class="post-metadata">

**Author:** ![Jaycee\_Lewis](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/jaycee_lewis/32/61352_2.png) [@Jaycee\_Lewis](https://community.hubspot.com/u/Jaycee_Lewis)\
**Post date:** [March 4, 2025, 5:01pm UTC](https://community.hubspot.com/t/user-email/127204/2 "2025-03-04T17:01:11Z")

</div>

Hey, @Hutfuchs 👋 Is this for use on HubSpot-hosted pages or non-HubSpot pages? — Jaycee

---

<div class="post-metadata">

**Author:** ![Balaji\_Mavlers1](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/balaji_mavlers1/32/59061_2.png) [@Balaji\_Mavlers1](https://community.hubspot.com/u/Balaji_Mavlers1)\
**Post date:** [April 8, 2025, 2:11pm UTC](https://community.hubspot.com/t/user-email/127204/3 "2025-04-08T14:11:12Z")

</div>

Hi Hutfuchs,  
To track custom events with the \_hsq.push([‘identify’, …]) function and associate them with the logged-in user’s email in HubSpot, here are some strategies to consider:  
1. Using HubSpot’s JavaScript API (if user is logged in):  
If the user is logged into your HubSpot portal, HubSpot’s JavaScript API allows you to access some user information. Unfortunately, the email is not directly available via the standard API for privacy reasons, but you can try the following:  
\_hsq.push([‘identify’, {  
email: ‘{{ contact.email }}’ // Use HubL to inject the email if available  
}]);  
However, {{ contact.email }} only works in HubSpot pages where the contact is known (e.g., on a form submission thank-you page).  
2. Accessing Email via HubSpot Cookie (Using Server-Side Rendering):  
Since you mentioned that the data exists in a cookie but isn’t accessible via JavaScript, consider this workaround:  
Server-Side Rendering (SSR): If you’re using HubSpot CMS, you can inject the email server-side using HubL like this:  
\<script\>  
var userEmail = ‘{{ contact.email }}’;  
\_hsq.push([‘identify’, { email: userEmail }]);  
\</script\>  
This works if the contact is known when the page loads.  
3. Using HubSpot’s Contact API (for Dynamic Identification):  
If the user is logged in but the email isn’t available client-side, you can make an API call to HubSpot’s Contacts API to fetch the user’s details:  
fetch(‘/api/v1/contacts/email’, {  
method: ‘GET’,  
headers: {  
‘Content-Type’: ‘application/json’,  
‘Authorization’: ‘Bearer YOUR\_API\_KEY’  
}  
})  
.then(response =\> response.json())  
.then(data =\> {  
\_hsq.push([‘identify’, { email: data.email }]);  
});  
(Note: This requires server-side logic to handle API keys securely.)  
4. Using a Hidden Form Field:  
If you’re already using forms on your site, you can pass the email via a hidden field:  
\<input type=“hidden” name=“email” value=“{{ contact.email }}”\>  
Then capture the value in Javascript&colon;  
var userEmail = document.querySelector(‘input[name=“email”]’).value;  
\_hsq.push([‘identify’, { email: userEmail }]);  
5. Custom Cookie Handling:  
If the email is stored in a cookie but not accessible via JavaScript, it may be an HttpOnly cookie. In this case:  
Server-Side Approach: Use server-side code to read the cookie and inject the value into the HTML as a JavaScript variable.  
Custom Authentication: If you’re managing your authentication, you can store the email in a non-HttpOnly cookie for JavaScript access (ensuring compliance with privacy regulations).
