for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
function generateIdentifier() {
const possible = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'
let text = ''
for (let i = 0; i < 20; i++) {
text += possible.charAt(Math.floor(Math.random() * possible.length))
}
return text
export default function getIdentifier(userIdentifier) {
if (userIdentifier || userIdentifier === 0) {
return String(userIdentifier)
if (typeof window === 'undefined' || !('localStorage' in window)) {
return null
const key = '__ab_experiment_identifier__'
try {
userIdentifier = localStorage.getItem(key)
localStorage
/** global: localStorage */
This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.
To learn more about declaring variables in Javascript, see the MDN.
userIdentifier = userIdentifier && String(userIdentifier)
if (!userIdentifier) {
userIdentifier = generateIdentifier()
localStorage.setItem(key, userIdentifier)
} catch (exception) {
return userIdentifier
This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.
To learn more about declaring variables in Javascript, see the MDN.