You might have a requirement to send an NPS survey directly from an action on your website or software platform.
A few examples are when you need to:
- Send an email survey if a user clicks on a button on your website
- Send an email survey if a customer completes a step in your e-commerce checkout
- Link your software to SightMill even if your software does not support webhook APIs
- Send an email survey if any event happens on your website
One of the best ways to achieve any of these actions is to use link your website with SightMill using our webhooks API and calling this API from your website using some simple javascript. Here's how to accomplish this:
Both examples below need your project's unique webhook for incoming data - you will find this in the Settings/Webhooks menu and it's the first field.
- Toggle on the feature (first toggle switch at the top of the menu screen)
- Select and copy your unique webhooks link that is displayed in the Email Survey field
- (If you want to store any incoming email survey requests as new contacts in SightMill - so you can then send them regular surveys in the future - switch on the 'Store Email Webhooks Data' toggle.
Example 1:
Send an email NPS survey from your website using javascript
A simple first example calls the webhook using javascript that you can copy and paste into your web page
- <script type='text/javascript'>
- var data = {
- 'email': 'sc@test.com', //mandatory field replace email address with your variable
- 'firstname': 'Simon', //optional field replace Simon with your variable
- 'lastname': 'Smith', //optional field replace Smith with your variable
- 'tags': 'first-tag', //optional field replace first-tag with your variable
- 'segment': 'gold', //optional field replace gold with your variable
- 'id': 'sc@test.com' //mandatory field replace email address with your variable
- };
- var xhr = new XMLHttpRequest();
- xhr.open('POST', 'https://sightmill.com/hooks/XXXXX/survey/email'); //replce https link between double quotes with your unique webhook link from the first field in the Webhooks menu
- xhr.send(JSON.stringify(data));
- </script>
The data that is used to complete the email survey is in lines 3-8 above - we've included example text, but you should replace this with the variables from your software that includes this information for the user.
Example 2:
Send an email NPS survey if a user clicks on a button on your website
Paste the following javascript into your webpage.
- <script type='text/javascript'>
- function postDataToWebhook(){
- //url to your webhook which is the top field in the Webhooks menu
- var webHookUrl="https://sightmill.com/hooks/XXXXX/survey/email"; //replace the link between double quotes with your unique webhooks address
- var oReq = new XMLHttpRequest();
- var myJSONStr = payload={
- 'email': 'sc@test.com', //mandatory field replace email address with your variable
- 'firstname': 'Simon', //optional field replace Simon with your variable
- 'lastname': 'Smith', //optional field replace Smith with your variable
- 'tags': 'first-tag', //optional field replace first-tag with your variable
- 'segment': 'gold', //optional field replace gold with your variable
- 'id': 'sc@test.com' //mandatory field replace email address with your variable
- };
- document.write(myJSONStr);
- oReq.addEventListener("load", reqListener);
- oReq.open("POST", webHookUrl,true);
- oReq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
- oReq.send(JSON.stringify(myJSONStr));
- }
- function reqListener () {
- console.log(this.responseText);
- }
- </script>
You should populate the data with variables from your website - for example, if you are using Wordpress, add the user's email address wiith Wordpress' user information variables.
To send out the email survey, you need to call the new function created above, which you can do either add it to an event (such as a button click) or use another small script:
- <script type='text/javascript'>
- postDataToWebhook();
- </script>