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>
Related Articles
How to use webhooks to trigger SightMill to send an email survey
You can link your CRM or application directly to SightMill so that an email survey is sent by SightMill when triggered directly from your application. This is a great way to send an email survey after, for example, a customer service call or when a ...
How do webhooks work in practice?
Let's take an example of integrating SightMill with Salesforce CRM so that SightMill will generate and send out an NPS email survey when you change your contact settings in Salesforce to show the contact has bought your product. (Note: to send ...
What is the webhook format?
Our webhook API is a simple, industry-standard method of linking different systems together to let you send out an NPS survey in response to an event on a different system. For example, you could: Link your helpdesk system to SightMill using webhooks ...
How to integrate with Zendesk
It's easy to connect Zendesk to SightMill - which automates the process of sending email surveys. There's no coding and it uses the webhooks API that will take you just a few minutes to start sending email surveys in response to a trigger in Zendesk ...
Does SightMill have an API?
Yes, we support an API concept called webhooks. Webhooks are an industry-standard, lightweight technology used to pass data between platforms in response to events. As more and more applications use real-time information and events, webhooks are ...