Anonymous Poll
Guide: Anonymous Voting with pollz-js SDK
Prerequisites
Before you proceed with enabling anonymous voting using the pollz-js SDK, ensure that you have already initialized the SDK and created a poll by following the relevant guides in the "Guides" section.
Enable Anonymous Voting
Anonymous voting allows users to participate in polls without revealing their identities. Follow these steps to enable anonymous voting using the pollz-js SDK.
Step 1: Import the SDK
In your Node.js application, ensure you have already imported the pollz-js SDK:
const { PollzSDK } = require('pollz-js');Step 2: Generate Anonymous Voting Token
Use the createAnonymousToken method provided by the Anonymous module of the SDK to generate an anonymous voting token for a specific poll. Provide the poll ID as an argument.
const pollz = new PollzSDK();
// Replace 'your-app-id' and 'your-app-secret' with actual credentials
const initInput = {
appId: 'your-app-id',
appSecret: 'your-app-secret',
};
// Initialize the SDK
await pollz.init(initInput);
// Replace with the actual poll ID
const pollIdForToken = 1;
try {
const anonymousToken = await pollz.anonymous.createAnonymousToken(pollIdForToken);
console.log('Anonymous Token:', anonymousToken);
} catch (error) {
console.error('Failed to generate anonymous token:', error.message);
}Replace 'your-app-id' and 'your-app-secret' with the actual credentials obtained from the Pollz platform. Adjust the pollIdForToken according to the poll for which you want to generate an anonymous voting token.
Step 3: Vote Anonymously
Users can now vote anonymously using the generated token. Use the voteAnonymously method provided by the Anonymous module of the SDK to submit anonymous votes. Provide the anonymous voting token, chosen option IDs, and an optional user ID.
Replace 'your-anonymous-token' with the actual anonymous voting token generated in the previous step. Adjust the optionIdsForAnonymousVote and userIdForAnonymousVote according to your application's context.
Congratulations! You have successfully enabled and implemented anonymous voting for a poll using the pollz-js SDK. Explore more SDK features and functionalities to enhance your application's polling experience. Refer to the relevant guides for detailed instructions on other SDK capabilities.
Last updated