API Methods

All available methods for controlling the FeedbackJar widget.

init

Initialize the widget with your widget ID.

window.fj.init(widgetId, options);

Parameters:

  • widgetId (string, required) - Your widget ID
  • options (object, optional) - Configuration options

See Initialization for details.


identify

Associate feedback with a specific user.

window.fj.identify({
  id: 'user_123',
  email: 'user@example.com',
  firstName: 'John',
  lastName: 'Doe',
  avatar: 'https://example.com/avatar.jpg'
});

Parameters:

  • id (string, optional) - Unique user identifier
  • email (string, optional) - User email address
  • firstName (string, optional) - User first name
  • lastName (string, optional) - User last name
  • avatar (string, optional) - URL to user avatar image

All fields are optional but providing them helps you track who sent feedback.


showWidget

Programmatically open the feedback panel.

window.fj.showWidget();

With options:

window.fj.showWidget({
  message: 'Tell us what you think!'
});

Parameters:

  • message (string, optional) - Pre-fill the feedback textarea

hideWidget

Close the feedback panel.

window.fj.hideWidget();

getWidgetState

Get current widget state.

const state = await window.fj.getWidgetState();
console.log(state);

Returns:

{
  isOpen: boolean,
  section: string
}

setWidgetPosition

Change widget position.

window.fj.setWidgetPosition('left');

Parameters:

  • position ('left' | 'right') - New position

setTheme

Change widget theme.

window.fj.setTheme('dark');

Parameters:

  • theme ('auto' | 'light' | 'dark') - Theme to apply

setWidgetEnabled

Enable or disable the widget.

// Disable (hides button and panel)
window.fj.setWidgetEnabled(false);

// Enable
window.fj.setWidgetEnabled(true);

Parameters:

  • enabled (boolean) - Whether widget should be enabled

destroy

Remove the widget from the page completely.

window.fj.destroy();

This cleans up all event listeners and removes the widget DOM. Useful for SPA route changes or cleanup.


Method Chaining

Methods are queued if called before the widget loads:

window.fj.init('YOUR_WIDGET_ID');
window.fj.identify({ id: '123' });
window.fj.setTheme('dark');
window.fj.showWidget();

All methods execute in order once the widget is ready.