• Resolved lolo343

    (@lolo343)


    [ 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

Viewing 4 replies - 1 through 4 (of 4 total)
  • Thread Starter lolo343

    (@lolo343)

    I also changed this :
    window.OneSignal.registerForPushNotifications();

    by :
    window.OneSignal.showHttpPrompt();

    The registration window appears right away, but when I scan the code I get an error message that appears after the 12-second delay

    Thread Starter lolo343

    (@lolo343)

    this is the error message :

    tslib.es6.js:62 Uncaught (in promise) InvalidStateError {description: "RedundantPermissionMessage", reason: 1, message: "Another permission message (SlidedownPermissionMessage) is being displayed.", name: "InvalidStateError", stack: "InvalidStateError: Another permission message (Sli…m/sdks/OneSignalSDK.js:1:1486)?    at <anonymous>"}description: "RedundantPermissionMessage"reason: 1message: "Another permission message (SlidedownPermissionMessage) is being displayed."name: "InvalidStateError"stack: "InvalidStateError: Another permission message (SlidedownPermissionMessage) is being displayed.?    at Function.<anonymous> (https://cdn.onesignal.com/sdks/OneSignalSDK.js:1:139123)?    at i (https://cdn.onesignal.com/sdks/OneSignalSDK.js:1:2384)?    at Object.next (https://cdn.onesignal.com/sdks/OneSignalSDK.js:1:1719)?    at s (https://cdn.onesignal.com/sdks/OneSignalSDK.js:1:1486)?    at <anonymous>"__proto__: t
    s @ tslib.es6.js:62
    • This reply was modified 7 years, 4 months ago by lolo343.
    Thread Starter lolo343

    (@lolo343)

    Has anyone successfully implemented this option on wordpress ?

    Hi lolo343,

    Sorry for the confusion in getting the prompts to work. Could you reach out to us at [email protected] with:

    a) A publicly available URL to your site (to reproduce the issue)
    b) A link to this support thread

    We’ll reproduce the error to figure out what the code that’ll work for your case. Thanks!

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Onesignal delay prompt’ is closed to new replies.