Category: developer
Triggering the widget programmatically
Triggering the widget at the right moment in the customer journey can be a powerful way to get feedback at the exact right moment.
Showing the widget
After you've placed the code snippet in your <head>
you can trigger the widget by using:
freddyWidget.show();
Typically you would use this when there is no page load and you want to trigger the widget after a specific event or if you want to implement a specific call-to-action. For instance after a puchase was made, a video was watched or a button was clicked.
Here's the Javascript widget for triggering the widget on a button click:
document.getElementById('my-button').addEventListener('click', function() {
freddyWidget.show();
});
If you want to trigger the widget programmatically directly after the page is loaded, wrap the show()
method in the load event to ensure that all resources, including the Freddy script, are loaded:
window.addEventListener('load', function() {
freddyWidget.show();
});
Passing custom fields
When triggering the widget programmatically you can pass custom fields. This is a powerful way to enrich responses with data that is relevant to your business. Read all about custom fields in the documentation here.
Cooldown logic
If you've set cooldown logic for your survey (either after a response or after close), then using show()
will not open the widget if the cooldown is still in place.
Hiding the widget
Note that there is also:
freddyWidget.hide();
We've added this functionality so you can fully customize the experience, however we normally don't recommend using it. This is because it's difficult to know what the user is doing exactly, and you risk closing the widget while a user is typing feedback. But a use case can be that there is an urgent action for the user to complete where you need to close all other items on the screen.