11///<reference path="../.d.ts"/>
22"use strict" ;
3+ import { createGUID } from "../common/helpers" ;
34
45class AnalyticsSettingsService implements IAnalyticsSettingsService {
56 constructor ( private $userSettingsService : UserSettings . IUserSettingsService ,
6- private $staticConfig : IStaticConfig ) { }
7+ private $staticConfig : IStaticConfig ,
8+ private $logger : ILogger ) { }
79
810 public canDoRequest ( ) : IFuture < boolean > {
911 return ( ( ) => { return true ; } ) . future < boolean > ( ) ( ) ;
1012 }
1113
1214 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 > ( ) ( ) ;
1426 }
1527
1628 public getClientName ( ) : string {
@@ -20,5 +32,15 @@ class AnalyticsSettingsService implements IAnalyticsSettingsService {
2032 public getPrivacyPolicyLink ( ) : string {
2133 return "http://www.telerik.com/company/privacy-policy" ;
2234 }
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+ }
2345}
2446$injector . register ( "analyticsSettingsService" , AnalyticsSettingsService ) ;
0 commit comments