6

We have a setup where we capture Hotjar User ID in Google Tag Manager and then pass it as a custom dimension to Google Analytics. It's done to simply merge and cross-reference both data sources.

We used the following code to capture the User ID:

function() { return hj.property.get('userId'); }

2 days back we stopped receiving the data, even though there haven't been any changes to Google Tag Manage, Google Analytics or our Hotjar account.

My suspicion is that there have been a system update on the Hotjar end. I had a chat with their technical support, but they were unable to help me.

Would be great if someone with more experience could have a look at the following file, to see if there is a way to capturing the 'userId' value:

https://script.hotjar.com/modules-397099a69f05558cbf66f164cffcaf65.js

Thanks

Victor Leontyev
  • 8,488
  • 2
  • 16
  • 36
TomG
  • 71
  • 1
  • 3
  • Can you unpack that file (into jsfiddle or something) or update your question with relevant snippet of code? I'm at work and a bit paranoid, so I don't want to click that link. ;) – nyuen Nov 17 '16 at 01:13
  • It's a legit URL. Unfortunately the script is too large for me to post it here. Not enough available characters. – TomG Nov 17 '16 at 09:23
  • Yeah... that's too much to sift through and the scope the is too big, I'm afraid. You'll have to try hard to narrow it down to what you think could be the problem. – nyuen Nov 17 '16 at 18:12
  • I got this problem too. Previously "hj.property.get('userId');" will return me the HotJar ID but now it showing is not a function in console. – yk1007 Nov 25 '16 at 08:09
  • @TomG i've just received response from Hj: "[...] That is correct, yes. We changed our tracking code. In the future we will offer a more "unbreakable" solution on how to extract the userID. We are currently working on this and will keep you updated on it!" – Łukasz Rysiak Dec 19 '16 at 10:30

6 Answers6

7

Please try hj.pageVisit.property.get('userId'). This one has returned a proper userId for me today.

Rainer
  • 79
  • 3
6

As of FEB 2019 you can use the following to get the Hotjar User ID:

hj.globals.get("userId").split("-").shift()
LR.
  • 103
  • 1
  • 3
  • 6
  • 1
    Thank you, this works, but unfortunately it's not immediately available. Can you advise which event to listen to, at which point `globals` becomes available? – Liran H Apr 18 '19 at 12:07
3

Having looked at the JS file loaded by HotJar i discovered the following code

hj.hq.isUndefined(hj.globals.get("userId"))

From that i extracted the following

hj.globals.get("userId")

And this works for me as of today. Hope this helps someone else. Please let me know if it has worked in all cases.

jabreezy
  • 31
  • 1
1

It looks like it is not available in DOM right now.

According to Hotjar support:

...this change came about when we moved towards supporting Single Page Apps. I'm told that we may provide this ability again in the future, though I don't have an ETA for it at the moment, as we're currently focusing on improving other aspects of Hotjar.

Checking our current requests for this, it unfortunately seems that not a lot of users are voting on this feature - this is why it's pivotal for us to get this feedback on our "Suggest a Feature" tool

Cheers, Florian .

florian
  • 461
  • 1
  • 5
  • 11
0

Try this, but check with setTimeout until you get a value:

hj.pageVisit.property.get('userId').

OBS: In IE don't run this code... getting undefined value in response.

n4m31ess_c0d3r
  • 3,028
  • 5
  • 26
  • 35
Breno
  • 11
0

This code worked for me:

hj.globals.key.split("-").shift()    

If you are using GTM, use setTimeout or Tag sequencing to make sure this is triggered after hotjar Tag is loaded.

Sergej
  • 1
  • 3