@@ -81,7 +81,7 @@ export class ClickstreamProvider implements AnalyticsProvider {
8181 this . eventRecorder = new EventRecorder ( this . context ) ;
8282 this . globalAttributes = { } ;
8383 this . setGlobalAttributes ( configuration . globalAttributes ) ;
84- this . userAttributes = StorageUtil . getUserAttributes ( ) ;
84+ this . userAttributes = StorageUtil . getSimpleUserAttributes ( ) ;
8585 this . sessionTracker = new SessionTracker ( this , this . context ) ;
8686 this . pageViewTracker = new PageViewTracker ( this , this . context ) ;
8787 this . clickTracker = new ClickTracker ( this , this . context ) ;
@@ -130,11 +130,14 @@ export class ClickstreamProvider implements AnalyticsProvider {
130130 this . recordEvent ( resultEvent , event . isImmediate ) ;
131131 }
132132
133- createEvent ( event : ClickstreamEvent ) {
133+ createEvent (
134+ event : ClickstreamEvent ,
135+ allUserAttributes : UserAttribute = null
136+ ) {
134137 return AnalyticsEventBuilder . createEvent (
135138 this . context ,
136139 event ,
137- this . userAttributes ,
140+ allUserAttributes === null ? this . userAttributes : allUserAttributes ,
138141 this . globalAttributes ,
139142 this . sessionTracker . session
140143 ) ;
@@ -155,40 +158,43 @@ export class ClickstreamProvider implements AnalyticsProvider {
155158 } else if ( userId !== previousUserId ) {
156159 const userInfo = StorageUtil . getUserInfoFromMapping ( userId ) ;
157160 const newUserAttribute : UserAttribute = { } ;
158- userInfo [ Event . ReservedAttribute . USER_ID ] = {
161+ newUserAttribute [ Event . ReservedAttribute . USER_ID ] = {
159162 value : userId ,
160163 set_timestamp : new Date ( ) . getTime ( ) ,
161164 } ;
162- Object . assign ( newUserAttribute , userInfo ) ;
165+ newUserAttribute [ Event . ReservedAttribute . USER_FIRST_TOUCH_TIMESTAMP ] =
166+ userInfo [ Event . ReservedAttribute . USER_FIRST_TOUCH_TIMESTAMP ] ;
167+ StorageUtil . updateUserAttributes ( newUserAttribute ) ;
163168 this . userAttributes = newUserAttribute ;
164169 this . context . userUniqueId = StorageUtil . getCurrentUserUniqueId ( ) ;
165- this . recordProfileSet ( ) ;
166170 }
171+ this . recordProfileSet ( this . userAttributes ) ;
167172 StorageUtil . updateUserAttributes ( this . userAttributes ) ;
168173 }
169174
170175 setUserAttributes ( attributes : ClickstreamAttribute ) {
171176 const timestamp = new Date ( ) . getTime ( ) ;
177+ const allUserAttributes = StorageUtil . getAllUserAttributes ( ) ;
172178 for ( const key in attributes ) {
173179 const value = attributes [ key ] ;
174180 if ( value === null ) {
175- delete this . userAttributes [ key ] ;
181+ delete allUserAttributes [ key ] ;
176182 } else {
177- const currentNumber = Object . keys ( this . userAttributes ) . length ;
183+ const currentNumber = Object . keys ( allUserAttributes ) . length ;
178184 const { checkUserAttribute } = EventChecker ;
179185 const result = checkUserAttribute ( currentNumber , key , value ) ;
180186 if ( result . error_code > 0 ) {
181187 this . recordClickstreamError ( result ) ;
182188 } else {
183- this . userAttributes [ key ] = {
189+ allUserAttributes [ key ] = {
184190 value : value ,
185191 set_timestamp : timestamp ,
186192 } ;
187193 }
188194 }
189195 }
190- StorageUtil . updateUserAttributes ( this . userAttributes ) ;
191- this . recordProfileSet ( ) ;
196+ StorageUtil . updateUserAttributes ( allUserAttributes ) ;
197+ this . recordProfileSet ( allUserAttributes ) ;
192198 }
193199
194200 setGlobalAttributes ( attributes : ClickstreamAttribute ) {
@@ -221,10 +227,11 @@ export class ClickstreamProvider implements AnalyticsProvider {
221227 this . recordEvent ( errorEvent ) ;
222228 }
223229
224- recordProfileSet ( ) {
225- const profileSetEvent = this . createEvent ( {
226- name : Event . PresetEvent . PROFILE_SET ,
227- } ) ;
230+ recordProfileSet ( allUserAttributes : UserAttribute ) {
231+ const profileSetEvent = this . createEvent (
232+ { name : Event . PresetEvent . PROFILE_SET } ,
233+ allUserAttributes
234+ ) ;
228235 this . recordEvent ( profileSetEvent ) ;
229236 }
230237
0 commit comments