UNPKG

@moengage/web-sdk

Version:
643 lines (578 loc) 16.7 kB
/** * The configuration used while initializing the SDK. */ declare interface InitData { /** * @deprecated * Use appId instead. */ app_id: string; appId?: string; cluster: string; /** * @deprecated * Use env and logLevel instead. */ debug_logs?: number; env?: SDK_ENVIRONMENT; logLevel?: LOG_LEVEL; /** * @deprecated * Use projectId instead. */ project_id?: string; projectId?: string; /** * @deprecated * Use disableOnsite instead. */ disable_onsite?: boolean; disableOnsite?: boolean; enableSPA?: boolean; /** * Cards configuration for Web SDK Cards module */ cards?: CardsConfig; /** * @deprecated * Use disableWebPush instead. */ disable_web_push?: boolean; disableWebPush?: boolean; swPath?: string; swScope?: string; disableCookies?: boolean; useLatest?: boolean; sdkVersion?: string; disableSdk?: boolean; contentSecurityNonce?: string; customProxyDomain?: string; /** * @deprecated * Use botsList instead. */ bots_list?: string[]; botsList?: string[]; integrationType?: string; } /** * SDK Environment enum */ declare enum SDK_ENVIRONMENT { TEST = 'TEST', LIVE = 'LIVE', } /** * Log Level enum */ declare enum LOG_LEVEL { NONE = 0, LIMITED = 1, ALL = 2, } /** * Integration type enum */ declare enum INTEGRATION_TYPE { GTM = 'GTM', FLUTTER = 'Flutter', SEGMENT = 'Segment', AMP = 'AMP', NPM = 'NPM', CHROME_EXTENSION = 'Chrome extension', TV = 'TV', VTEX = 'VTEX', SHOPIFY = 'Shopify', MOENGAGE_ASSIST = 'MoEngage Assist plugin', DIRECT = 'Direct', } /** * Configuration for self-handled soft ask */ declare interface SelfHandledSoftAskConfig { softAsk: boolean; mainClass: string; allowClass: string; dismissClass: string; } /** * Cards configuration interface * Matches CardsConfigModel structure from the SDK */ declare interface CardsConfig { /** Enable Cards module */ enable: boolean; /** CSS selector for the placeholder element that opens the inbox */ placeholder?: string; /** Background color (any valid CSS color format) */ backgroundColor?: string; /** Overlay color (any valid CSS color format) */ overLayColor?: string; /** Font faces array for custom fonts */ fontFaces?: { family?: string; url?: string; }[]; /** Card dismiss configuration */ cardDismiss?: { enable?: boolean; color?: string; }; /** Option button color */ optionButtonColor?: string; /** Date/time text color */ dateTimeColor?: string; /** Unclicked card indicator color */ unclickedCardIndicatorColor?: string; /** Pin icon URL */ pinIcon?: string; /** Refresh icon URL */ refreshIcon?: string; /** Navigation bar configuration */ navigationBar?: { backgroundColor?: string; text?: string; color?: string; fontSize?: string; fontFamily?: string; }; /** Close button configuration */ closeButton?: { webIcon?: string; mWebIcon?: string; callBack?: () => void; }; /** Tab configuration */ tab?: { active?: { color?: string; underlineColor?: string; backgroundColor?: string; }; inactiveTabFontColor?: string; fontSize?: string; fontFamily?: string; backgroundColor?: string; }; /** Web floating icon configuration */ webFloating?: { enable?: boolean; icon?: string; postion?: string; countBackgroundColor?: string; countColor?: string; iconBackgroundColor?: string; fontFamily?: string; zIndex?: string; }; /** Mobile web floating icon configuration */ mWebFloating?: { enable?: boolean; icon?: string; postion?: string; countBackgroundColor?: string; countColor?: string; iconBackgroundColor?: string; fontFamily?: string; zIndex?: string; }; /** Card styling configuration */ card?: { headerFontSize?: string; descriptionFontSize?: string; ctaFontSize?: string; fontFamily?: string; horizontalRowColor?: string; }; /** Error page configuration */ errorContent?: { img?: string; text?: string; }; /** No data content configuration */ noDataContent?: { img?: string; text?: string; }; /** Callback function to open inbox */ openInbox?: () => void; /** Z-index for the cards container */ zIndex?: 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 trackEvent(eventName: string, eventAttrs: any): Promise<any>; /** * @deprecated Use trackEvent instead. */ 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; /** * Sets the log level for console output (PRIMARY METHOD). * @param level - Log level to set (0=none, 1=limited, 2=all) * @returns A Promise that resolves when the log level is set. */ declare function setLogLevel(level: number): Promise<void>; /** * 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. */ /** * @deprecated Use setLogLevel instead. This method is kept for backward compatibility. * Sets the log level for console output. * @param level - Log level to set (0=none, 1=limited, 2=all) * @returns A Promise that resolves when the log level is set. */ declare function setDebugLevel(level: number): Promise<void>; /** * @deprecated Use identifyUser instead. */ declare function add_unique_user_id(id: string | number): Promise<any>; /** * @deprecated Use identifyUser instead. */ 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; /** * Enables data tracking. * @returns A promise that resolves with `true` if `enableDataTracking` operation was successful. */ declare function enableDataTracking(): Promise<boolean>; /** * Disables data tracking. * @returns A promise that resolves with `true` if `disableDataTracking` operation was successful. */ declare function disableDataTracking(): Promise<boolean>; /** * @returns `true` if data tracking is enabled; `false` otherwise. */ declare function isDataTrackingEnabled(): 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 * @param {string} userAttributeLevel - The level at which the user attribute is to be fetched. This is valid only for portfolio of DBs. If not provided, the attribute will be fetched at the 'PROJECT' level by default. Refer to `Attribute.USER_ATTRIBUTE_LEVEL` for possible values. * @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, userAttributeLevel?: 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. * @param userAttributeLevel - The level at which the user attribute is to be set. This is valid only for portfolio of DBs. If not provided, the attribute will be set at the 'PROJECT' level by default. Refer to `Attribute.USER_ATTRIBUTE_LEVEL` for possible values. * @returns A Promise that resolves when the user attribute is added. */ declare function setUserAttribute( attrName: string, attrValue: any, userAttributeLevel?: string, ): Promise<any>; /** * @deprecated Use setUserAttribute instead. */ declare function add_user_attribute( attrName: string, attrValue: any, userAttributeLevel?: string, ): Promise<any>; /** * Namespace for user attribute. */ declare namespace Attribute { /** * Enumeration for user attribute levels. */ enum USER_ATTRIBUTE_LEVEL { PROJECT = 'PROJECT', PORTFOLIO = 'PORTFOLIO', } } /** * 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 setFirstName(firstName: string): Promise<any>; /** * @deprecated Use setFirstName instead. */ 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 setLastName(lastName: string): Promise<any>; /** * @deprecated Use setLastName instead. */ 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 setEmailId(email: string): Promise<any>; /** * @deprecated Use setEmailId instead. */ 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 setMobileNumber(mobile: string): Promise<any>; /** * @deprecated Use setMobileNumber instead. */ 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 setUserName(user_name: string): Promise<any>; /** * @deprecated Use setUserName instead. */ 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 setGender(gender: string): Promise<any>; /** * @deprecated Use setGender instead. */ 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 setBirthDate(dob: Date): Promise<any>; /** * @deprecated Use setBirthDate instead. */ 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 logoutUser(): Promise<any>; /** * @deprecated Use logoutUser instead. */ declare function destroy_session(): Promise<any>; /** * Starts the web push operations. * @param config - Configuration for self-handled soft ask (if opt-in type is two-step) * @note Self-handled web push must be configured from MoEngage dashboard in order to use this method. */ declare function callWebPush(config?: SelfHandledSoftAskConfig): void; /** * @deprecated Use callWebPush instead. */ 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 trackPageView(): Promise<any>; /** * @deprecated Use trackPageView instead. */ 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 handlePageChange(): void; /** * @deprecated Use handlePageChange instead. */ 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 onCardsLoaded(): Promise<any>; /** * @deprecated Use onCardsLoaded instead. */ 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, setLogLevel, setDebugLevel, add_unique_user_id, update_unique_user_id, identifyUser, getUserIdentities, enableSdk, disableSdk, isSdkEnabled, enableDataTracking, disableDataTracking, isDataTrackingEnabled, 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, Attribute, SDK_ENVIRONMENT as env, LOG_LEVEL as logLevel, setUserAttribute, setFirstName, setLastName, setEmailId, setMobileNumber, setUserName, setGender, setBirthDate, logoutUser, callWebPush, trackPageView, handlePageChange, onCardsLoaded, trackEvent, };