Mouseflow Help & Support

How do I trigger a Feedback campaign manually?

Follow

When setting up a Feedback campaign you have the option of using manual triggers. This means you can have your campaign triggered by any custom event on your website. This can be when your visitor clicks a button or comes from a certain source - or any other event you need.

Triggering a campaign

To trigger a campaign, you need to call a simple function. You can call the function as part of your Mouseflow tracking code or add it as a stand-alone script. Here's an example of the function:

<script type="text/javascript"> 
window._mfq = window._mfq || [];
window._mfq.push(['activateFeedback', '{FEEDBACK-ID}']);
</script>

In this example you will need to replace the placeholder {FEEDBACK-ID} with the ID of the campaign in question. This ID is visible when you select the manual trigger and can also be seen in the URL of the campaign. An example ID could be 'QMBELz7bIUufA-Mpn9Yplg' - for this ID, the call would be:

window._mfq.push(['activateFeedback', 'QMBELz7bIUufA-Mpn9Yplg']);

Note that triggering a campaign manually will not override any other limitations in the campaign, like page rules. So if the campaign is set up to fire only on the page "/contact", you can't trigger it manually on other pages. The same is true for segmenting - if the campaign is set to fire for specific languages, visitor types or device types, it can't be triggered it if these details don't match.


Common use cases

Below, we'll show some common use cases for manual triggers. Note that we use jQuery in these examples:

Trigger a campaign when clicking an element

To trigger a campaign on a click, you first need to create a click handler for the element that should be clicked. In this example, we'll have the user click a button:

<button id="feedback_button" type="button">Start Feedback Campaign</button> 

Using the ID of this button, we can easily create a click handler:

<script type="text/javascript">
$('#feedback_button').click( function() {
window._mfq = window._mfq || [];
window._mfq.push(['activateFeedback', 'QMBELz7bIUufA-Mpn9Yplg']);
});
</script>

That's it. The Feedback campaign will now be triggered when the button is clicked.


Trigger a campaign for specific referrers

Triggering a campaign for certain referrers can be useful, if you want to target visitors from a certain source. In this example we'll target all visitors from google.com. First, we'll use the JavaScript property 'document.referrer':

document.referrer

This property will return a string containing the URL of the referral page. If that page was google.com, the string could look like this:

"https://www.google.com/"

We can then use JavaScript to look at the value of this property for each visitor - and to trigger the Feedback campaign, if the string contains a certain value. In this case, we'll look for the value 'google.com':

<script type="text/javascript">
if (document.referrer.indexOf('google.com') > -1) {
window._mfq = window._mfq || [];
window._mfq.push(['activateFeedback', 'QMBELz7bIUufA-Mpn9Yplg']);
}
</script>

This will trigger the Feedback campaign for each visitor from google.com.

Have more questions? Submit a request

Comments

Powered by Zendesk