@@ -23,6 +23,7 @@ import { OdpEvent } from './odp_event';
2323import { OdpConfig } from './odp_config' ;
2424import { IOdpEventApiManager } from './odp_event_api_manager' ;
2525import { invalidOdpDataFound } from './odp_utils' ;
26+ import { IUserAgentParser } from './user_agent_parser' ;
2627
2728const MAX_RETRIES = 3 ;
2829
@@ -123,6 +124,19 @@ export abstract class OdpEventManager implements IOdpEventManager {
123124 */
124125 private readonly clientVersion : string ;
125126
127+ /**
128+ * Version of the client being used
129+ * @private
130+ */
131+ private readonly userAgentParser ?: IUserAgentParser ;
132+
133+
134+ /**
135+ * Information about the user agent
136+ * @private
137+ */
138+ private readonly userAgentData ?: Map < string , unknown > ;
139+
126140 constructor ( {
127141 odpConfig,
128142 apiManager,
@@ -132,6 +146,7 @@ export abstract class OdpEventManager implements IOdpEventManager {
132146 queueSize,
133147 batchSize,
134148 flushInterval,
149+ userAgentParser,
135150 } : {
136151 odpConfig : OdpConfig ;
137152 apiManager : IOdpEventApiManager ;
@@ -141,6 +156,7 @@ export abstract class OdpEventManager implements IOdpEventManager {
141156 queueSize ?: number ;
142157 batchSize ?: number ;
143158 flushInterval ?: number ;
159+ userAgentParser ?: IUserAgentParser ;
144160 } ) {
145161 this . odpConfig = odpConfig ;
146162 this . apiManager = apiManager ;
@@ -149,6 +165,22 @@ export abstract class OdpEventManager implements IOdpEventManager {
149165 this . clientVersion = clientVersion ;
150166 this . initParams ( batchSize , queueSize , flushInterval ) ;
151167 this . state = STATE . STOPPED ;
168+ this . userAgentParser = userAgentParser ;
169+
170+ if ( userAgentParser ) {
171+ const { os, device } = userAgentParser . parseUserAgentInfo ( ) ;
172+
173+ const userAgentInfo : Record < string , unknown > = {
174+ 'os' : os . name ,
175+ 'os_version' : os . version ,
176+ 'device_type' : device . type ,
177+ 'model' : device . model ,
178+ } ;
179+
180+ this . userAgentData = new Map < string , unknown > (
181+ Object . entries ( userAgentInfo ) . filter ( ( [ key , value ] ) => value != null && value != undefined )
182+ ) ;
183+ }
152184
153185 this . apiManager . updateSettings ( odpConfig ) ;
154186 }
@@ -408,7 +440,8 @@ export abstract class OdpEventManager implements IOdpEventManager {
408440 * @private
409441 */
410442 private augmentCommonData ( sourceData : Map < string , unknown > ) : Map < string , unknown > {
411- const data = new Map < string , unknown > ( ) ;
443+ const data = new Map < string , unknown > ( this . userAgentData ) ;
444+
412445 data . set ( 'idempotence_id' , uuid ( ) ) ;
413446 data . set ( 'data_source_type' , 'sdk' ) ;
414447 data . set ( 'data_source' , this . clientEngine ) ;
0 commit comments