{"__v":49,"_id":"5668806406039e0d00c4ed24","category":{"__v":11,"_id":"551ef4ef4986f62b00a7203e","pages":["551ef4f04986f62b00a7206d","551ef4f04986f62b00a7206e","551ef4f04986f62b00a7206f","552359b8e20da719000e797b","5536d74bc36ca60d003c5540","5548372bd2c8410d006c212d","55d77b86f662951900fc0ef5","5605b89024c9d80d001551fd","5668806406039e0d00c4ed24","56688887ee1dbf0d008f62a7","568c6de813c5ad0d00b34e4d","5699b35bcb127f0d003cc1ba","56cbe4638df25d0b00e8d774"],"project":"542b6018044e1e2200413772","version":"551ef4ef4986f62b00a7202e","reference":false,"createdAt":"2015-03-24T04:27:30.031Z","from_sync":false,"order":7,"slug":"website-push","title":"Website Push"},"parentDoc":null,"project":"542b6018044e1e2200413772","user":"55c146fdc0777c0d0046769d","version":{"__v":7,"_id":"551ef4ef4986f62b00a7202e","forked_from":"542b6018044e1e2200413775","project":"542b6018044e1e2200413772","createdAt":"2015-04-03T20:15:43.149Z","releaseDate":"2015-04-03T20:15:43.149Z","categories":["551ef4ef4986f62b00a7202f","551ef4ef4986f62b00a72030","551ef4ef4986f62b00a72031","551ef4ef4986f62b00a72032","551ef4ef4986f62b00a72033","551ef4ef4986f62b00a72034","551ef4ef4986f62b00a72035","551ef4ef4986f62b00a72036","551ef4ef4986f62b00a72037","551ef4ef4986f62b00a72038","551ef4ef4986f62b00a72039","551ef4ef4986f62b00a7203a","551ef4ef4986f62b00a7203b","551ef4ef4986f62b00a7203c","551ef4ef4986f62b00a7203d","551ef4ef4986f62b00a7203e","55d7f1879510f00d007ec727","56b94a5a9fc0de1700b60ae9","56bd0e48ac1c5c1900b2dbe4","56d74afc3eb4dd0b0020196a","5723ab8a1f41110e003081ed","576b4dd327d6252b00085422"],"is_deprecated":false,"is_hidden":false,"is_beta":false,"is_stable":true,"codename":"","version_clean":"2.0.0","version":"2.0"},"updates":[],"createdAt":"2015-12-09T19:26:28.622Z","link_external":false,"link_url":"","githubsync":"","sync_unique":"","hidden":false,"api":{"results":{"codes":[]},"settings":"","auth":"required","params":[],"url":""},"isReference":false,"order":10,"body":"*Note:* WordPress users, customizing all of the features below can be found on the Configuration tab of our plugin.\n\n## How do I hide the notify button after subscribing, or only show it on certain pages?\n\nThe notify button init options takes in a `displayPredicate` function which is evaluated before the notify button is shown. To hide the notify button, this function must return the value `false` *or* a `Promise` that resolves to the value `false`. You may return any other value to show the notify button.\n\nHere is an example *hiding* the notify button if the user is subscribed:\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"// Do NOT call init() twice\\n// This is just an example\\nOneSignal.push([\\\"init\\\", {\\n    /* Your other init options here */\\n    notifyButton: {\\n        /* Your other notify button settings here ... */\\n        enable: true,\\n        displayPredicate: function() {\\n            return OneSignal.isPushNotificationsEnabled()\\n                .then(function(isPushEnabled) {\\n                    /* The user is subscribed, so we want to return \\\"false\\\" to hide the notify button */\\n                    return !isPushEnabled;\\n                });\\n        },\\n    }\\n}]);\",\n      \"language\": \"javascript\"\n    }\n  ]\n}\n[/block]\n## How do I customize or disable the automatic welcome notification when a new site visitor subscribes?\n\nUse the `welcomeNotification` parameter in your [init()](https://documentation.onesignal.com/docs/website-sdk-api#init) options. The `url` parameter is, by default, set to a special value that, on Chrome and Firefox, disables the notification from opening a separate webpage. By default, Safari must open a webpage and it will default to your site's URL. You may optionally set `url` so the notification opens a separate URL (on Chrome, Safari, and Firefox).\n\n**Showing a Welcome Notification**\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"// Do NOT call init() twice\\nOneSignal.push([\\\"init\\\", {\\n    /* Your other init options here */\\n    welcomeNotification: {\\n        \\\"title\\\": \\\"My Custom Title\\\",\\n        \\\"message\\\": \\\"Thanks for subscribing!\\\",\\n        // \\\"url\\\": \\\"\\\" /* Leave commented for the notification to not open a window on Chrome and Firefox (on Safari, it opens to your webpage) */\\n    }\\n}]);\",\n      \"language\": \"javascript\"\n    }\n  ]\n}\n[/block]\n**Disabling Welcome Notifications**\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"// Do NOT call init() twice\\nOneSignal.push([\\\"init\\\", {\\n    welcomeNotification: {\\n        disable: true\\n    }\\n}]);\",\n      \"language\": \"javascript\"\n    }\n  ]\n}\n[/block]\n## How can I change the language / text of the subscription prompt pop-up window?\n[block:html]\n{\n  \"html\": \"<img src=\\\"http://i.imgur.com/v8I93BL.png\\\" style=\\\"background: url(http://i.imgur.com/v8I93BL.png) no-repeat 0 0;\\tbackground-size: contain;\\theight: auto;\\tmax-width: 100%; margin: 0 auto; display: block;\\\"/>\"\n}\n[/block]\n**Note**: This does not apply to Safari's permission prompt. This only applies to the HTTP prompt on Chrome and Firefox.\n\nUse the `promptOptions` parameter in your [init()](https://documentation.onesignal.com/docs/website-sdk-api#init) options. You may change all text except the URL  on the notification image (subdomain.onesignal.com). You may enter text in your own language, but please note all fields are limited in length (usually to one line of text). Unset fields use their defaults.\n\n**Customizing the Pop-Up Text**\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"// Do NOT call init() twice\\nOneSignal.push([\\\"init\\\", {\\n    // Your other init options here\\n    promptOptions: {\\n        /* Change bold title, limited to 30 characters */\\n        siteName: 'OneSignal Documentation',\\n        /* Subtitle, limited to 90 characters */\\n        actionMessage: \\\"We'd like to show you notifications for the latest news and updates.\\\",\\n        /* Example notification title */\\n        exampleNotificationTitle: 'Example notification',\\n        /* Example notification message */\\n        exampleNotificationMessage: 'This is an example notification',\\n        /* Text below example notification, limited to 50 characters */\\n        exampleNotificationCaption: 'You can unsubscribe anytime',\\n        /* Accept button text, limited to 15 characters */\\n        acceptButtonText: \\\"ALLOW\\\",\\n        /* Cancel button text, limited to 15 characters */\\n        cancelButtonText: \\\"NO THANKS\\\"\\n    }\\n}]);\",\n      \"language\": \"javascript\"\n    }\n  ]\n}\n[/block]\n## How can I enable or disable the notify button? How can I change the text or its behavior?\n\nUse the `notifyButton` parameter in your [init()](https://documentation.onesignal.com/docs/website-sdk-api#init) options.\n\n**Customizing the Notify Button**\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"// Do NOT call init() twice\\nOneSignal.push([\\\"init\\\", {\\n    /* Your other init options here */\\n    notifyButton: {\\n        enable: true, /* Required to use the notify button */\\n        size: 'medium', /* One of 'small', 'medium', or 'large' */\\n        theme: 'default', /* One of 'default' (red-white) or 'inverse\\\" (white-red) */\\n        position: 'bottom-right', /* Either 'bottom-left' or 'bottom-right' */\\n        offset: {\\n            bottom: '0px',\\n            left: '0px', /* Only applied if bottom-left */\\n            right: '0px' /* Only applied if bottom-right */\\n        },\\n        prenotify: true, /* Show an icon with 1 unread message for first-time site visitors */\\n        showCredit: false, /* Hide the OneSignal logo */\\n        text: {\\n            'tip.state.unsubscribed': 'Subscribe to notifications',\\n            'tip.state.subscribed': \\\"You're subscribed to notifications\\\",\\n            'tip.state.blocked': \\\"You've blocked notifications\\\",\\n            'message.prenotify': 'Click to subscribe to notifications',\\n            'message.action.subscribed': \\\"Thanks for subscribing!\\\",\\n            'message.action.resubscribed': \\\"You're subscribed to notifications\\\",\\n            'message.action.unsubscribed': \\\"You won't receive notifications again\\\",\\n            'dialog.main.title': 'Manage Site Notifications',\\n            'dialog.main.button.subscribe': 'SUBSCRIBE',\\n            'dialog.main.button.unsubscribe': 'UNSUBSCRIBE',\\n            'dialog.blocked.title': 'Unblock Notifications',\\n            'dialog.blocked.message': \\\"Follow these instructions to allow notifications:\\\"\\n        }\\n    }\\n}]);\",\n      \"language\": \"javascript\"\n    }\n  ]\n}\n[/block]\n**Customizing the Notify Button's Colors**\n\nYou can override the theme's colors by entering your own. Values are strings which are then interpreted by CSS, so any CSS-valid color works as each value. For example, `white`, `#FFFFFF`, `#FFF`, `rgb(255, 255, 255)`, `rgba(255, 255, 255, 1.0)`, and `transparent` are all valid values.\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"// Do NOT call init() twice\\nOneSignal.push([\\\"init\\\", {\\n  // Your other init options here\\n  notifyButton: {\\n    enable: true, // Required to use the notify button\\n    // Your other notify button settings here\\n    colors: { // Customize the colors of the main button and dialog popup button\\n      'circle.background': 'rgb(84,110,123)',\\n      'circle.foreground': 'white',\\n      'badge.background': 'rgb(84,110,123)',\\n      'badge.foreground': 'white',\\n      'badge.bordercolor': 'white',\\n      'pulse.color': 'white',\\n      'dialog.button.background.hovering': 'rgb(77, 101, 113)',\\n      'dialog.button.background.active': 'rgb(70, 92, 103)',\\n      'dialog.button.background': 'rgb(84,110,123)',\\n      'dialog.button.foreground': 'white'\\n    },\\n  }\\n}]);\",\n      \"language\": \"javascript\"\n    }\n  ]\n}\n[/block]\n## How can I automatically dismiss a notification after some time?\n\nOn Firefox and Safari, notifications are automatically dismissed after a short amount of time. On Chrome, by default, notifications last indefinitely (they are displayed until the user interacts with it by dismissing it or clicking it). On Chrome Desktop v47+, you can add [the `persistNotification` parameter](doc:website-sdk-api#init) to your OneSignal init call to control whether a notification is displayed indefinitely or dismissed after 20 seconds.\n\n`persistNotification` defaults to true if unset. Set it to false to automatically dismiss the notification after 20 seconds (Chrome Desktop v47+ only).\n\n**Dismissing Notifications After ~20 Sec. (Chrome Desktop v47+)**\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"// Do NOT call init() twice\\nOneSignal.push([\\\"init\\\", {\\n  // Your other init options here\\n  persistNotification: false // Automatically dismiss the notification after ~20 seconds in Chrome Deskop v47+\\n}]);\",\n      \"language\": \"javascript\"\n    }\n  ]\n}\n[/block]\n## Can manifest.json, OneSignalSDKWorker.js, and OneSignalSDKUpdaterWorker.js be served from a subfolder of my site?\n\n**manifest.json**\n\n- This file can be served from any subfolder of your site and the file can be named however you would like. Just be sure to include the file with the correct path and filename.\n- On Chrome, this files must still be served from your site (cannot be served from a CDN or another site). On Firefox and Safari, the manifest.json is not used for push notifications at all.\n\n**OneSignalSDKWorker.js & OneSIgnalSDKUpdaterWorker.js**\n\n- These files should not be renamed and the files should be served from the top-level root\n- Alternatively, these two files can be served from a sub-directory only if these two files are served with an additional HTTP header \"Service-Worker-Allowed: /\". These two files make up our service worker, a background web worker to display notifications. Parts of our web SDK depend on the service worker being registered properly: it should be served with the HTTP header \"Service-Worker-Allowed: /\" if served from a subfolder, otherwise it should be served at the top-level root of your site.\n\nIf the files are served with the HTTP header \"Service-Worker-Allowed: /\", please add this code **before** initializing the SDK:\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"var OneSignal = OneSignal || [];\\nOneSignal.push(function() {\\n  // Be sure to call this code *before* you initialize the web SDK\\n  \\n  // This registers the workers at the root scope, which is allowed by the HTTP header \\\"Service-Worker-Allowed: /\\\"\\n  OneSignal.SERVICE_WORKER_PARAM = { scope: '/' };\\n});\",\n      \"language\": \"javascript\"\n    }\n  ]\n}\n[/block]\nIf the files are served from a subfolder, please add this code **during** the initialization options so our SDK knows where to find the workers:\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"// Do NOT call init() twice\\nOneSignal.push([\\\"init\\\", {\\n  // Your other init options here\\n  path: '/subfolder/', /* A trailing slash is required */\\n}]);\",\n      \"language\": \"javascript\"\n    }\n  ]\n}\n[/block]","excerpt":"","slug":"customizing-features","type":"basic","title":"Customizing Features"}

Customizing Features


*Note:* WordPress users, customizing all of the features below can be found on the Configuration tab of our plugin. ## How do I hide the notify button after subscribing, or only show it on certain pages? The notify button init options takes in a `displayPredicate` function which is evaluated before the notify button is shown. To hide the notify button, this function must return the value `false` *or* a `Promise` that resolves to the value `false`. You may return any other value to show the notify button. Here is an example *hiding* the notify button if the user is subscribed: [block:code] { "codes": [ { "code": "// Do NOT call init() twice\n// This is just an example\nOneSignal.push([\"init\", {\n /* Your other init options here */\n notifyButton: {\n /* Your other notify button settings here ... */\n enable: true,\n displayPredicate: function() {\n return OneSignal.isPushNotificationsEnabled()\n .then(function(isPushEnabled) {\n /* The user is subscribed, so we want to return \"false\" to hide the notify button */\n return !isPushEnabled;\n });\n },\n }\n}]);", "language": "javascript" } ] } [/block] ## How do I customize or disable the automatic welcome notification when a new site visitor subscribes? Use the `welcomeNotification` parameter in your [init()](https://documentation.onesignal.com/docs/website-sdk-api#init) options. The `url` parameter is, by default, set to a special value that, on Chrome and Firefox, disables the notification from opening a separate webpage. By default, Safari must open a webpage and it will default to your site's URL. You may optionally set `url` so the notification opens a separate URL (on Chrome, Safari, and Firefox). **Showing a Welcome Notification** [block:code] { "codes": [ { "code": "// Do NOT call init() twice\nOneSignal.push([\"init\", {\n /* Your other init options here */\n welcomeNotification: {\n \"title\": \"My Custom Title\",\n \"message\": \"Thanks for subscribing!\",\n // \"url\": \"\" /* Leave commented for the notification to not open a window on Chrome and Firefox (on Safari, it opens to your webpage) */\n }\n}]);", "language": "javascript" } ] } [/block] **Disabling Welcome Notifications** [block:code] { "codes": [ { "code": "// Do NOT call init() twice\nOneSignal.push([\"init\", {\n welcomeNotification: {\n disable: true\n }\n}]);", "language": "javascript" } ] } [/block] ## How can I change the language / text of the subscription prompt pop-up window? [block:html] { "html": "<img src=\"http://i.imgur.com/v8I93BL.png\" style=\"background: url(http://i.imgur.com/v8I93BL.png) no-repeat 0 0;\tbackground-size: contain;\theight: auto;\tmax-width: 100%; margin: 0 auto; display: block;\"/>" } [/block] **Note**: This does not apply to Safari's permission prompt. This only applies to the HTTP prompt on Chrome and Firefox. Use the `promptOptions` parameter in your [init()](https://documentation.onesignal.com/docs/website-sdk-api#init) options. You may change all text except the URL on the notification image (subdomain.onesignal.com). You may enter text in your own language, but please note all fields are limited in length (usually to one line of text). Unset fields use their defaults. **Customizing the Pop-Up Text** [block:code] { "codes": [ { "code": "// Do NOT call init() twice\nOneSignal.push([\"init\", {\n // Your other init options here\n promptOptions: {\n /* Change bold title, limited to 30 characters */\n siteName: 'OneSignal Documentation',\n /* Subtitle, limited to 90 characters */\n actionMessage: \"We'd like to show you notifications for the latest news and updates.\",\n /* Example notification title */\n exampleNotificationTitle: 'Example notification',\n /* Example notification message */\n exampleNotificationMessage: 'This is an example notification',\n /* Text below example notification, limited to 50 characters */\n exampleNotificationCaption: 'You can unsubscribe anytime',\n /* Accept button text, limited to 15 characters */\n acceptButtonText: \"ALLOW\",\n /* Cancel button text, limited to 15 characters */\n cancelButtonText: \"NO THANKS\"\n }\n}]);", "language": "javascript" } ] } [/block] ## How can I enable or disable the notify button? How can I change the text or its behavior? Use the `notifyButton` parameter in your [init()](https://documentation.onesignal.com/docs/website-sdk-api#init) options. **Customizing the Notify Button** [block:code] { "codes": [ { "code": "// Do NOT call init() twice\nOneSignal.push([\"init\", {\n /* Your other init options here */\n notifyButton: {\n enable: true, /* Required to use the notify button */\n size: 'medium', /* One of 'small', 'medium', or 'large' */\n theme: 'default', /* One of 'default' (red-white) or 'inverse\" (white-red) */\n position: 'bottom-right', /* Either 'bottom-left' or 'bottom-right' */\n offset: {\n bottom: '0px',\n left: '0px', /* Only applied if bottom-left */\n right: '0px' /* Only applied if bottom-right */\n },\n prenotify: true, /* Show an icon with 1 unread message for first-time site visitors */\n showCredit: false, /* Hide the OneSignal logo */\n text: {\n 'tip.state.unsubscribed': 'Subscribe to notifications',\n 'tip.state.subscribed': \"You're subscribed to notifications\",\n 'tip.state.blocked': \"You've blocked notifications\",\n 'message.prenotify': 'Click to subscribe to notifications',\n 'message.action.subscribed': \"Thanks for subscribing!\",\n 'message.action.resubscribed': \"You're subscribed to notifications\",\n 'message.action.unsubscribed': \"You won't receive notifications again\",\n 'dialog.main.title': 'Manage Site Notifications',\n 'dialog.main.button.subscribe': 'SUBSCRIBE',\n 'dialog.main.button.unsubscribe': 'UNSUBSCRIBE',\n 'dialog.blocked.title': 'Unblock Notifications',\n 'dialog.blocked.message': \"Follow these instructions to allow notifications:\"\n }\n }\n}]);", "language": "javascript" } ] } [/block] **Customizing the Notify Button's Colors** You can override the theme's colors by entering your own. Values are strings which are then interpreted by CSS, so any CSS-valid color works as each value. For example, `white`, `#FFFFFF`, `#FFF`, `rgb(255, 255, 255)`, `rgba(255, 255, 255, 1.0)`, and `transparent` are all valid values. [block:code] { "codes": [ { "code": "// Do NOT call init() twice\nOneSignal.push([\"init\", {\n // Your other init options here\n notifyButton: {\n enable: true, // Required to use the notify button\n // Your other notify button settings here\n colors: { // Customize the colors of the main button and dialog popup button\n 'circle.background': 'rgb(84,110,123)',\n 'circle.foreground': 'white',\n 'badge.background': 'rgb(84,110,123)',\n 'badge.foreground': 'white',\n 'badge.bordercolor': 'white',\n 'pulse.color': 'white',\n 'dialog.button.background.hovering': 'rgb(77, 101, 113)',\n 'dialog.button.background.active': 'rgb(70, 92, 103)',\n 'dialog.button.background': 'rgb(84,110,123)',\n 'dialog.button.foreground': 'white'\n },\n }\n}]);", "language": "javascript" } ] } [/block] ## How can I automatically dismiss a notification after some time? On Firefox and Safari, notifications are automatically dismissed after a short amount of time. On Chrome, by default, notifications last indefinitely (they are displayed until the user interacts with it by dismissing it or clicking it). On Chrome Desktop v47+, you can add [the `persistNotification` parameter](doc:website-sdk-api#init) to your OneSignal init call to control whether a notification is displayed indefinitely or dismissed after 20 seconds. `persistNotification` defaults to true if unset. Set it to false to automatically dismiss the notification after 20 seconds (Chrome Desktop v47+ only). **Dismissing Notifications After ~20 Sec. (Chrome Desktop v47+)** [block:code] { "codes": [ { "code": "// Do NOT call init() twice\nOneSignal.push([\"init\", {\n // Your other init options here\n persistNotification: false // Automatically dismiss the notification after ~20 seconds in Chrome Deskop v47+\n}]);", "language": "javascript" } ] } [/block] ## Can manifest.json, OneSignalSDKWorker.js, and OneSignalSDKUpdaterWorker.js be served from a subfolder of my site? **manifest.json** - This file can be served from any subfolder of your site and the file can be named however you would like. Just be sure to include the file with the correct path and filename. - On Chrome, this files must still be served from your site (cannot be served from a CDN or another site). On Firefox and Safari, the manifest.json is not used for push notifications at all. **OneSignalSDKWorker.js & OneSIgnalSDKUpdaterWorker.js** - These files should not be renamed and the files should be served from the top-level root - Alternatively, these two files can be served from a sub-directory only if these two files are served with an additional HTTP header "Service-Worker-Allowed: /". These two files make up our service worker, a background web worker to display notifications. Parts of our web SDK depend on the service worker being registered properly: it should be served with the HTTP header "Service-Worker-Allowed: /" if served from a subfolder, otherwise it should be served at the top-level root of your site. If the files are served with the HTTP header "Service-Worker-Allowed: /", please add this code **before** initializing the SDK: [block:code] { "codes": [ { "code": "var OneSignal = OneSignal || [];\nOneSignal.push(function() {\n // Be sure to call this code *before* you initialize the web SDK\n \n // This registers the workers at the root scope, which is allowed by the HTTP header \"Service-Worker-Allowed: /\"\n OneSignal.SERVICE_WORKER_PARAM = { scope: '/' };\n});", "language": "javascript" } ] } [/block] If the files are served from a subfolder, please add this code **during** the initialization options so our SDK knows where to find the workers: [block:code] { "codes": [ { "code": "// Do NOT call init() twice\nOneSignal.push([\"init\", {\n // Your other init options here\n path: '/subfolder/', /* A trailing slash is required */\n}]);", "language": "javascript" } ] } [/block]