Project specific snippet
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.
Project-specific widgets react to the following events
load – The widget was loaded (initialized)
destroy – The widget was destroyed
open – The widget was opened
close – The widget was closed
submit – The widget’s form was submitted
Installation widget and exposing API
<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
api.on('open', function(event) {
event.api.setValue('visitor', '[email protected]');
});
Customizing the feedback button
api.init({
button: {isHidden: true}; //hiding the button
});
api.init({
button: {
position: "rightCenter" //or "rightBottom" or "bottomRight"
}
});
Changing visibility of the button via API
api.showButton()
api.hideButton()
Opening the widget via the API
api.open()
Setting custom data via the API
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"
Passing user information via the API
You can pass user information to Usersnap to increase the options to target specific user groups and provide targeted experiences.
// assuming a global widget config looking something like this
window.onUsersnapCXLoad = function(api) {
api.init({
user: {
email: "[email protected]", // Email address
userId: "USER_ID", // on client system
}
});
}
Examples on popular frameworks
Check out sample code for installing widgets in different popular frameworks in the repository below:
Updated 4 days ago