Add program opening count to Keen.io analytics

This commit is contained in:
Florian Rival
2018-02-03 19:09:33 +01:00
parent 24afa155c8
commit c49af90a9c
2 changed files with 36 additions and 1 deletions

View File

@@ -3,6 +3,10 @@ import Keen from 'keen-tracking';
import Window from '../Window';
import { getUserUUID } from './UserUUID';
import Authentification from '../GDevelopServices/Authentification';
import {
getProgramOpeningCount,
incrementProgramOpeningCount,
} from './LocalStats';
const isDev = Window.isDev();
let client = null;
@@ -29,6 +33,9 @@ export const installAnalyticsEvents = (authentification: Authentification) => {
email: userProfile ? userProfile.email : undefined,
emailVerified: userProfile ? userProfile.emailVerified : undefined,
},
localStats: {
programOpeningCount: getProgramOpeningCount(),
},
page: {
title: document.title,
url: document.location.href,
@@ -91,6 +98,7 @@ export const installAnalyticsEvents = (authentification: Authentification) => {
export const sendProgramOpening = () => {
if (isDev || !client) return;
incrementProgramOpeningCount();
client.recordEvent('program_opening');
};
@@ -120,7 +128,11 @@ export const sendTutorialOpened = (tutorialName: string) => {
});
};
export const sendErrorMessage = (errorMessage: string, type: string, rawError: any) => {
export const sendErrorMessage = (
errorMessage: string,
type: string,
rawError: any
) => {
if (isDev || !client) return;
client.recordEvent('error_message', {

View File

@@ -0,0 +1,23 @@
// @flow
const localStoragePrefix = 'gd-local-stats';
export const getProgramOpeningCount = (): number => {
try {
const count = localStorage.getItem(`${localStoragePrefix}-program-opening`);
if (count !== null) return parseInt(count, 10);
} catch (e) {
console.warn('Unable to load stored program opening count', e);
}
return 0;
};
export const incrementProgramOpeningCount = () => {
const count = getProgramOpeningCount() + 1;
try {
localStorage.setItem(`${localStoragePrefix}-program-opening`, '' + count);
} catch (e) {
console.warn('Unable to store program opening count', e);
}
};