mirror of
https://github.com/4ian/GDevelop.git
synced 2025-10-15 10:19:04 +00:00
Add an anonymous UUID to users in analytics to help understanding user behaviors in newIDE
This commit is contained in:
@@ -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,
|
||||
|
18
newIDE/app/src/Utils/Analytics/UserUUID.js
Normal file
18
newIDE/app/src/Utils/Analytics/UserUUID.js
Normal 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;
|
||||
};
|
Reference in New Issue
Block a user