Invalid user ID

Find out the solution for non-string user IDs.

The following error occurs when identifying a user with a non-string identifier, which is common in applications that use numeric sequences.

By design, the SDK does not perform automatic conversion to alert you to potential problems and avoid unexpected results that can occur when converting numbers to strings, especially when dealing with large numbers.

As a workaround, you can convert the numeric identifier to a string before calling any method that identifies the user, such as identify. Ideally, this should be done on the server side to avoid potential representation inconsistencies between the server and client.

If server-side conversion is not feasible, you can alternatively perform the conversion on the client side as follows:

Handling numeric IDs
123456789
function convertId(id) {
if (!Number.isSafeInteger(id)) {
throw new Error(`The ID "${id}" cannot be safely converted to a string.`);
}
return id.toFixed(0);
}
croct.identify(convertId(randomUserId));