Last active
April 12, 2023 11:17
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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