@@ -3,6 +3,7 @@ import { CreateRequestFunction, MigrationState } from './types/internal'
33import StorageManager from './StorageManager'
44import Constants from './Constants'
55import ArgsBuilder from './ArgsBuilder'
6+ import shajs from 'sha.js'
67
78type Region = 'eu1' | 'in1' | 'sg1' | 'us1' | 'sk1' ;
89
@@ -107,6 +108,11 @@ export default class MigrationManager {
107108
108109 const argsDict = args ?. buildDict ( ) || { }
109110
111+ const userId = argsDict [ Constants . PARAMS . USER_ID ]
112+ if ( userId ) {
113+ this . identity . setUserId ( userId )
114+ }
115+
110116 switch ( action ) {
111117 case Constants . METHODS . START :
112118 if ( ! this . identity . isAnonymous ) {
@@ -143,7 +149,8 @@ export default class MigrationManager {
143149 )
144150
145151 if ( userId ) {
146- Object . assign ( attrs , { Identity : userId } )
152+ this . identity . setUserId ( userId )
153+ Object . assign ( attrs , this . identity . profile )
147154 clevertap . onUserLogin . push ( { Site : attrs } )
148155 } else {
149156 clevertap . profile . push ( { Site : attrs } )
@@ -271,7 +278,9 @@ export class IdentityManager {
271278
272279 public get cleverTapID ( ) : string {
273280 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 } `
275284 }
276285
277286 return this . deviceId
@@ -284,4 +293,10 @@ export class IdentityManager {
284293 public get isAnonymous ( ) : boolean {
285294 return this . userId === this . deviceId
286295 }
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+ }
287302}
0 commit comments