Skip to main content

Web SDK

Getting Started

If you haven't already, please start with the Getting Started Guide below.

Installation

The first step is to install the Polls Platform Web SDK. The SDK can be installed using a <script> tag or using npm or Yarn.

Add the following <script> tag to the head of every page on your site. The script will add the PollsSDK object to the global scope. In the onload function of the script tag you can interact with the PollsSDK object to initialize the SDK and create polls.

<head>
<script>
// function that is called after the SDK is loaded
var loadedPollsSDK = () => {
console.log("PollsSDK", PollsSDK);
};
</script>

<!-- this script tag loads the SDK -->
<script
src="https://polls-cdn.com/sdk/web/v3/sdk.min.js"
onload="loadedPollsSDK();"
></script>
</head>

Once the SDK is loaded, you can use destructuring syntax to access objects/types from within the SDK.

const {
initializePolls,
DomainConfigType,
PollResponse,
createPoll,
Environment,
} = PollsSDK;

Create a Poll

Once you have installed the SDK, you're ready to create your first poll.

initializePolls({  apiKey: "YOUR API KEY",  domainConfig: {    type: DomainConfigType.subdomain,    subdomain: "YOUR SUBDOMAIN",  },  environment: Environment.production,});// creating a poll is synchronous and instantaneousconst poll: PollResponse = createPoll({  title,  ownerId,  settings,  options,});// the poll can be opened immediately// in a new tab, or embedded in your siteconsole.log("Poll URL", poll.url);

Setting up Poll Data

The following is a more complete example of setting up fields for a poll.

const options: OptionRequest[] = [  {    resourceId: "1", // the id of this resource in your system    title: "This is the first option",    type: OptionType.defaultTemplate,    subtitle: "Subtitles are displayed below the title",    details: "Descriptions are on the third line",    url: "https://example.com/1",    imageUrl: "https://example.com/images/1.png",  },  {    resourceId: "2", // the id of this resource in your system    title: "This is the second option",    type: OptionType.defaultTemplate,    subtitle: "Subtitles are displayed below the title",    details: "Descriptions are on the third line",    url: "https://example.com/2",    imageUrl: "https://example.com/images/2.png",  },];const poll: PollResponse = createPoll({  title: "Which one should we buy?",  ownerId: ownerId,  settings: {    multipleVotes: true,  },  options: options,});

Opening the Poll

Continue to the next section to learn about the various options for opening the Poll.