Examples and Tutorials
Welcome to the Peekaboo SDK Examples and Tutorials section. Here, you'll find practical examples and step-by-step tutorials to help you get started with Peekaboo SDK and make the most out of its features.
Table of Contents
- Basic Integration
- Advanced Customization
- Handling User Interactions
- Using Real-Time Analytics
- Error Handling and Debugging
Basic Integration
Example: Basic IWE Creation
This example demonstrates how to create and display a simple Interactive Wait Experience (IWE).
-
JavaScript:
import Peekaboo from 'peekaboo-sdk';
const peekaboo = new Peekaboo({
apiKey: 'YOUR_API_KEY',
projectId: 'YOUR_PROJECT_ID'
});
peekaboo.createIWE({
message: 'Hang tight! Great things are coming your way!',
theme: 'default'
}); -
Java:
import com.peekaboo.sdk.Peekaboo;
public class Main {
public static void main(String[] args) {
Peekaboo peekaboo = new Peekaboo("YOUR_API_KEY", "YOUR_PROJECT_ID");
peekaboo.createIWE("Hang tight! Great things are coming your way!", "default");
}
} -
Python:
import peekaboo_sdk as peekaboo
peekaboo.initialize(api_key='YOUR_API_KEY', project_id='YOUR_PROJECT_ID')
peekaboo.create_iwe(
message='Hang tight! Great things are coming your way!',
theme='default'
)
Advanced Customization
Tutorial: Creating a Custom Themed IWE
This tutorial walks you through creating a custom-themed IWE with interactive elements.
-
Define the Custom Theme:
const customTheme = {
backgroundColor: '#123456',
textColor: '#ffffff',
fontSize: '18px',
fontFamily: 'Verdana, sans-serif'
}; -
Create the Interactive Element:
const interactivity = {
type: 'poll',
question: 'What feature would you like to see next?',
options: ['New UI', 'More Games', 'Better Performance']
}; -
Create and Display the IWE:
peekaboo.createIWE({
message: 'We value your feedback!',
theme: customTheme,
interactivity: interactivity
}); -
Complete Code Example:
import Peekaboo from 'peekaboo-sdk';
const peekaboo = new Peekaboo({
apiKey: 'YOUR_API_KEY',
projectId: 'YOUR_PROJECT_ID'
});
const customTheme = {
backgroundColor: '#123456',
textColor: '#ffffff',
fontSize: '18px',
fontFamily: 'Verdana, sans-serif'
};
const interactivity = {
type: 'poll',
question: 'What feature would you like to see next?',
options: ['New UI', 'More Games', 'Better Performance']
};
peekaboo.createIWE({
message: 'We value your feedback!',
theme: customTheme,
interactivity: interactivity
});
Handling User Interactions
Example: Capturing User Feedback
This example shows how to capture and handle user interactions within an IWE.
-
Register Event Listener:
peekaboo.on('userInteraction', (event) => {
console.log('User interaction captured:', event);
}); -
Create an Interactive IWE:
peekaboo.createIWE({
message: 'Tell us your favorite color!',
theme: 'default',
interactivity: {
type: 'quiz',
question: 'What is your favorite color?',
options: ['Red', 'Blue', 'Green', 'Yellow']
}
}); -
Complete Code Example:
import Peekaboo from 'peekaboo-sdk';
const peekaboo = new Peekaboo({
apiKey: 'YOUR_API_KEY',
projectId: 'YOUR_PROJECT_ID'
});
peekaboo.on('userInteraction', (event) => {
console.log('User interaction captured:', event);
});
peekaboo.createIWE({
message: 'Tell us your favorite color!',
theme: 'default',
interactivity: {
type: 'quiz',
question: 'What is your favorite color?',
options: ['Red', 'Blue', 'Green', 'Yellow']
}
});
Using Real-Time Analytics
Tutorial: Accessing and Displaying Real-Time Analytics
This tutorial demonstrates how to fetch and display real-time analytics data.
-
Fetch Analytics Data:
peekaboo.getAnalytics().then((data) => {
console.log('Real-time analytics:', data);
}); -
Display Analytics in the UI:
peekaboo.getAnalytics().then((data) => {
document.getElementById('analytics').innerText = JSON.stringify(data, null, 2);
}); -
Complete Code Example:
import Peekaboo from 'peekaboo-sdk';
const peekaboo = new Peekaboo({
apiKey: 'YOUR_API_KEY',
projectId: 'YOUR_PROJECT_ID'
});
peekaboo.getAnalytics().then((data) => {
document.getElementById('analytics').innerText = JSON.stringify(data, null, 2);
}); -
HTML Element for Displaying Analytics:
<div id="analytics"></div>
Error Handling and Debugging
Example: Implementing Error Handling
This example shows how to implement error handling to capture and manage errors within Peekaboo SDK.
-
Register Error Handler:
peekaboo.onError((error) => {
console.error('An error occurred:', error);
}); -
Trigger an Error for Testing:
// Simulate an error
peekaboo.createIWE({
message: 'This will fail!',
theme: 'nonexistentTheme'
}); -
Complete Code Example:
import Peekaboo from 'peekaboo-sdk';
const peekaboo = new Peekaboo({
apiKey: 'YOUR_API_KEY',
projectId: 'YOUR_PROJECT_ID'
});
peekaboo.onError((error) => {
console.error('An error occurred:', error);
});
// Simulate an error
peekaboo.createIWE({
message: 'This will fail!',
theme: 'nonexistentTheme'
});
Peekaboo SDK - Transforming wait times into delightful experiences.