Skip to content

Instantly share code, notes, and snippets.

@Rendez
Created February 24, 2014 10:40
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Rendez/9185389 to your computer and use it in GitHub Desktop.
Save Rendez/9185389 to your computer and use it in GitHub Desktop.
Create a 'returning visitor' or 'new visitor' property for Mixpanel.
/**
* If the mixpanel cookie exists this user was in the site before,
* we have to consider him returning, only every 24 hours, just like GA.
*/
var RETURNING_VISITOR = document.cookie.indexOf('_mixpanel') != -1;
// if the mixpanel cookie does not exists the user is considered new
if (!RETURNING_VISITOR) {
$.cookie('mp_visitor', true, { expires: 1, path: '/' });
// else the user might not be returning.
} else if ($.cookie('mp_visitor') !== null) {
RETURNING_VISITOR = false;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment