---
updatedAt: 2025-05-07T22:19:47.000Z
agentTools:
  projectIndex: https://help.usersnap.com/llms.txt
---

# API for project-specific widgets (old version)

## Project specific snippet

> ❗️ Notice!
>
> We recommend using the global snippet and its API for showing and hiding feedback buttons and widgets. The project-specific snippets and API will only be maintained and not enhanced in the future.

> 📘 API for project-specific snippets
>
> This snippet will only work for this project and ignore all display rules of this and other projects. Moreover, this version of the API has its own methods, listed below.
>
> If you are using the global snippet for the installation of the Usersnap feedback platform, please go to [this API docu](https://help.usersnap.com/docs/api-for-usersnap-project).

## Project-specific widgets react to the following events

Please, read the documentation about the events in the [general Usersnap API section](https://help.usersnap.com/docs/api-for-usersnap-project#these-events-are-available-via-the-api)

## Installation widget and exposing API

```html Installation snippet
<script>
  window.onUsersnapCXLoad = function(api) {
    api.init();
  }
  var script = document.createElement('script');
  script.async = 1;
  script.src = 'https://widget.usersnap.com/load/<<PROJECT_API_KEY>>?onload=onUsersnapCXLoad';
  document.getElementsByTagName('head')[0].appendChild(script);
</script>
```

## Setting default values - email address

```javascript Setting email address
api.on('open', function(event) {
    event.api.setValue('visitor', 'john@doe.me');
});
```

## Customizing the feedback button

```javascript Hiding the button
api.init({
  button: {isHidden: true}; //hiding the button
});
```

```javascript Setting button position
api.init({
  button: {
    position: "rightCenter" //or "rightBottom" or "bottomRight"
  } 
});
```

## Changing visibility of the button via API

```javascript Showing/Hiding button
api.showButton()

api.hideButton()
```

## Opening the widget via the API

```javascript Opening the widget
api.open()
```

## Setting custom data via the API

```javascript Custom data
api.on('open', function(event) {
    event.api.setValue('custom', {userID: 'u123', enviroment: 'staging'});
});
```

You can pass any data that is of interest to you as "custom data".

This data you can view on the feedback's detail screen under "More details" -> "Custom data"

<HTMLBlock>{`
<style>
.button_us {
  border: none;
  color: white;
  padding: 10px 20px;
  text-align: center;
  text-decoration: none;
  display: inline-block;
  font-size: 16px;
  margin: 4px 2px;
  transition-duration: 0.4s;
  cursor: pointer;
}

.button2_us {
  background-color: #3a21ce; 
  color: white; 
  border: 2px solid #3a21ce;
}

.button2_us:hover {
  background-color: #FFFFFF;
  color: #3a21ce;
  border: 2px solid #3a21ce;
}

</style>

<div><center>
  <button onclick="window.location.href='https://usersnap.com/signup?utm_source=helpcenter&utm_medium=web&utm_campaign=apispecific'" class="button_us button2_us">Get started</button>
  </center>
</div>
`}</HTMLBlock>

## Examples on popular frameworks

Check out sample code for installing widgets in different popular frameworks in the repository below:

<Embed url="https://github.com/usersnap/public" title="usersnap/public" favicon="https://github.com/favicon.ico" image="https://avatars0.githubusercontent.com/u/3296843?s=400&v=4" provider="github.com" href="https://github.com/usersnap/public" />