Betting events The SPA offers an API that allows you to subscribe to various user-related events, such as user login, logout, and navigation to the 'Bets History' page, among others. Once subscribed to an event, you can implement custom logic to handle the event as needed.
EventType Interface Description redirect
interface RedirectPayload { destination: Destination; link: string; } enum Destination { Login = 'login', Logout = 'logout', } Called at the moment of performing the actions specified in Destination, it is necessary to be able to set the transition via external routes open-bets-history
{}
Called at the moment of opening the bet history handle-not-enough-balance
interface HandleNotEnoughBalancePayload { deposit: string; } Called when a player does not have enough funds to make a bet on-odd-format-change
interface OnOddFormatChangePayload { oddFormat: OddFormat; } Called when a player changes the odd format add-odd
interface AddOddPayload { id: string; } Called when a player adds an outcome to the betslip delete-odd
interface DeleteOddPayload { id: string; } Called when a player deletes an outcome from the betslip toggle-widget-betslip
interface ToggleWidgetBetslipPayload { isOpen: boolean; } Called when a player opens the betslip widget
Here are some examples of how to use the events:
redirect open-bets-history handle-not-enough-balance on-odd-format-change add-odd delete-odd toggle-widget-betslip
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15 bettingAPI . subscribe ( 'redirect' , ({ destination , link }) => {
switch ( destination ) {
// at the moment only two values are available for the 'destination'
case 'login' : {
window . location . href = '#!/auth/signin?popup' ;
}
case 'logout' : {
window . location . href = '#!/auth/signout' ;
}
// after handling login and logout events you should execute window.location.reload()
default : {
break ;
}
}
});
bettingAPI . subscribe ( 'open-bets-history' , () => {
fetch ( 'your-analytics-url' , { method : 'POST' });
});
bettingAPI . subscribe ( 'handle-not-enough-balance' , ({ deposit }) => {
console . error ( `Not enough balance, deposit: ${ deposit } ` );
});
bettingAPI . subscribe ( 'on-odd-format-change' , ({ id }) => {
console . log ( `Played changed odd format, ${ id } ` );
});
bettingAPI . subscribe ( 'add-odd' , ({ id }) => {
fetch ( 'your-analytics-url' , {
method : 'POST' ,
body : JSON . stringify ({ user : 'USERID' , type : 'ADDED' , outcomeID : id }),
});
});
bettingAPI . subscribe ( 'delete-odd' , ({ id }) => {
fetch ( 'your-analytics-url' , {
method : 'POST' ,
body : JSON . stringify ({ user : 'USERID' , type : 'DELETED' , outcomeID : id }),
});
});
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 bettingAPI . subscribe ( 'toggle-widget-betslip' , ( payload ) => {
const el = document . getElementById ( 'betting-betslip-mobile' );
if ( el && payload . isOpen ) {
el . style . setProperty ( 'top' , ' 0' );
el . style . setProperty ( 'bottom' , 'initial' );
el . style . setProperty ( 'height' , '100%' );
document . body . classList . add ( 'betting-fixed-body' );
}
if ( el && ! payload . isOpen ) {
el . style . setProperty ( 'top' , null );
el . style . setProperty ( 'bottom' , '0' );
el . style . setProperty ( 'height' , null );
document . body . classList . remove ( 'betting-fixed-body' );
}
});