Pergunta

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.

Foi útil?

Solução 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.

Outras dicas

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.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top