@@ -3,6 +3,7 @@ import { CreateRequestFunction, MigrationState } from './types/internal'
3
3
import StorageManager from './StorageManager'
4
4
import Constants from './Constants'
5
5
import ArgsBuilder from './ArgsBuilder'
6
+ import shajs from 'sha.js'
6
7
7
8
type Region = 'eu1' | 'in1' | 'sg1' | 'us1' | 'sk1' ;
8
9
@@ -107,6 +108,11 @@ export default class MigrationManager {
107
108
108
109
const argsDict = args ?. buildDict ( ) || { }
109
110
111
+ const userId = argsDict [ Constants . PARAMS . USER_ID ]
112
+ if ( userId ) {
113
+ this . identity . setUserId ( userId )
114
+ }
115
+
110
116
switch ( action ) {
111
117
case Constants . METHODS . START :
112
118
if ( ! this . identity . isAnonymous ) {
@@ -143,7 +149,8 @@ export default class MigrationManager {
143
149
)
144
150
145
151
if ( userId ) {
146
- Object . assign ( attrs , { Identity : userId } )
152
+ this . identity . setUserId ( userId )
153
+ Object . assign ( attrs , this . identity . profile )
147
154
clevertap . onUserLogin . push ( { Site : attrs } )
148
155
} else {
149
156
clevertap . profile . push ( { Site : attrs } )
@@ -271,7 +278,9 @@ export class IdentityManager {
271
278
272
279
public get cleverTapID ( ) : string {
273
280
if ( this . userId !== this . anonymousLoginUserId && ! this . isAnonymous ) {
274
- return `${ this . deviceId } _${ this . userId } `
281
+ const sha = this . sha256 ( this . userId )
282
+
283
+ return `${ this . deviceId } _${ sha } `
275
284
}
276
285
277
286
return this . deviceId
@@ -284,4 +293,10 @@ export class IdentityManager {
284
293
public get isAnonymous ( ) : boolean {
285
294
return this . userId === this . deviceId
286
295
}
296
+
297
+ private sha256 ( s : string ) : string {
298
+ const sha = new shajs . sha256 ( ) . update ( s ) . digest ( 'hex' )
299
+
300
+ return sha . substring ( 0 , 10 )
301
+ }
287
302
}
0 commit comments