Not sure why Mixpanel is tagged on this question, but since it is, I'll mention that the Mixpanel jslib solves this problem.
If you send events without identifying the user, the jslib automatically generates a UUID based on time, Math.random()
, and browser characteristics. This data is stored in a cookie.