Skip to main content

2. Anonymous Mode

This document describes the second integration mode: Anonymous Mode. Details of all modes can be found in the Integration Modes section.

For anonymous access without requiring users to create or link Classwise accounts, you can use anonymous mode. This is useful for temporary access or guest users.

{
"message_type": "mode_selection",
"data": {
"type": "anonymous",
"partnerUserId": "your_unique_user_identifier"
}
}

Requirements for anonymous mode:

  • partnerUserId must be a unique string identifier (1-100 characters)
  • The identifier should be consistent for the same user across sessions
  • This creates a temporary anonymous session in Classwise
tip

Best Practices for Anonymous Mode

  • Keep partnerUserId strings between 1-100 characters
  • partnerUserId should not contain any personal information. It is the only identifier we keep, used solely for statistical purposes – to understand how many unique users have accessed Classwise in this way.

Example: Anonymous Mode Implementation

function handleMessage(event) {
if (event.origin !== "https://app.classwise.com") return;

const dataObj = event.data;

switch (dataObj.message_type) {
case "waiting_for_mode_selection":
// Send anonymous mode selection
const anonymousModeMessage = {
message_type: "mode_selection",
data: {
type: "anonymous",
partnerUserId: "user_id_1531", // or uuid or any unique identifier
},
};

event.source?.postMessage(anonymousModeMessage, event.origin);
break;

case "waiting_for_content":
// User is authenticated (anonymously), send quiz content
sendQuizContent(event);
break;
}
}

function sendQuizContent(event) {
const quizData = {
message_type: "start_quiz",
data: {
// Your quiz content here
},
};

event.source?.postMessage(quizData, event.origin);
}

Example: Handling Mode Selection Errors

Classwise may respond with error messages if mode selection fails:

function handleMessage(event) {
if (event.origin !== "https://app.classwise.com") return;

const dataObj = event.data;

if (dataObj.error) {
switch (dataObj.error.message) {
case "authentication_failed":
console.error("Mode selection failed:", dataObj.error.details);
// Handle error - maybe retry or fallback to different mode
break;

case "user_not_authenticated":
console.error("User authentication required:", dataObj.error.details);
// User needs to be authenticated before sending content
break;

case "Message validation failed":
console.error("Invalid message format:", dataObj.error.details);
// Check your message structure
break;
}
}
}

Error Handling

When using anonymous mode, you may encounter these error responses:

Error TypeDescriptionAction Required
mode_selection_failedMode selection process failedRetry with different parameters or use different mode
anonymous_mode_unsupportedAnonymous mode is not supported for the current operationUse other integration mode to use this feature