1
1
///<reference path="../.d.ts"/>
2
2
"use strict" ;
3
+ import { createGUID } from "../common/helpers" ;
3
4
4
5
class AnalyticsSettingsService implements IAnalyticsSettingsService {
5
6
constructor ( private $userSettingsService : UserSettings . IUserSettingsService ,
6
- private $staticConfig : IStaticConfig ) { }
7
+ private $staticConfig : IStaticConfig ,
8
+ private $logger : ILogger ) { }
7
9
8
10
public canDoRequest ( ) : IFuture < boolean > {
9
11
return ( ( ) => { return true ; } ) . future < boolean > ( ) ( ) ;
10
12
}
11
13
12
14
public getUserId ( ) : IFuture < string > {
13
- return this . $userSettingsService . getSettingValue < string > ( this . $staticConfig . ANALYTICS_INSTALLATION_ID_SETTING_NAME ) ;
15
+ return ( ( ) => {
16
+ let currentUserId = this . $userSettingsService . getSettingValue < string > ( "USER_ID" ) . wait ( ) ;
17
+ if ( ! currentUserId ) {
18
+ currentUserId = createGUID ( false ) ;
19
+
20
+ this . $logger . trace ( `Setting new USER_ID: ${ currentUserId } .` ) ;
21
+ this . $userSettingsService . saveSetting < string > ( "USER_ID" , currentUserId ) . wait ( ) ;
22
+ }
23
+
24
+ return currentUserId ;
25
+ } ) . future < string > ( ) ( ) ;
14
26
}
15
27
16
28
public getClientName ( ) : string {
@@ -20,5 +32,15 @@ class AnalyticsSettingsService implements IAnalyticsSettingsService {
20
32
public getPrivacyPolicyLink ( ) : string {
21
33
return "http://www.telerik.com/company/privacy-policy" ;
22
34
}
35
+
36
+ public getUserSessionsCount ( ) : IFuture < number > {
37
+ return ( ( ) => {
38
+ return this . $userSettingsService . getSettingValue < number > ( "SESSIONS_STARTED" ) . wait ( ) || 0 ;
39
+ } ) . future < number > ( ) ( ) ;
40
+ }
41
+
42
+ public setUserSessionsCount ( count : number ) : IFuture < void > {
43
+ return this . $userSettingsService . saveSetting < number > ( "SESSIONS_STARTED" , count ) ;
44
+ }
23
45
}
24
46
$injector . register ( "analyticsSettingsService" , AnalyticsSettingsService ) ;
0 commit comments