Magento Setup
How to set up OneSignal Web Push notifications on Magento sites
Non-HTTPS domains are no longer supported
Sites hosted on HTTP are no longer supported. As a result of this change, we are pausing support for this platform indefinitely. Sites that continue to use the
os.tc
domain will no longer be able to prompt for push notifications; however, existing subscriptions will continue to receive notifications.
This guide will walk you through how to set up web push on Magento. If you do not use Magento, or wish to write custom code, please see Web Quickstart.
If you haven't already, sign up for a free account on onesignal.com.
If this is not your first app with OneSignal, click New App/Website. Otherwise, you will see the next page.
Name your app something similar to your site, then select Web from the platform list. Click Next: Configure Your Platform.
Note: If you want to set up more platforms, you will be able to do so later within the app's settings page.
1. Choose Integration
Select Typical Site. This will enable you to configure the prompts and other settings directly within the OneSignal dashboard.
2. Site Setup
Input your default site information.
Field | Description |
---|---|
SITE NAME | The default name for your site. Shows in push notifications. |
SITE URL | Your actual website URL (e.g. https://example.com , https://www.example.com ).Must include: - https:// - If your site uses www make sure to include it.To test locally, see Local Testing Setup |
AUTO RESUBSCRIBE (HTTPS ONLY) | Recommended: Allows push subscribers to automatically resubscribe upon returning to your site without being prompted if they clear their browser data or if you are transferring to OneSignal from another push provider. |
DEFAULT ICON URL | Icon used for Prompting and the default for push notifications. Enter an https icon URL or upload file that is square 256x256 pixels.The file must be .png , .jpg , or .gif . |
3. Permission Prompt Setup
By default, the Push Slide Prompt will show on the first page view after 10 seconds. You can skip this step for now and come back later to add new prompts or modify this one. See our Web Prompting Guide for more details.
4. Welcome Notification (Optional)
A push notification sent immediately to current user upon subscribing to your site for the first time. Enabled by default, it can be toggled-off to prevent showing and update message content at anytime. If you want to add a delay, toggle off this notification and use Journeys or Automated Messages.
5. Advanced Push Settings (Optional)
OneSignal provides several Advanced Options. For instance:
Multiple Service Workers
If you are using or plan to use another service worker on your site, please follow the OneSignal Service Worker Setup Guide.
Safari Certificate (Optional)
OneSignal automatically provides the necessary certificates to work with Safari Browsers at no additional cost. If you already have your own Safari Web Push Certificates, toggle on this option to upload your Safari Web .p12 Push Certificate
and password.
Click Save to continue.
6. Upload Files
Download OneSignal SDK file which is the Service Worker file. You must upload this file to your server.
Option 1. Create file and copy code
-
Create a new file
OneSignalSDKWorker.js
and make it public. -
Copy-paste the following import statement into the file:
importScripts("https://cdn.onesignal.com/sdks/web/v16/OneSignalSDK.sw.js");
Option 2. Download zip folder and upload
-
Click Download OneSignal SDK files (you can also download the file here).
-
Unzip the download. There should be a single file you need to host.
Hosting the file
The OneSignal SDK file must be publicly accessible and can be placed at the top-level root of your site. The OneSignal SDK will look for the file at https://yoursite.com/OneSignalSDKWorker.js
. If you want to place them in a subfolder, you can! Please see our OneSignal Service Worker Guide for instructions.
Subfolders or Migrating from another Push Provider
If you want to place the
OneSignalSDKWorker.js
file in a subfolder or if you are migrating to OneSignal from another provider, please see our OneSignal Service Worker Guide for instructions.
7. Add Code to Site
To enable OneSignal on your site, you will need to paste the provided code into your website's <head>
. If you do not have access to modify your site's code, you will need to contact a developer to help you.
The OneSignal JavaScript SDK code should work on any site, but if your site is setup using Angular, React JS, or Vue JS then follow these links.
<script src="https://cdn.onesignal.com/sdks/web/v16/OneSignalSDK.page.js" defer></script>
<script>
window.OneSignalDeferred = window.OneSignalDeferred || [];
OneSignalDeferred.push(function(OneSignal) {
OneSignal.init({
appId: "YOUR_ONESIGNAL_APP_ID",
});
});
</script>
8. Subscribe and Send Yourself a Notification
Go to your website. You should be prompted to subscribe to push notifications based on the prompt settings you setup. Click it to see the native browser prompt and subscribe to push. Then Find & Set Test Subscriptions and send yourself a Push Notification.
Setup Complete!
If you are having difficulty, please check Web Push Troubleshooting or contact [email protected] for assistance.
Updated 9 months ago