JavaScript SDK
Corowd JavaScript SDK Documentation
The Corowd JavaScript SDK provides methods to interact with the in-web widget. More details about widget installation here.
Options
Events
Configure event handlers for different events that occur during the use of the widget. These events can be configured using a configuration object.
hideButton: Boolean
Hide button by default when script is loaded.
Example:
Corowd.hideButton = true;
onLoaded
: Function
This key should contain a function that is triggered when the widget configuration is loaded.
Example:
Corowd.onLoaded = () => {
console.log('Widget configuration loaded.');
}
beforeLoad
: Function
This key should contain a function that is triggered when the widget script is loaded.
Example:
Corowd.beforeLoad = () => {
console.log('Widget script loaded.');
}
onOpen
: Function
This key should contain a function that is triggered when the widget is opened.
Example:
Corowd.onOpen = () => {
console.log('Widget opened.');
}
onClose
: Function
This key should contain a function that is triggered when the widget is closed.
Example:
Corowd.onClose = () => {
console.log('Widget closed.');
}
onFeedbackSent
: Function
This key should contain a function that is triggered when feedback is sent through the widget.
Example:
Corowd.onFeedbackSent = () => {
console.log('Feedback sent.');
}
onReviewSent
: Function
This key should contain a function that is triggered when a review is sent through the widget.
Example:
Corowd.onReviewSent = () => {
console.log('Review sent.');
}
onViewChange
: Function
This key should contain a function that is triggered when the view of the widget is changed.
Example:
Corowd.onViewChange = (view) => {
console.log(`View changed to ${view}`);
}
Note that all of these keys are optional, and you can include only the keys that you need in your configuration object. Additionally, the functions can be defined with parameters to receive event data, depending on the event.
Methods
Open widget
This method opens the widget, displaying it to the user. If the widget is already open, calling this method has no effect.
Corowd.open()
Close widget
This method closes the widget, hiding it from the user. If the widget is already closed, calling this method has no effect.
Corowd.close()
Hide widget button
This method hides the default widget button. This can be useful if you want to create your own button to trigger the widget. To show the widget, you can add an event to your button that calls the Corowd.open()
method.
Corowd.hideButton()
Show widget button
This method shows the widget button. If you have previously called Corowd.hideButton()
, you can use this method to show the button again.
Corowd.showButton()
Control widget view mode
This method sets the view of the widget to the specified type. The method can be used only when the widget is opened. The available types are:
main-menu
: Displays the main menu, which allows the user to access different features of the widget.report-form
: Displays a form for the user to report an issue or problem.review-form
: Displays a form for the user to submit a review or feedback.
Corowd.setView(type)
Push message
This method pushes a custom message to the widget. This method can be used to provide helpful tips or information to the user.
message
parameter should be a string that represents the message to be displayedtime
parameter should be a number that represents the time value for the message
Corowd.pushMessage(message, time)
User identification
Corowd.identify(user)
This method identifies the user of your project to synchronize data between platforms. The user
parameter should be an object that contains the following properties:
id
: The user ID of the current user. This should be unique for each user.email
: The email address of the current user. This should be a valid email address.meta
: Additional data about the current user. This can be any JSON object. Maximum size of object characters is 500.
Calling this method allows the widget to associate the current user with their data across platforms.