Custom Code for OneSign Push Notifications

Below OneSign custom code will do the follow features:

  • Show small subscription bell only when users are not subscribed yet
  • Hide the OneSign logo
  • Delay subscription request prompt
  • Customize notification text
  • Send custom notification welcome message



Generate and upload SDK files then add below code in HTML header

<link rel="manifest" href="/manifest.json">
<script src="" async></script>
<script src="/onesignal-moddiy.js" async></script> 

In onesignal-moddiy.js file

var OneSignal = window.OneSignal || [];
OneSignal.push(function() {
		appId: "f0964f83-6f53-4152-b9bd-aee6ee68a440",
		autoResubscribe: true,
		autoRegister: false,
		notifyButton: {
			enable: true,
			size: 'small',
			theme: 'default',
			position: 'bottom-left',
			showCredit: false,
			prenotify: true,
			displayPredicate: function() {
				return OneSignal.isPushNotificationsEnabled()
				.then(function(isPushEnabled) { return !isPushEnabled;});
			text: {
				'tip.state.unsubscribed': 'Get instant discount coupon',
				'tip.state.blocked': "You've blocked instant discount coupon",
				'message.prenotify': 'Click to get instant discount coupon',
				'dialog.blocked.title': 'Unblock Instant Coupon',
				'dialog.blocked.message': "Follow these instructions to allow instant discount coupons and important notifications:"
		welcomeNotification: {
			"title": "Thank you for subscribing!",
			"message": "Get 10% off all products today, please use coupon code PU10SH, enjoy :)",
			"url": ""
	var notificationPromptDelay = 15000;
	var navigationStart = window.performance.timing.navigationStart;
	var timeNow =;
    setTimeout(promptAndSubscribeUser, Math.max(notificationPromptDelay - (timeNow - navigationStart), 0));

function promptAndSubscribeUser() {
	window.OneSignal.isPushNotificationsEnabled(function(isEnabled) {
		if (!isEnabled) {
			OneSignal.push(function() {OneSignal.registerForPushNotifications();});

Leave a Reply

Your email address will not be published. Required fields are marked *