@@ -23,6 +23,7 @@ import { OdpEvent } from './odp_event';
23
23
import { OdpConfig } from './odp_config' ;
24
24
import { IOdpEventApiManager } from './odp_event_api_manager' ;
25
25
import { invalidOdpDataFound } from './odp_utils' ;
26
+ import { IUserAgentParser } from './user_agent_parser' ;
26
27
27
28
const MAX_RETRIES = 3 ;
28
29
@@ -123,6 +124,19 @@ export abstract class OdpEventManager implements IOdpEventManager {
123
124
*/
124
125
private readonly clientVersion : string ;
125
126
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
+
126
140
constructor ( {
127
141
odpConfig,
128
142
apiManager,
@@ -132,6 +146,7 @@ export abstract class OdpEventManager implements IOdpEventManager {
132
146
queueSize,
133
147
batchSize,
134
148
flushInterval,
149
+ userAgentParser,
135
150
} : {
136
151
odpConfig : OdpConfig ;
137
152
apiManager : IOdpEventApiManager ;
@@ -141,6 +156,7 @@ export abstract class OdpEventManager implements IOdpEventManager {
141
156
queueSize ?: number ;
142
157
batchSize ?: number ;
143
158
flushInterval ?: number ;
159
+ userAgentParser ?: IUserAgentParser ;
144
160
} ) {
145
161
this . odpConfig = odpConfig ;
146
162
this . apiManager = apiManager ;
@@ -149,6 +165,22 @@ export abstract class OdpEventManager implements IOdpEventManager {
149
165
this . clientVersion = clientVersion ;
150
166
this . initParams ( batchSize , queueSize , flushInterval ) ;
151
167
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
+ }
152
184
153
185
this . apiManager . updateSettings ( odpConfig ) ;
154
186
}
@@ -408,7 +440,8 @@ export abstract class OdpEventManager implements IOdpEventManager {
408
440
* @private
409
441
*/
410
442
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
+
412
445
data . set ( 'idempotence_id' , uuid ( ) ) ;
413
446
data . set ( 'data_source_type' , 'sdk' ) ;
414
447
data . set ( 'data_source' , this . clientEngine ) ;
0 commit comments