Skip to main content

How to integrate one signal push notification in website (Laravel)?

Integrate one signal push notification

    <script src="https://cdn.onesignal.com/sdks/OneSignalSDK.js" async=""></script>
    <script>
    var OneSignal = window.OneSignal || [];
        var initConfig = {
            appId: "{{ env('OneSignalApp_ID') }}",
            notifyButton: {
                enable: true
            },
        };
        OneSignal.push(function () {
            OneSignal.init(initConfig);
            console.log(OneSignal);
        });
        OneSignal.push(function() {
/*             OneSignal.isPushNotificationsEnabled(function(isEnabled) {
                if (isEnabled)
                console.log("Push notifications are enabled!");
                else
                console.log("Push notifications are not enabled yet.");    
            }); */

            OneSignal.isPushNotificationsEnabled(function(isEnabled) {
            if (isEnabled) {
                // user has subscribed
                OneSignal.getUserId( function(userId) {
                    console.log('player_id of the subscribed user is : ' + userId);
                    if($("#one_signal_player_id").length > 0){
                        $("#one_signal_player_id").val(userId);
                    }
                    // Make a POST call to your server with the user ID        
                });
            }
            });
        });
        </script>

Comments

Popular posts from this blog

How to check date format in PHP?

Check date format in PHP function isCorrectDateFromat($date){     if(!empty($date)){         $dateString = $date; // Replace this with your date string         $format = "Y-m-d"; // Replace this with your expected date format         $dateTime = DateTime::createFromFormat($format, $dateString);         if ($dateTime === false) { /*             echo "The date is not in the correct format."; */         } else {             $errors = DateTime::getLastErrors();             if (empty($errors)) { /*                 echo "The date is in the correct format."; */                 return true;             } else { /*                 echo "...