To get the widget to appear on your web page simply copy and paste the snippet below before the <body/>
tag on every page where you want the widget to appear for website visitors.
N.B: Your APP_ID
and PUBLIC_KEY
are auto-generated after a website live chat channel is created on the Simpu Inbox dashboard
- <script src="<https://static.simpu.co/widgets/v1/simpu-widget.js"></script>
- <script>
- var widget = window.Simpu.default.init({
- app_id: APP_ID,
- public_key: PUBLIC_KEY
- });
- widget.render();
- </script>
The widget can be configured with extra information about users, such as:
name: string
email: string
user_id: string|number
You can get this information from your application and this is used to differentiate between visitors to your application and users of your website.
- <script src="<https://static.simpu.co/widgets/v1/simpu-widget.js"></script>
- <script>
- var user_email = "user@example.com";
- var user_name = "Jean Doe";
- var user_id = 19;
- var widget = window.Simpu.default.init({
- app_id: APP_ID,
- public_key: PUBLIC_KEY,
- name: user_name,
- email: user_email,
- user_id: user_id,
- });
- widget.render();
- </script>
Hide the default launcher when triggering the widget programmatically with the widget methods.
- <script src="<https://static.simpu.co/widgets/v1/simpu-widget.js"></script>
- <script>
- var widget = window.Simpu.default.init({
- app_id: APP_ID,
- public_key: PUBLIC_KEY,
- hide_launcher: true,
- });
- widget.render();
- </script>
hide_launcher
is set to false by default and this will forcefully show the launcher icon.
The following methods allow you to interact with the widget.
This method renders the widget with the default launcher. The widget can be rendered on a page without the default launcher by setting the hide_launcher
config value as false
when initiating the widget.
- var widget = window.Simpu.default.init({
- app_id: APP_ID,
- public_key: PUBLIC_KEY,
- });
- widget.render();
This method opens the widget panel.
- var widget = window.Simpu.default.init({
- app_id: APP_ID,
- public_key: PUBLIC_KEY,
- });
- widget.open();
You can also pass an optional callback function to the open
function to carryout an action after the widget is opened.
- widget.open(() => console.log("open"));
This method closes the widget panel if it is open. It will not hide the widget launcher.
- var widget = window.Simpu.default.init({
- app_id: APP_ID,
- public_key: PUBLIC_KEY,
- });
- widget.close();
You can also pass an optional callback function to the close
function to carryout an action after the widget is closed.
- widget.close(() => console.log("close"));
Remove the close button from the widget interface.
- var widget = window.Simpu.default.init({
- app_id: APP_ID,
- public_key: PUBLIC_KEY,
- hide_close_button: true,
- });
- widget.close();
This example shows open and close the widget programmatically with a button on your web page.
- <body>
- <p>Hi.</p>
- <button id="open">open</button>
- <button id="close">close</button>
- <script src="https://static.simpu.co/widgets/v1/simpu-widget.js"></script> <script>
- var widget = window.Simpu.default.init({
- app_id: APP_ID,
- public_key: PUBLIC_KEY,
- hide_launcher: false,
- });
- widget.render();
- document.querySelector("#open").addEventListener("click", () => { widget.open();
- });
- document.querySelector("#close").addEventListener("click", () => { widget.close();
- });
- </script>
- </body>