Unstable User Email Identification Script in HubSpot

We want to collect feedback about our product from customers using your Feedback Surveys option.
However, we want to know who sent us the feedback and avoid receiving anonymous opinions.

To achieve this, we pass the user’s email as per HubSpot documentation.

Unfortunately, we have encountered instability with this method. Sometimes, the email is transmitted and identified correctly, but Feedback Surveys still requests the email

Conditions of the Issue:

The issue with the email prompt primarily occurs when a user accesses our platform for the first time. If the user navigates to another page after the initial load, the issue does not reoccur. During our troubleshooting, we added a timeout for the script loading and processing and ensured the script execution happens after the initial load. However, this solution has also proven to be unstable.
More details:

After integrating the HubSpot Tracking Code, the following occurs:

  • Sometimes the form works correctly, sending data and displaying the message “Thanks so much.”

  • Sometimes the form prompts for an email input, despite the email being passed via the line _hsq.push([‘identify’, { email: “#{User.current.email}” }]);.

The problem is inconsistent: sometimes the form works correctly, and sometimes it asks for an email input even though HubSpot always receives the user data.

Steps Taken:

  1. Script Loading Check:
  • Verified that the HubSpot script loads without errors through the browser’s developer console.
  1. User Identification Check:
  • Ensured that the line _hsq.push([‘identify’, { email: “#{User.current.email}” }]); correctly substitutes the current user’s email.
  1. Asynchronous Script Loading:
  • Tried different script loading methods, including loading the script after the page fully loads using window.addEventListener(‘load’, …).
  1. Adding Logs and Debugging:
  • Added console logs to verify that the user identification is performed correctly each time it is needed.
  1. Session and User State Check:
  • Ensured that the current user’s state updates correctly on all application pages, especially after login.

Results:

None of the above steps led to a stable resolution of the problem. The form continues to malfunction, requiring the user’s email input despite these details being passed to HubSpot. When navigating through pages, the script reloads, and the form starts working correctly, adding to its inconsistent behavior.

Hi @hsgfmdev! Welcome to the community and thanks so much for your post.
I understand you are trying to use a HubSpot API to pass the contact email to the feedback survey form to prevent anonymous submissions, but you are seeing intermittent success. You outlined your troubleshooting steps well-- I probably would have recommended a delay/timeout as well.
I would love to invite a couple of our experts on this one. @Teun @evaldas Have either of you come across this issue before? Do you have any suggestions or alternative solutions you have found in this type of scenario? Thanks in advance! :blush:

Hey @RomanGruit or @zaklein -- wanted to invite y’all for some extra eyes if you have come across something similar!

HI @hsgfmdev -- I wanted to check in here. Glad to see you reached out to HubSpot Support on this one. The Support team can access your account from the backend to verify if there are any issues on our end causing this.
If you get a helpful response, we would love if you could share your findings here as well to benefit other Community members who may encounter the same issue. We can keep this open to see what other Community members can contribute as well. :blush:

Best,
Kennedy

Hi @hsgfmdev :waving_hand:

Thanks for the detailed explanation of the issue you’re experiencing. Would you please clarify:

  1. Which kind of HubSpot Feedback Survey are you using (Custom survey, Customer support, Customer satisfaction, Customer loyalty) and what’s its delivery method (e.g. Email, Shareable link, Web page)?
  2. Do you currently have Contact “Email” as a required or optional field in your Feedback Survey form?
  3. How do you know the given user’s email address (e.g. is the Feedback Survey only visible to logged in users?)

Answers to these questions should help the community troubleshoot the issue you’re experiencing. Please let me know if you have any follow-up questions.

Thanks @zach_threadint :raising_hands: — Jaycee