Survata integration for Science Daily
Overview
To integrate a Survata surveywall into your website:
- Include the Survata JavaScript snippet within the <head> tag.
- Create a surveywall object:
Survata.createSurveywall()
- 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 src="//api.survata.net/latest/js/survata.js"></script> <script> (function(w, 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); }; 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 = "replace_with_your_publisher_id"; }(window, 'Survata')); </script>
Notes
- 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 parameters:
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 snippets below at the bottom on your page. Note that in the demo page that we created, we added the class '.banner-ad' to the divs wrapping the advertisement blocks on the page. Feel free to modify this to your news.
<script> Survata.ready(function() { var s = Survata.createSurveywall({ brand: 'Science Daily', explainer: 'Take a brief survey to enjoy this visit to ScienceDaily without ads' }); var hideSurvata = function() { $('.survata-content').hide(); }; var hideAds = function() { $('.banner-ad').hide(); hideSurvata(); }; s.on('load', function(data) { if (data.status === 'monetizable') { $('.survata-content').show(); $('.survata-btn').on('click', s.startInterview); } else { hideSurvata(); } }); s.on('interviewComplete', function() { hideAds(); }); s.on('interviewError', function() { hideSurvata(); }); }, true); Survata.fail(function() { hideSurvata(); }); </script>
Example Survata content block to place the Survata button div. Feel free to modify to meet your needs.
<div class="survata-content" style="border: 1px solid black; margin-top: 5px; margin-bottom: 5px; padding: 5px; display: none;"> <h3>Want ad-free access?</h3> <div style="float:left;">Take a brief survey and enjoy this visit to ScienceDaily without ads</div> <div style="float:right;"><button class="survata-btn"><i class="icon-check"></i> Take Survey</button></div> <div style="clear:both"></div> </div>
Here is a link to a your demo integration:
https://www.survata.com/publisher-demos/science-daily/
For additional information, here is a link to our general publisher integration document: