Methods
Our PLUG widget SDK is a powerful tool designed to further enhance our widget on your website or application. With our SDK, you can seamlessly integrate our feature-rich widget by empowering you to create a dynamic and personalized user experience. Let's get started.
Initialize the widget
Calling the init() method initializes the PLuG widget on your website. Initializing the PLuG widget is necessary for you to perform any other actions on the PLuG widget SDK.
1 useEffect(() => {2 window.plugSDK.init({3 app_id: <your_unique_app_id>,4 });5 }, []);
When React is using Strict mode, you might get a warning message from window.plugSDK.init() being called multiple times. These errors won't impact the installation and functioning of the widget.
Shutdown the widget
The shutdown() method is helpful when you want to end the user session which is currently initialized in the PLuG widget. You can use this method to clear your users' conversations and tickets when they log out of your application.
1 await window.plugSDK.shutdown();
After calling the shutdown() method, you can call the init() method to reinitialize PLuG widget on your website if you wish to showcase the PLuG widget again in the logged out version of your application.
Once the shutdown() method is called, all the other functionality in the widget such as session recording or Nudges will also be stopped. You need to reinitialize the widget again to have these features active.
Open or close the widget
To control whether the PLuG widget launcher screen is open, you can use the togglewidget() method with a boolean value. Your code needs to listen to the event ON_PLUG_WIDGET_READY to call this method. If the widget isn't ready then this method won’t make any action.
1 window.plugSDK.toggleWidget(true);
Take actions from events
This method can be used to listen to events coming from the PLuG widget. The following are the different PAYLOAD_TYPES.
1 useEffect(() => {2 window.plugSDK.onEvent((payload) => {3 if (payload.type === PAYLOAD_TYPE) {4 //Your logic goes here5 }6 });7 }, []);
Looking for something more? Reach out to us through our own PLuG widget in the bottom right of this screen and we would be happy to assist you.