@bookingbooster/bbtm
v0.2.13
Published
The **BBTM** library is used to track reservations conversion for any accommodation facility that uses the Booking Booster app.
Downloads
102
Readme
BBTM
The BBTM library is used to track reservations conversion for any accommodation facility that uses the Booking Booster app.
Table of Contents
Installation
Install the library using npm:
npm install @bookingbooster/bbtm
Usage
Import the Library Import and initialize BBTM in your JavaScript/
import BBTM from '@bookingbooster/bbtm';
const bbtm = new BBTM();
// Initialize with URL parameters
bbtm.init();
// Get the current session token
const token = bbtm.getSessionToken();
// Use the token to restore session if needed
// E.g. when the booking page changes, use the token retrieved via getSessionToken() in a previous page where init() has been called
bbtm.setSessionToken(token);
// Confirm a successful reservation
bbtm.sendConversion().then(() => {
console.log('Reservation conversion successfully sent to the BBTM.');
});
Api Reference
class BBTM Constructor Creates an instance of BBTM. Throws an error if used in a non-browser environment.
init(options?: BBTMOptions): void
Initializes the session using the URL parameters bbclk, bbacc, and bbsrc. If those paramethers are in the URL they will have priority over the optional provided storage
Parameters:
interface BBTMOptions {
storage?: BBTMStorage;
}
getSessionToken(): string | null
Retrieves the current session token. This token should be saved and reused to maintain a session across different steps of the reservation process.
Returns: A string containing the session token, or null if any required values are missing.
setSessionToken(newToken: string): void
Restores the session token. Use the token obtained from getSessionToken to set the session across different components of your application.
Parameters: newToken (string): The token string to restore.
sendConversion(): Promise<boolean>
Confirms the completion of a reservation process. This should be called at the final step of a successful booking.
Returns: Promise indicating the success of the operation.
BBTM Local Storage The BBTM class utilizes a session storage system to handle reservation data. You have the option to use the default storage system (localStorage) or implement your own custom storage solution.
Default Storage: BBTMLocalStorage The library includes a BBTMLocalStorage class that implements the BBTMStorage interface. This class handles storing and retrieving the session data in localStorage.
Example with provided storage
const bbtm = new BBTM();
bbtm.init({ storage: new BBTMLocalStorage() });
Custom Storage If you prefer to use a different storage mechanism (e.g., sessionStorage, a custom database, or an API), you can create your own storage class by implementing the BBTMStorage interface.
BBTMStorage Interface The interface you need to implement custom storage solutions:
export interface BBTMStorage {
set(session: BBTMSession): void | Promise<void>;
get(): BBTMSession | Promise<BBTMSession> | undefined | Promise<undefined>;
}