Overview

To integrate a Survata surveywall into your website:

  1. Include the Survata JavaScript snippet within the <head> tag. 
  2. Create a surveywall object: Survata.createSurveywall()
  3. Trigger a Survata interview: surveywallObj.startInterview()

Instructions

1. Add the Survata snippet to your page

Add the following JavaScript snippet to the head section of your page.

<script type="text/javascript">
    (function(w, d, t, v) {
        w[v] = w[v] || {}; w[v].qr = []; w[v].qf = [];
        var got = 0, g = function() {
            if (got) { return; } got = 1;
            w[v].ft = setTimeout(function() {
                for (var i = 0; i < w[v].qf.length ; i++) { w[v].qf[i][0].call(w[v]); }
                w[v].f = 1; w[v].qf = [];
                w[v].fail = function(fn) { fn.call(w[v]); return w[v]; };
            }, 5000);
            var s = d.createElement(t);
            s.src = ('https:' === d.location.protocol ? 'https:' : 'http:') + "//api.survata.net/latest/js/survata.js?cb="+((new Date().getTime())/1e3).toFixed();
            var scr = d.getElementsByTagName(t)[0], par = scr.parentNode; par.insertBefore(s, scr);
        };
        w[v].ready = function() { g(); w[v].qr.push(arguments); return w[v]; };
        w[v].fail = function() { g(); w[v].qf.push(arguments); return w[v]; };
        w[v].publisher = "1528e200-a031-11e4-bcd8-0800200c9a66";
    }(window, document, 'script', 'Survata'));
</script>

Notes

2. Create the Survata surveywall object and wait for "load" event

Register any code that uses the Survata library inside the Survata.ready callback, which will be executed when Survata library is ready for execution. Within this call, create a surveywall object by calling Survata.createSurveywall, which accepts an (optional) object with the following options:

Attach an event handler to the surveywall object and wait for the "load" event, which will occur when the surveywall is loaded. If an interview is available for the user, the survey wall will appear and will block the content until completed.

Add the snippet below at the bottom on your page:

<script>
(function() {
 
	function hideSurvata(msg) {
    	$('#survata-loading').hide();
    	$('#survata-status').text(msg);
  	};
 
	// Survata has loaded successfully
	Survata.ready(function() {
    	var s = Survata.createSurveywall({
        	brand:      'Insticator',
        	explainer:  'Complete this short, anonymous Survata survey',
       	 	parent: document.getElementById('survata-content'),
        	allowSkip:  false,
        	disallowClose: true,
        	hideHeader: true,
			hideFooter: true,
       	 	verticalLayout: true
    	});

    	s.on('load', function(data) {	
        	if (data.status === 'monetizable') {
          		$('#survata-loading').hide();
          		s.startInterview();
        	}
        	else if (data.status === 'earnedCredit') {
          		hideSurvata('Survey already taken on this page');
        	}
        	else {
          		hideSurvata('No survey is available');
        	}
    	});

		s.on('interviewComplete', function() {
      		hideSurvata('Thanks for taking the survey');
    	});
  	}, true);
 
	// error loading Survata JS
	Survata.fail(function() {
    	hideSurvata('No survey is available');
  	});
 
	// OPTIONAL - Only show Survata a fraction of the time during testing by wrapping the Survata code in a block like this
	// if (diceRoller(.25)} {// Survata code here (only show Survata 25% of the time) }
	var diceRoller = function(fraction) {
    	return Math.random() < fraction;
	};
})();
 
</script>

 

Example Survata content block within <div class="grid grid-detail"> Feel free to modify to meet your needs.

<div id="survata-content">
	<div id="survata-loading" style="text-align:center;"><img src="//media.survata.com/loaders/circles_medium.gif"/></div>
    <div id="survata-status"></div>
</div>

 

Here is a link to a demo integration:

https://www.survata.com/publisher-demos/insticator/

For additional information, here is a link to our general publisher integration document: 

Publisher API documentation