Skip to content

Instantly share code, notes, and snippets.

@hitGovernor
Last active April 12, 2023 11:17
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hitGovernor/19ea232c84286cf7ecc34a6a33df7c1b to your computer and use it in GitHub Desktop.
Save hitGovernor/19ea232c84286cf7ecc34a6a33df7c1b to your computer and use it in GitHub Desktop.
Retrieves the HotJar user ID from the browser. The ID can be passed to analytics or other systems as a way to connect HotJar recordings to other systems.
(function () {
// gets hotjar user id (hjUID)
var hjUID = "";
try {
if (typeof (hj) != "undefined" && hj.hasOwnProperty("globals")) {
// sample: a21c0a02-3b48-53c6-94b4-5604e281e5d8
// the value before the first "-" ("a21c0a02") is the user identifier that can be referenced in the hj interface
// use the following snippet to return only the user identifier (eg// "a21c0a02"):
// hjUID =hj.globals.get("userId").split("-").shift();
// use the following snippet to return the full string (eg// "a21c0a02-3b48-53c6-94b4-5604e281e5d8")
hjUID = hj.globals.get("userId");
}
} catch (err) {
/** ignore **/
}
// return hjUID or an empty string ""
return hjUID;
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment