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 as a standalone script:

<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.


Testing the campaign on your live site

You may want to test your feedback campaign before deploying it to your users.

If you would like to preview the feedback campaign before deploying it to your users, we recommend you use the "Manual" setting for the campaign trigger.


Once you have set up the manual trigger for your feedback campaign, you will want to take the line of JavaScript provided and run it in your browser. That way only you can see the campaign, and not your visitors.

Copy the line of JavaScript provided, and go to the page where you are wanting to see the campaign triggered. Make sure you are being recorded by Mouseflow, otherwise the campaign won't appear. Open the browser's developer tools (instructions for Chrome), enter the line of code provide into the console, and hit enter.


You may want to use Private Browsing or Incognito mode for testing the campaign multiple times.


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 referrer property in JavaScript:

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.