Events

Control the behavior of your Userback widget by triggering specific actions during load, open, close, or survey submission events. This allows for a more tailored user interaction.

📘

Before you start

The Userback widget must be installed on your website. See the Widget Installation Guide if you haven't done this yet.


Basic use cases

Execute actions when the widget loads

Userback.on_load = () => {
  console.log("Widget Loaded");
};

Execute actions when the widget opens

Userback.on_open = () => {
  console.log("Widget Opened");
};

Execute actions when the widget closes

Userback.on_close = () => {
  console.log("Widget Closed");
};

Execute actions when a survey is submitted

Userback.on_survey_submit = (surveyData) => {
  console.log("Survey Submitted", surveyData);
};

Advanced use cases

Manipulate the DOM when the widget loads

By combining on_load with DOM manipulation, you can create a more interactive experience. For instance, show a tooltip when the widget is loaded:

Userback.on_load = () => {
  let tooltip = document.createElement("span");
  tooltip.className = 'tooltip';
  tooltip.innerText = 'Userback is ready!';
  document.body.appendChild(tooltip);
};

Tracking user behavior with custom analytics

When the widget is opened or closed, you might want to track this behavior for analytics purposes.

Userback.on_open = () => {
  console.log("User opened the widget");
};

Userback.on_close = () => {
  console.log("User closed the widget");
};

Trigger another survey after a survey is submitted

You may want to chain surveys — for example, show a follow-up question set based on the user’s initial response. With on_survey_submit, you can trigger another survey programmatically:

Userback.on_survey_submit = (surveyData) => {
  console.log("Survey Submitted:", surveyData);

  Userback.openSurvey(NEXT_SURVEY_KEY);
};

Redirect after feedback submission

You might want to direct the user to another webpage after feedback is sent:

Userback.after_send = () => {
  window.location.href = 'https://www.yourdomain.com/thankyou';
};

Available event handlers

on_load, on_open, on_close, before_send, after_send, on_survey_submit


Need help? Visit the Help Center or use the chat bubble on this page to contact our support team.


Did this page help you?