A customer of mine uses SurveyMonkey, a popular online survey tool, to build and manage their visitor surveys. You can set up the survey to pop up an invitation to participate, which then leads on to the survey itself.
Once your survey is all set up, SurveyMonkey gives you a script tag to embed on the pages you want to run the survey on. The script tag is a simple fetch of some code hosted on the surveymonkey.com servers. The code it ultimately fetches is a simple window.open() call.
So far so simple. The catch in my case was that the customer wanted the survey to appear when the user left the page rather than when they arrived, the reasoning being that at least then they would have seen some site content in order to better answer the survey questions.
My second attempt was to use AJAX to fetch the SurveyMonkey code and then run it via an eval(). This failed because of browser cross-site-scripting restrictions (you can’t use AJAX to talk to a server other than the one that served the current document). It took me a while to remember this; at first I thought that the fact that surveymonkey.com was returning a 302 redirect was the issue.
So I finally gave up and fired off a question to the SurveyMonkey support folks to see if there was a way of doing this, e.g. via JSONP or some other API. They got back to me after a few hours, but only to confirm what I already suspected: there is no API.
In the end I implemented my own invitation popup, which was a shame. SurveyMonkey has configuration options to control when the popup appears, e.g. every 100 visits, once per user, etc, which I was obviating by rolling my own. The invitation popup then used SurveyMonkey’s Embed HTML to present the actual survey.
They say in science there’s an inherent bias in that negative results tend not to get published. This is part of my effort to redress the balance!