Events API
The widget exposes a JavaScript API that lets you control it and react to user actions directly from your site’s code.
How it works
Section titled “How it works”Before the widget loads, window.Pliic is an array. You push commands onto it with push(). Once the widget finishes loading, the array is replaced by an object with its own push() method, and all queued commands are executed in order.
This pattern ensures you can register events even before the script finishes loading.
<script> window.Pliic = window.Pliic || []; window.Pliic.push(['on', 'suggestion:created', function(data) { console.log('New suggestion:', data.title); }]);</script>Available commands
Section titled “Available commands”Open the panel
Section titled “Open the panel”window.Pliic.push(['open']);Close the panel
Section titled “Close the panel”window.Pliic.push(['close']);Switch the active tab
Section titled “Switch the active tab”window.Pliic.push(['setTab', 'suggestions']);window.Pliic.push(['setTab', 'support']);Subscribe to an event
Section titled “Subscribe to an event”window.Pliic.push(['on', 'widget:open', function() { console.log('Widget opened');}]);Events
Section titled “Events”| Event | Payload | Description |
|---|---|---|
widget:open | — | The widget panel was opened. |
widget:close | — | The widget panel was closed. |
widget:tab-change | { tab: string } | The active tab changed. |
suggestion:created | { id: number, title: string } | A new suggestion was submitted. |
ticket:created | { id: number, ticket_number: string } | A new ticket was submitted. |
Full example
Section titled “Full example”<script> window.Pliic = window.Pliic || [];
window.Pliic.push(['on', 'widget:open', function() { console.log('The user opened the widget'); }]);
window.Pliic.push(['on', 'widget:tab-change', function(data) { console.log('Active tab:', data.tab); }]);
window.Pliic.push(['on', 'suggestion:created', function(data) { console.log('Suggestion #' + data.id + ': ' + data.title); }]);
window.Pliic.push(['on', 'ticket:created', function(data) { console.log('Ticket created:', data.ticket_number); }]);</script>
<script src="https://pliic.com/widget/v1.js" data-app-key="YOUR_APP_KEY" async defer></script>Next steps
Section titled “Next steps”- User authentication — identify logged-in users
- Troubleshooting — when something doesn’t work