Survata integration for Gradible

Survata integration for Gradible

Overview

To integrate a Survata surveywall into your website:

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

Instructions

1. Include the Survata JavaScript snippet

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 = "2ce886a0-8184-11e4-b4a9-0800200c9a66";
    }(window, document, 'script', 'Survata'));
</script>

Notes

  • This snippet loads the Survata library asynchronously and will not delay the loading of other page resources.
  • We guarantee that we will not introduce "breaking changes" within a major API version.  So, if your snippet references a major API version (e.g. v3), then your integration will continue to work as the API is upgraded.  Minor version upgrades (e.g. v3.1) include bug fixes and feature additions but no breaking changes.  Any change that breaks compatibility will result in a major version number upgrade (e.g. to v4).
  • We do occasionally require that publishers upgrade to a new major API version, which might require code changes.

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:

  • brand - the brand name for your site (default: your domain name)
  • explainer - a short sentence that explains the surveywall to your users

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() {
    // survata surveywall loaded
    function survataLoaded() {
    	jQuery('#survata-loading').hide();
    	jQuery('#survata-button').show();
    }
    // user has already taken a survey
    function surveyTaken () {
    	jQuery('#survata-loading, #survata-button').hide();
        jQuery('#survata-survey-complete').show();
    }
    // survey is unavailable or Survata failed to load
    function surveyUnavailable() {
        jQuery('#survata-loading').hide();
        jQuery('#survata-survey-unavailable').show();
    }
    Survata.ready(function() {
        var s = Survata.createSurveywall({
            brand:      'Gradible',
            explainer:  'Take a short survey to earn 10 LoanCreds'
        });
        s.on('load', function(data) {
            if (data.status === 'monetizable') {
            	survataLoaded();
            	jQuery('#survata-button').on('click', function(event) {
            		event.preventDefault();
            		s.startInterview();
        		});
                surveyReady = true;
            }
            else if (data.status === 'earnedCredit') {
            	surveyTaken();
            }
            else {
            	surveyUnavailable();
            }
        });
        s.on('interviewComplete', function() {
           surveyTaken();
        });
    }, true);
    Survata.fail(function(){
    	surveyUnavailable();
    });
}());
</script>

 

Example code of a task tile with Survata content. Feel free to modify to meet your needs.

<div class="tile title-hot-">
	<div class="intro-icon-disc cont-large">
		<i class="icon-edit intro-icon-large"></i>
	</div>
	<h6>
		<small>10 LoanCreds </small><br>
	    <div id="survata-loading">
	    	<p style="margin: 5px 0">Loading...</p>
	        <img src="//survatacdn.com/loaders/stripes_small.gif">
	   	</div>
		<a href="#" id="survata-button" style="display: none;"><span>Take Survey</span></a>
	    <p id="survata-survey-complete" style="margin-bottom: 10px; display: none;">You already completed this task</p>
	    <p id="survata-survey-unavailable" style="margin-bottom: 10px; display: none;">Survey currently unavailable</p>
	</h6>
	<p>Earn 10 LoanCreds for completing a survey</p>
</div>

 

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

Publisher API documentation