UNPKG

@moengage/web-sdk

Version:
393 lines (351 loc) 10.9 kB
/** * The configuration used while initializing the SDK. */ declare interface InitData { app_id: string; cluster: string; debug_logs?: number; disable_onsite?: boolean; enableSPA?: boolean; cards?: { enable: boolean; placeholder?: string; backgroundColor?: string; overLayColor?: string; fontFaces?: { family?: string; url?: string; }[]; cardDismiss?: { color?: string; enable?: boolean; }; optionButtonColor?: string; dateTimeColor?: string; unclickedCardIndicatorColor?: string; pinIcon?: string; refreshIcon?: string; navigationBar?: { backgroundColor?: string; text?: string; color?: string; fontSize?: string; fontFamily?: string; }; closeButton?: { webIcon?: string; mWebIcon?: string; }; tab?: { active?: { color?: string; underlineColor?: string; backgroundColor?: string; }; inactiveTabFontColor?: string; fontSize?: string; fontFamily?: string; backgroundColor?: string; }; webFloating?: { enable?: boolean; icon?: string; postion?: string; countBackgroundColor?: string; countColor?: string; iconBackgroundColor?: string; fontFamily?: string; }; mWebFloating?: { enable?: boolean; icon?: string; postion?: string; countBackgroundColor?: string; countColor?: string; iconBackgroundColor?: string; fontFamily?: string; }; card?: { headerFontSize?: string; descriptionFontSize?: string; ctaFontSize?: string; fontFamily?: string; horizontalRowColor?: string; }; noDataContent?: { img?: string; text?: string; }; }; disable_web_push?: boolean; swPath?: string; disableCookies?: boolean; useLatest?: boolean; sdkVersion?: string; disableSdk?: boolean; proxyDomains?: ProxyDomains; } /** * The proxies for the SDK's network requests */ declare interface ProxyDomains { api?: string; cdnScript?: string; cdnImage?: string; cdnApp?: string; } declare interface Identity { [identity: string]: string; } /** * Callback function for onsite module events */ declare interface OnsiteCallback { (data: any): void; } /** * Data structure for self-handled onsite interactions */ declare interface OnsiteInteractionData { campaignId: string; campaignName: string; context: any; } /** * Initializes the SDK. * @param initData - configuration for SDK intialization. */ declare function initialize(initData: InitData): void; /** * Indicates if the SDK has been loaded in the DOM and is available for use. * @returns `true` if the SDK has been successfully loaded; `false` otherwise. */ declare function isMoeLoaded(): boolean; /** * Tracks an event with the given name and attributes. * @param eventName - The name of the event to track. * @param eventAttrs - The attributes associated with the event. * @returns A Promise that resolves when the event tracking is completed. */ declare function track_event(eventName: string, eventAttrs: any): Promise<any>; /** * Provides the current-build version. * @returns The current version of the SDK in use. */ declare function getSdkVersion(): string; /** * Explicitly set new debug level. To be used to see log messages in live environment too. * @note This does not append '_DEBUG' to the workspace ID. * @param level Debug level to set. */ declare function setDebugLevel(level: number): Promise<void>; /** * Sets an identifier for the user. * @param id - The identifier associated to the user. * @returns A Promise that resolves when setting of the identifier is complete. */ declare function add_unique_user_id(id: string | number): Promise<any>; /** * Updates the identifier of the user whose identifier is already set. * @param id - The identifier associated to the user. * @returns A Promise that resolves when the identifier is updated. */ declare function update_unique_user_id(id: string | number): Promise<any>; /** * Adds/updates the identities of the user. * @param identity - The identities associated to the user. * @returns A promise that resolves when setting of the identities is complete. */ declare function identifyUser(identity: Identity): Promise<any>; /** * Adds/updates the UID of the user. * @param identity - The UID associated to the user. * @returns A promise that resolves when setting of the UID is complete. */ declare function identifyUser(identity: string): Promise<any>; /** * Provides the current identities associated to the user. * @returns the current identities of the user or null, if no identities have been set. */ declare function getUserIdentities(): Identity | null; /** * Enables the Web SDK. * @returns A promise that resolves with `true` if `enableSdk` operation was successful. */ declare function enableSdk(): Promise<boolean>; /** * Disables the Web SDK. * @returns A promise that resolves with `true` if `disableSdk` operation was successful. */ declare function disableSdk(): Promise<boolean>; /** * @returns `true` if Web SDK is enabled; `false` otherwise. */ declare function isSdkEnabled(): boolean; /* Provides the unique user id if present. * @return {*} {string} returns the unique user id if present else returns empty string */ declare function getUserId(): string; /** * Provides the value of the attribute passed as parameter * @param {string} attribute * @return {*} returns the value of the attribute passed as parameter * if the attribute is not present, it returns empty string */ declare function getUserAttribute(attribute: string): any; /** * Adds a user attribute with the given name and value. * @param attrName - The name of the user attribute. * @param attrValue - The value of the user attribute. * @returns A Promise that resolves when the user attribute is added. */ declare function add_user_attribute( attrName: string, attrValue: any, ): Promise<any>; /** * Sets the first name of the user. * @param firstName - the first name of the user. * @returns A Promise that resolves when the first name is set. */ declare function add_first_name(firstName: string): Promise<any>; /** * Sets the last name of the user. * @param lastName - the last name of the user. * @returns A Promise that resolves when the last name is set. */ declare function add_last_name(lastName: string): Promise<any>; /** * Sets the email of the user. * @param email - the email of the user. * @returns A Promise that resolves when the email is set. */ declare function add_email(email: string): Promise<any>; /** * Sets the mobile number of the user. * @param mobile - the mobile number of the user. * @returns A Promise that resolves when the mobile number is set. */ declare function add_mobile(mobile: string): Promise<any>; /** * Sets the name of the user. * @param user_name - the name of the user. * @returns A Promise that resolves when the name is set. */ declare function add_user_name(user_name: string): Promise<any>; /** * Sets the gender of the user. * @param gender - the gender of the user. * @returns A Promise that resolves when the gender is set. */ declare function add_gender(gender: string): Promise<any>; /** * Sets the birthday of the user. * @param dob - the birthday of the user. * @returns A Promise that resolves when the birthday is set. */ declare function add_birthday(dob: Date): Promise<any>; /** * Logs out the current user. * @returns A Promise that resolves when the user is logged out. */ declare function destroy_session(): Promise<any>; /** * Starts the web push operations. * @note Self-handled web push must be configured from MoEngage dashboard in order to use this method. */ declare function call_web_push(config?: any): void; /** * Tracks events related to page-view. * @returns A Promise that resolves when tracking of page-view events is completed. */ declare function track_page_view(): Promise<any>; /** * Enforces the functionaly of page-change. * Tracks page-view events and resets all the SDK modules. */ declare function handle_page_change(): void; /** * Emits an event on the window object when the cards module has been successfully initialized. * Use this method at the beginning of your code. Start using the cards module after the Promise resolves. * @note Refer this guide on how to use the cards module: https://developers.moengage.com/hc/en-us/articles/9526886582292-Cards * @returns A Promise that resolves when the cards module is successfully initialized. */ declare function on_cards_loaded(): Promise<any>; /** * Contains the properties and methods of the cards module. * @note Refer this guide on how to use the cards module: https://developers.moengage.com/hc/en-us/articles/9526886582292-Cards */ declare const cards: any; /** * Contains the properties and methods of the onsite module for in-app messaging. */ declare const onsite: { /** * Retrieves web personalisation V1 campaign data. * @returns The onsite data if SDK is loaded and available; otherwise false. */ getData(): Promise<any>; /** * Registers a callback function for web personalisation V1. * @param callback - The callback function to register. * @returns Promise. */ registerCallback(callback: OnsiteCallback): Promise<any>; /** * Gets self-handled onsite messaging data. * @param callback - The callback function to handle the onsite messaging data. * @returns */ getSelfHandledOSM(callback: OnsiteCallback): any; /** * Tracks when a self-handled onsite message is shown. * @param data - The data associated with the shown onsite message. * @returns Promise<any>. */ selfHandledShown(data: OnsiteInteractionData): Promise<any>; /** * Tracks when a self-handled onsite message is clicked. * @param data - The data associated with the clicked onsite message. * @returns Promise<any>. */ selfHandledClicked(data: OnsiteInteractionData): Promise<any>; /** * Tracks when a self-handled onsite message is dismissed. * @param data - The data associated with the dismissed onsite message. * @returns Promise<any>. */ selfHandledDismissed(data: OnsiteInteractionData): Promise<any>; }; export { initialize, isMoeLoaded, track_event, getSdkVersion, setDebugLevel, add_unique_user_id, update_unique_user_id, identifyUser, getUserIdentities, enableSdk, disableSdk, isSdkEnabled, getUserId, getUserAttribute, add_user_attribute, add_first_name, add_last_name, add_email, add_mobile, add_user_name, add_gender, add_birthday, destroy_session, call_web_push, track_page_view, handle_page_change, on_cards_loaded, cards, onsite, InitData, };