Onesignal delay prompt
-
[ Moderator note: moved to Fixing WordPress. Please do not use Developing With WordPress for these topics. ]
Hello to the community, I am looking for someone who uses the plugin Onesignal (web push) on his website, and who has set up a delay for displaying the registration window.
I followed the one signal documentation and it does not work.First i have created a file named onesignaldelay.js with:
`window.OneSignal = window.OneSignal || [];
var notificationPromptDelay = 12000;
window.OneSignal.push(function() {
var navigationStart = window.performance.timing.navigationStart;
var timeNow = Date.now();
setTimeout(promptAndSubscribeUser, Math.max(notificationPromptDelay – (timeNow – navigationStart), 0)); });
function promptAndSubscribeUser() {
window.OneSignal.isPushNotificationsEnabled(function(isEnabled) {
if (!isEnabled) {
window.OneSignal.registerForPushNotifications();
} }); }`Then in a second time I added this code in the functions.php file to call the script :
function theme_js(){ wp_enqueue_script( 'onesignaldelay', '/wp-content/themes/wp-knowledge-base-child/js/onesignaldelay.js', array() ); } add_action( 'wp_footer', 'theme_js' );
I do not get errors in the crawler, but the 12-second timeout in the javascript file seems to have no effect.
Has anyone ever implemented this change ?
thank you in advance for your help
- The topic ‘Onesignal delay prompt’ is closed to new replies.