OneSignal Web Push Notification Setup
Easily configure push notifications for your website with this step-by-step tool
Setup Complete!
Your OneSignal configuration is ready. Copy the code below and add it to your website.
<!-- OneSignal Setup Code -->
<script src="https://cdn.onesignal.com/sdks/OneSignalSDK.js" async></script>
<script>
window.OneSignal = window.OneSignal || [];
OneSignal.push(function() {
OneSignal.init({
appId: "YOUR_APP_ID",
});
});
</script>
<!-- End OneSignal Code -->
{
"name": "Your Website",
"short_name": "Website",
"start_url": "/",
"display": "standalone",
"background_color": "#ffffff",
"theme_color": "#1a73e8",
"icons": [
{
"src": "https://example.com/icon-192x192.png",
"sizes": "192x192",
"type": "image/png"
}
]
}
// OneSignal Service Worker
importScripts('https://cdn.onesignal.com/sdks/OneSignalSDKWorker.js');
Implementation Instructions
- Copy the HTML code and paste it into the <head> section of your website
- Create a manifest.json file with the provided code
- Create a OneSignalSDKWorker.js file with the service worker code
- Update your HTML to reference the manifest: <link rel="manifest" href="/manifest.json">
- Test your setup by visiting your website
${html.replace(//g, '>')}
`;
// Generate manifest code
const manifest = `{
"name": "${siteName.value.trim() || 'Your Website'}",
"short_name": "${siteName.value.trim().substring(0, 12) || 'Website'}",
"start_url": "/",
"display": "standalone",
"background_color": "#ffffff",
"theme_color": "#1a73e8",
"icons": [
{
"src": "${iconUrl.value.trim() || 'https://example.com/icon-192x192.png'}",
"sizes": "192x192",
"type": "image/png"
}
]
}`;
manifestCode.innerHTML = `${manifest.replace(//g, '>')}
`;
// Service worker code is static
swCode.innerHTML = `// OneSignal Service Worker
importScripts('https://cdn.onesignal.com/sdks/OneSignalSDKWorker.js');
`;
alert('Code generated successfully! You can now copy the code snippets.');
}
// Function to reset the form
function resetForm() {
appId.value = '';
siteName.value = '';
siteUrl.value = '';
iconUrl.value = '';
notificationTitle.value = 'New Notification';
notificationMessage.value = 'Check out our latest updates!';
notificationUrl.value = '';
promptStyle.value = 'slide';
autoPrompt.checked = true;
welcomeNotification.checked = true;
notifyButton.checked = true;
promptMessage.value = 'We\'d like to show you notifications for the latest updates.';
updatePreview();
// Reset code blocks
htmlCode.innerHTML = `<!-- OneSignal Setup Code -->
<script src="https://cdn.onesignal.com/sdks/OneSignalSDK.js" async></script>
<script>
window.OneSignal = window.OneSignal || [];
OneSignal.push(function() {
OneSignal.init({
appId: "YOUR_APP_ID",
});
});
</script>
<!-- End OneSignal Code -->
`;
manifestCode.innerHTML = `{
"name": "Your Website",
"short_name": "Website",
"start_url": "/",
"display": "standalone",
"background_color": "#ffffff",
"theme_color": "#1a73e8",
"icons": [
{
"src": "https://example.com/icon-192x192.png",
"sizes": "192x192",
"type": "image/png"
}
]
}
`;
swCode.innerHTML = `// OneSignal Service Worker
importScripts('https://cdn.onesignal.com/sdks/OneSignalSDKWorker.js');
`;
}
});