API
Smiley Digital comes with a few events and properties that can be used to interact with the panel or how the survey is presented.
hideOnInit
Section titled “hideOnInit”type: boolean | undefined
Example
Section titled “Example”<script type="text/javascript"> window.HappyOrNot.init({ token: "{token}", hideOnInit: true });</script>
onEvent
Section titled “onEvent”type: function
parameters: toggle
Toggle Smiley Pop-up in our out. Default state can be manipulated with the hideOnInit
setting (example above).
// Calling togglePanel, will pop the panel in and outconst togglePanel = () => window.HappyOrNot.onEvent('toggle');document.querySelector('button').addEventListener('click', togglePanel);
Example
Section titled “Example”-
Initialize a Smiley Digital Pop-up by using the provided script (from Analytics service):
<script type="text/javascript" src="https://feedback.happy-or-not.com/v1/bootloader/{token}/bootloaderjs/?lang=fi-FI&init=true"></script> -
Tell Smiley Digital that it should be hidden by default, on page load:
<script type="text/javascript">window.HappyOrNot.init({token: '{token}',hideOnInit: true,});</script> -
Define a mechanism through which to trigger the pop-out panel on demand. Can be event based, timer based, etc. Within the same script tag as the previous code example, we can write a short function that pops out the panel after a set number of seconds have passed after page load:
const delay = 10 * 1000; // 10 secondssetTimeout(() => window.HappyOrNot.onEvent('toggle'), delay);
All together and in order:
<script type="text/javascript" src="https://feedback.happy-or-not.com/v1/bootloader/{token}/bootloaderjs/?lang=fi-FI&init=true"></script>
<script type="text/javascript"> window.HappyOrNot.init({ token: '{token}', hideOnInit: true, });
const delay = 10 * 1000; // 10 seconds setTimeout(() => window.HappyOrNot.onEvent('toggle'), delay);</script>
metadata
Section titled “metadata”Providing a metadata property on the Smiley Digital init
object allows for sending aditional information along with user feedback. The contents of the metadata
property take the following shape:
type Metadata = { metadata: { [key as string]: string; };};
Example
Section titled “Example”<script type="text/javascript"> window.HappyOrNot.init({ token: '{token}', metadata: { refId: '74a222d5-41e0-4ca8-95eb-bf675d17e570', }, });</script>
On Web (Standalone)
Section titled “On Web (Standalone)”Metadata can be configured as URL parameters attached to the shortlink. These parameters must be prefixed with m-
to be considered, otherwise they are discarded.
Example
Section titled “Example”https://smiley.link/ABCDFG?m-refId=value
This is sent with the smiley feedback as:
{ "refId": "value"}