Question

I want to track events on a chrome extension I'm building. So I want to have a unique identifier for each user.

I don't want any information about the user, simply I want all of they're events grouped together.

Is there a good way to solve this, without pinging a server. Or will I just use a really long random string so the probability of getting the same string by another user is low.

I'm using segment.io's analytics.js package to integrate with mixpanel.

Was it helpful?

Solution 2

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.

OTHER TIPS

You can generate an id upon extension install/update. You can then use this value as your unique id. Something like this should work (put it in your background page):

chrome.runtime.onInstalled.addListener(function(info){
    //    
    // info.reason should contain either "install" or "update"

    var sessionId = localStorage.getItem("session-id");

    if(!sessionId){
      localStorage.setItem("session-id", "random-session-id");
    }
});

More info on onInstalled is here: https://developer.chrome.com/extensions/runtime#event-onInstalled. NB: it fires on install, extension update and Chrome update.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top