Skip to content

Commit 38d5c5a

Browse files
authored
Merge pull request #321 from sillsdev/TT-4712
TT-4712 user and country analytics by year/month
2 parents 9e47693 + e8fe55a commit 38d5c5a

8 files changed

Lines changed: 89 additions & 0 deletions

File tree

migration/r4.4/analytics.sql

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
create table useranalytics (
2+
id serial not null primary key,
3+
userid int not null,
4+
year int not null,
5+
month int not null
6+
);
7+
create unique index ux_useranalytics on useranalytics(userid, year, month);
8+
grant all on useranalytics to transcriber;
9+
grant all on useranalytics_id_seq to transcriber;
10+
11+
12+
create table countryanalytics (
13+
id serial not null primary key,
14+
country text not null,
15+
year int not null,
16+
month int not null
17+
);
18+
create unique index ux_countryanalytics on countryanalytics(country, year, month);
19+
grant all on countryanalytics to transcriber;
20+
grant all on countryanalytics_id_seq to transcriber;

src/renderer/src/Sources.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ import { updateBackTranslationType } from './crud/updateBackTranslationType';
4242
import { updateConsultantWorkflowStep } from './crud/updateConsultantWorkflowStep';
4343
import { serializersSettings } from './serializers/serializersFor';
4444
import { requestedSchema } from './schema';
45+
import { logLoginAnalytics } from './crud/logLoginAnalytics';
4546
import { orbitReset } from './crud/orbitReset';
4647
type StategyError = (...args: unknown[]) => unknown;
4748

@@ -442,6 +443,7 @@ export const Sources = async (
442443
await forceDataChanges();
443444
console.log(`Forcing complete`);
444445
}
446+
logLoginAnalytics(tokenState.accessToken, errorReporter);
445447
}
446448
const user = localStorage.getItem(LocalKey.userId) as string;
447449
setUser(user);

src/renderer/src/crud/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ export * from './getOrgs';
66
export * from './groupmembership';
77
export * from './hasAnyRelated';
88
export * from './loadData';
9+
export * from './logLoginAnalytics';
910
export * from './media';
1011
export * from './offlineError';
1112
export * from './passage';
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import Bugsnag from '@bugsnag/js';
2+
import { axiosPost } from '../utils/axios';
3+
import { infoMsg, logError, Severity } from '../utils';
4+
5+
export async function logLoginAnalytics(
6+
token?: string | null,
7+
errorReporter?: typeof Bugsnag
8+
): Promise<void> {
9+
if (!token) return;
10+
try {
11+
await axiosPost('useranalytics/track', undefined, token);
12+
} catch (error) {
13+
logError(
14+
Severity.error,
15+
errorReporter,
16+
infoMsg(error as Error, 'logLoginAnalytics failed')
17+
);
18+
}
19+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import { InitializedRecord, UninitializedRecord } from '@orbit/records';
2+
3+
export interface CountryAnalytics extends UninitializedRecord {
4+
attributes: {
5+
country: string;
6+
year: number;
7+
month: number;
8+
};
9+
}
10+
11+
export type CountryAnalyticsD = CountryAnalytics & InitializedRecord;
12+
13+
export default CountryAnalytics;

src/renderer/src/model/index.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,5 +68,7 @@ export * from './organizationBible';
6868
export * from './paratextProject';
6969
export * from './intellectualProperty';
7070
export * from './vwchecksum';
71+
export * from './userAnalytics';
72+
export * from './countryAnalytics';
7173
export * from './IExecResult';
7274
export * from './SectionArray';
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import { InitializedRecord, UninitializedRecord } from '@orbit/records';
2+
3+
export interface UserAnalytics extends UninitializedRecord {
4+
attributes: {
5+
userId: number;
6+
year: number;
7+
month: number;
8+
};
9+
}
10+
11+
export type UserAnalyticsD = UserAnalytics & InitializedRecord;
12+
13+
export default UserAnalytics;

src/renderer/src/schema.tsx

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1035,6 +1035,25 @@ if (requestedSchema > 9 && schemaDefinition.models) {
10351035
};
10361036
schemaDefinition.version = 10;
10371037
}
1038+
if (requestedSchema > 10 && schemaDefinition.models) {
1039+
schemaDefinition.models.useranalytics = {
1040+
keys: { remoteId: {} },
1041+
attributes: {
1042+
userId: { type: 'number' },
1043+
year: { type: 'number' },
1044+
month: { type: 'number' },
1045+
},
1046+
};
1047+
schemaDefinition.models.countryanalytics = {
1048+
keys: { remoteId: {} },
1049+
attributes: {
1050+
country: { type: 'string' },
1051+
year: { type: 'number' },
1052+
month: { type: 'number' },
1053+
},
1054+
};
1055+
schemaDefinition.version = 11;
1056+
}
10381057

10391058
export const schema = new RecordSchema(schemaDefinition);
10401059

0 commit comments

Comments
 (0)