How do I use Mopinion events?
We fire several events on the document element of the website our form is active. We do this so you can easily hook into our form events to work with data related to our forms.
We have the following events available:
mopinion_loaded
mopinion_shown
mopinion_hidden
mopinion_next (standard forms only)
mopinion_previous (standard forms only)
mopinion_feedback_sent
mopinion_redirect
mopinion_question_answered (conversational forms only)
You can use an event listener to hear when a Mopinion event has taken place. You can then use the occurrence of an event to trigger your own script. With your own script you can, for example, log your feedback in the browser console or push the feedback to your own analytics program.
The structure of the event listener is as follows:
document.addEventListener('[MOPINION_EVENT_NAME]', function(e) {
[YOUR_OWN_TO_BE_EXECUTED_SCRIPT]
});
Replace [MOPINION_EVENT_NAME] with one of the eight Mopinion Events.
Replace [YOUR_OWN_TO_BE_EXECUTED_SCRIPT] with your own script.
In the remaining part of this article, we provide scripts for all 8 events to log the event variables and values in the browser console, push the event variables and values in the Google Tag Manager dataLayer and how that will look in the console/dataLayer.
The events fired are as follows:
1. mopinion_loaded
With this event, you know when a form is loaded, but not yet shown, on a page.
You can use the following JavaScript to display the event's output in the browser's console:
document.addEventListener('mopinion_loaded', function(e) {
console.log(e.detail);
});
Specific code to push the Event Object into the Google Tag Manager dataLayer:
<script type="text/javascript">
document.addEventListener('mopinion_loaded', function(e) {
window.dataLayer.push(e.detail);
});
</script>
The result in the console / dataLayer:
2. mopinion_shown
With this event, you know when the feedback form is shown.
You can use the following JavaScript to display the event's output in the browser's console:
Specific code to push the Event Object into the Google Tag Manager dataLayer:
The result in the console / dataLayer:
3. mopinion_hidden
With this event, you know when the feedback form is hidden again.
You can use the following JavaScript to display the event's output in the browser's console:
Specific code to push the Event Object into the Google Tag Manager dataLayer:
The result in the console / dataLayer:
4. mopinion_next
If your standard feedback form consists of multiple pages this event, will let you know when navigation to the next page takes place. It also makes all the feedback given until that point available. The array with all possible questions is updated with the value of the answered question till then.
You can use the following JavaScript to display the event's output in the browser's console:
Specific code to push the Event Object into the Google Tag Manager dataLayer:
The result in the console / dataLayer:
5. mopinion_previous
If your standard feedback form consists of multiple pages this event, will let you know when navigation to the previous page takes place. It also makes all the feedback given until that point available. The array with all possible questions is updated with the value of the answered question till then.
You can use the following JavaScript to display the event's output in the browser's console:
Specific code to push the Event Object into the Google Tag Manager dataLayer:
The result in the console / dataLayer:
6. mopinion_feedback_sent
With this event, you know when the feedback form is completely submitted.
You can use the following JavaScript to display the event's output in the browser's console:
Specific code to push the Event Object into the Google Tag Manager dataLayer:
The result in the console / dataLayer:
7. mopinion_redirect
With this event, you know when a link within a feedback form is clicked and to what page is being redirected.
You can use the following JavaScript to display the event's output in the browser's console:
Specific code to push the Event Object into the Google Tag Manager dataLayer:
The result in the console / dataLayer:
8. mopinion_question_answered
With this event, you know when a question in a conversational form has been answered. The array with all possible questions is updated with the value of the just-answered question. The ending element
tells what the last answered question was up till that point. As a value, the question title is provided.
You can use the following JavaScript to display the event's output in the browser's console:
Specific code to push the Event Object into the Google Tag Manager dataLayer:
The result in the console / dataLayer:
The labels role
, Survey ID
and Customer ID
are for Mopinion internal use. We advise to not use these labels in any of your further data processing.
Some content in the output is available in different ways. label: "Form trigger"
and triggerMethod:
both tell whether a form was triggered PASSIVE
, PROACTIVE
or EXIT
. label: "Survey"
and formName:
both provide the name of the form.