11import { OdpEvent } from '../../../core/odp/odp_event' ;
22import { OdpEventApiManager } from '../../../core/odp/odp_event_api_manager' ;
33import { LogLevel } from '../../../modules/logging' ;
4- import { ODP_EVENT_BROWSER_ENDPOINT } from '../../../utils/enums' ;
54import { ODP_CONFIG_NOT_READY_MESSAGE } from '../../../core/odp/odp_event_api_manager' ;
65
76const EVENT_SENDING_FAILURE_MESSAGE = 'ODP event send failed' ;
87
8+ const pixelApiPath = 'v2/zaius.gif' ;
9+
910export class BrowserOdpEventApiManager extends OdpEventApiManager {
1011 protected shouldSendEvents ( events : OdpEvent [ ] ) : boolean {
1112 if ( events . length <= 1 ) {
@@ -15,6 +16,15 @@ export class BrowserOdpEventApiManager extends OdpEventApiManager {
1516 return false ;
1617 }
1718
19+ private getPixelApiEndpoint ( ) : string {
20+ if ( ! this . odpConfig ?. isReady ( ) ) {
21+ throw new Error ( ODP_CONFIG_NOT_READY_MESSAGE ) ;
22+ }
23+ const apiHost = this . odpConfig . apiHost ;
24+ const pixelApiEndpoint = new URL ( pixelApiPath , apiHost . replace ( 'api' , 'jumbe' ) ) . href ;
25+ return pixelApiEndpoint ;
26+ }
27+
1828 protected generateRequestData (
1929 events : OdpEvent [ ]
2030 ) : { method : string ; endpoint : string ; headers : { [ key : string ] : string } ; data : string } {
@@ -23,11 +33,17 @@ export class BrowserOdpEventApiManager extends OdpEventApiManager {
2333 this . getLogger ( ) . log ( LogLevel . ERROR , ODP_CONFIG_NOT_READY_MESSAGE ) ;
2434 throw new Error ( ODP_CONFIG_NOT_READY_MESSAGE ) ;
2535 }
36+
37+ // this cannot be cached cause OdpConfig is mutable
38+ // and can be updated in place and it is done so in odp
39+ // manager. We should make OdpConfig immutable and
40+ // refacator later
41+ const pixelApiEndpoint = this . getPixelApiEndpoint ( ) ;
2642
2743 const apiKey = this . odpConfig . apiKey ;
2844 const method = 'GET' ;
2945 const event = events [ 0 ] ;
30- const url = new URL ( ODP_EVENT_BROWSER_ENDPOINT ) ;
46+ const url = new URL ( pixelApiEndpoint ) ;
3147 event . identifiers . forEach ( ( v , k ) => {
3248 url . searchParams . append ( k , v ) ;
3349 } ) ;
0 commit comments