Add an anonymous UUID to users in analytics to help understanding user behaviors in newIDE

This commit is contained in:
Florian Rival
2017-10-09 23:32:21 +02:00
parent d5f4a47eab
commit 60bf3115dd
2 changed files with 23 additions and 0 deletions

View File

@@ -1,4 +1,6 @@
import Keen from 'keen-tracking';
import { getUserUUID } from './UserUUID';
const sessionCookie = Keen.utils.cookie('visitor-stats');
const sessionTimer = Keen.utils.timer();
sessionTimer.start();
@@ -12,6 +14,9 @@ var client = new Keen({
client.extendEvents(function() {
return {
user: {
uuid: getUserUUID(),
},
page: {
title: document.title,
url: document.location.href,

View File

@@ -0,0 +1,18 @@
// See https://gist.github.com/jed/982883
const generateUUID = (a) => {
return a
// eslint-disable-next-line
? (a ^ Math.random() * 16 >> a / 4).toString(16)
: ([1e7] + -1e3 + -4e3 + -8e3 + -1e11).replace(/[018]/g, generateUUID);
}
const localStorageKey = 'gd-user-uuid';
export const getUserUUID = () => {
const existingUserUUID = localStorage.getItem(localStorageKey);
if (existingUserUUID) return existingUserUUID;
const newUserUUID = generateUUID();
localStorage.setItem(localStorageKey, newUserUUID);
return newUserUUID;
};