OneSignal FREE plugin for FREE and UNLIMITED Push Notifications šŸ“±

Hi, everyone

Big thanks to @mvandrei for this initiative great contribution for everyone. Iā€™m currently developing a web app only. Iā€™ve done exactly what @mproto1 shown but still not working.

Hereā€™s my set up.

The script will run only when PlayerID is empty

Then I do the trigger instantly
02

03

04

and put the script somewhere in the page

Anything wrong?

1 Like

Hey,

@all sorry for disappearing like this.
I know internet is all against TMI, so I will be as short as possible.
I had my dog ill, the doctors believed it was cancer, andā€¦after 6 months ITā€™S NOT! Yesterday was the last day of treatment and sheā€™s okay! (turned 6 years old on Christmas). She also had to have a kidney removedā€¦ and a few other ā€˜real lifeā€™ issues that I had to take care of.
Soā€¦ in a nutshell this is why I was absent.
My bubble app is almost ready thanks to a wonderful, talented freelancer whom worked around the clock at it.
Iā€™ve started all this as an alternative to bringing the bubble app to mobile as well. So I shared my success on that.
Then I needed push notifications so I did the same. I went ahead and build a plugin for myself since the one made by codurly didnā€™t work as intended (for me at least). It lacked exactly what I needed: mobile support. And since I did it for me I thought I could share it with you guys.
I didnā€™t realize that I need multiple devices under same account, and then a few other things along the way.
The plugin works, but I canā€™t say for sure why it doesnā€™t for everybody.
Those that have it working are not on the thread or didnā€™t came back to say it works (happens to us too, so no blame here).
Since my app is almost finished, I need to finish this too. So I will refresh it, make sure it works on ALL platforms, easy install (maybe some reusable elements where I can do that) and a simple and clean tutorial.
It will take ā€¦ maybe 1 month to finish the app, so around this date will have the plugin refreshed with tutorial and everything.
A bit late to the party but: Happy Holidays and Happy New Year!

6 Likes

Thanks you for all this @mvandrei itā€™s been so helpful. I think Iā€™ve found the issue with the PlayerID not being pulled into the DB when running on an Android device, and itā€™s line 84 which errors - if(device.ios())

That may explain why others canā€™t get it stored into their DB. Iā€™ll have a go and rewriting some parts of it later, with your permission. It works fine with iOS.

Sure, go ahead.
The latest version of the plugin is detecting the os and platform automatically: ios/android, mobile/desktop etc.
So it will be even easier to set it up, the plugin will do all the work.

Hi @mvandrei

Iā€™ve found that by changing the following line from:

if(device.ios()){

to:

if (window.isIOS()) {

Allows for the script to get the PlayerID (when running through Superview on Android) correctly. Previously, that was erroring for me, but now it works on both platforms. Not sure if that could be something to do with the device I was using or not but thought it was worth mentioning anyway.

Trying to see JavaScript errors when running through Superview I found was a little tricky so by adding this function into the script, will make any errors popup as an alert, which just makes debugging the script a little easier thatā€™s all. It can be removed afterwards.

window.onerror = function(msg, url, linenumber) {
  alert('Error message: ' + msg + '\nURL: ' + url + '\nLine Number: ' + linenumber);
  return true;
}

The JS script which Iā€™m currently using at the moment and works for me on both devices, currently looks like thisā€¦

(function() {

  if (window.isIOS) {
    return
  }
  window.isIOS = function() {
    return navigator && navigator.userAgent && (/(iPhone|iPad|iPod|iOS)/i.test(navigator.userAgent))
  }
}());

(function() {
  if (window.bridge) {
    return
  }
  window.bridge = function() {
    var callbacks = [],
      callbackID = 0,
      registerHandlers = [];
    document.addEventListener("PacificDidReceiveNativeCallback", function(e) {
      if (e.detail) {
        var detail = e.detail;
        var id = isNaN(parseInt(detail.id)) ? -1 : parseInt(detail.id);
        if (id != -1) {
          callbacks[id] && callbacks[id](detail.parameters, detail.error);
          delete callbacks[id]
        }
      }
    }, false);

    document.addEventListener("PacificDidReceiveNativeBroadcast", function(e) {
      if (e.detail) {
        var detail = e.detail;
        var name = detail.name;
        if (name !== undefined && registerHandlers[name]) {
          var namedListeners = registerHandlers[name];
          if (namedListeners instanceof Array) {
            var parameters = detail.parameters;
            namedListeners.forEach(function(handler) {
              handler(parameters)
            })
          }
        }
      }
    }, false);

    return {
      "post": function(action, parameters, callback, print) {
        var id = callbackID++;
        callbacks[id] = callback;
        if (window.webkit && window.webkit.messageHandlers && window.webkit.messageHandlers.pacific) {
          window.webkit.messageHandlers.pacific.postMessage({
            "action": action,
            "parameters": parameters,
            "callback": id,
            "print": print || 0
          })
        }
      },
      "on": function(name, callback) {
        var namedListeners = registerHandlers[name];
        if (!namedListeners) {
          registerHandlers[name] = namedListeners = []
        }
        namedListeners.push(callback);
        return function() {
          namedListeners[indexOf(namedListeners, callback)] = null
        }
      },
      "off": function(name) {
        delete registerHandlers[name]
      }
    }
  }()
}());

//shows any errors as an alert
window.onerror = function(msg, url, linenumber) {
  alert('Error message: ' + msg + '\nURL: ' + url + '\nLine Number: ' + linenumber);
  return true;
}

function getOneSignalToken() {
  window.bridge.post('onesignaltoken', {}, (results, error) => {
    id = results.token;
  })
}

if (window.isIOS()) {
  getOneSignalToken();
  console.log("its ios");
} else {
  console.log("its not ios");
  id = android.getOneSignalRegisteredId();
}

setTimeout(function codeAddress() {
  bubble_fn_1(id);
}, 1000);

I hope it helps somewhat.

1 Like

Hi,

Just to carry on sharing any info/problems Iā€™ve had today, hereā€™s something else which may help others.

Donā€™t get confused with what @mvandrei has put up previously though as his great solution has worked for most, this is just what Iā€™ve found that worked/didnā€™t work for me and what Iā€™ve done to make it work!

I found when the JS ran, my JavascripttoBubble value was being set correctly with the playerID but if I then tried to use that JavascripttoBubbleā€™s value in any workflowā€™s after that JS, all that happened was a blank value was put into my player ID field for the current user in the DB. It was a bit strange because it clearly had a value, I could create a text element and give it a dynamic value of ā€œJavascripttoBubbleā€™s X valueā€ and I could see it fine. I just couldnā€™t use it within the same workflow as it was blank all the time.
Made no sense to me.

So to get around this, I did the following:

Put a tick in the box which Trigerā€™s an event:

image

Then replaced the Custom workflow with a ā€œJavaScript To Bubble Eventā€ and move the action which modifies the current user into it. That way, when the JS sets the value, the event gets triggered automatically and that worked for me.

I also simplified the JS workflow to this:
image

I only have the 2 now, one runs the JS when the Page is Loaded AND the Current User is Logged In.
The other gets Triggered when the JavascripttoBubbleā€™s value is changed.
I removed the Pause and the Custom Event that was before.

Hope it helps someone!

I have the API key from the project inside of OneSignal but when i put it in to the ā€˜authorizationā€™ section it still doesnā€™t work.

Where is it supposed to go?

Do i need all of the other settings too? If so, where do i find those?

image

id = android.getOneSignalRegisteredId();

this line of error as ā€œandroidā€ unspecified

in the script put in what form?

Hi @JustinC

This is what I have in all those Plugin valuesā€¦

Hi @contato

When is the error occurring? Does it occur as soon as you preview your page through a browser (all browsers?) (ie when itā€™s first loaded?) or on an Android device/iOS device only? or every time regardless of where itā€™s loaded from?

Iā€™m probably missing some basic thing, but hereā€™s the only workflow option I see in the OneSignal Web notifications plugin:

Iā€™m trying to figure out how to send individual notifications to people - is anyone able to point me in the right direction? (I donā€™t see an option to set the playerId as a recipient there)

(I understand that a preliminary step to doing this would be registering the user as a player, but once thatā€™s done, how do i sent individual notifications?)

Thanks in advance!

That looks like the ā€œOneSignal - Web Notificationā€ plugin, look for the ā€œOneSignal - Push Notificationā€ plugin.

Will those work on the web? Or only in iOS/Android apps?

(Iā€™m trying to get a web-based solution going)

Ah ok, hadnā€™t realised that. So to get push notifications working with the Superview App for iOS/Android youā€™d need the OneSignal Push Notification plugin. For what you require, i.e. just the web based solution, web notifications then youā€™re right itā€™s the OneSignal - Web Notification plugin and for that one you donā€™t need any of the JS script stuff thatā€™s mentioned in this rather long post. Actually I tried getting that working for myself too and I managed to get there but with some hassles.

My configuration I used looked like this:

There shouldnā€™t be much configuration apart from the above required, if you get all that right then as soon as you launch your site, you should get prompted with a browser message asking you want to accept notifications and then you can use the only action available to populate which is the one your image shows. I wanted to do the same thing though, push a web notification out to a specific player ID and I wasnā€™t able to because there was no player ID available to use in that action (like there is with @mvandrei plugin)

Instead I think it uses Segments instead, so when you look in your OneSignal account, you see something like thisā€¦

These are the 4 default segments which you can use. Itā€™s great if you have 50 Active Users for example (in the Active Users segment) because you can use that one action to send a message to all of them but in my opinion I think the plugin could do with an additional option which would allow you to send not only to segments but to an individual player ID, I donā€™t think it will do that though.

Your only other option is use the Bubble API Connector and send one that way. It can be done, I got as far as what shows in the following screenshot but I canā€™t remember now if I ever got it to work, one day Iā€™ll end up revisiting it!

1 Like

Youā€™ll need to also get the PlayerID into the Bubble database, this is how you do itā€¦

Once you have the OneSignal - Web Notification plugin installed and configured, when you open your site it should prompt you with something like this (depending on how you have the notifications configured in your OneSignal settings.

If youā€™re not seeing that popup, then try closing the browser and re-opening (not just refreshing site) and check the configuration in the Settings area in your OneSignal account.

It will be in here, make sure you have it setup correctly, you have the Permission Prompt Setup completed and the Label is in your Plugin settings.

image

When the user clicks ALLOW and accepts any other prompts afterwards, thatā€™s when the user gets registered in OneSignal and when that happens, the Player ID is stored in your browser which we can retrieve by running a small JS script. In order for this JS script to work, youā€™ll want to upload the 3 SDK files which can be found here: https://github.com/OneSignal/OneSignal-Website-SDK/releases/download/https-integration-files/OneSignal-Web-SDK-HTTPS-Integration-Files.zip to the root of your siteā€¦ @mvandrei maybe we can put these SDK files into your plugin?

Then you can run this is in the Console:
OneSignal.getUserId(function(id){console.log(id)});

If you donā€™tā€™ have the SDK files uploaded correctly youā€™ll see this returned:

image

And if you do have them installed correctly, then youā€™ll get this:

image

Now set yourself up with a Run javaScript action with the JS in it, use the JavascripttoBubble event too and you should be able to get it into the Current User fields. If youā€™re not sure on how to that part let us know and Iā€™ll go into more detail, running out of time right now.

We should be able to put all this into another plugin with the API call in there to make it easier for ourselvesā€¦ OR if @mvandrei if youā€™re there, maybe we add it to your Plugin!!

2 Likes

thanks for the update @pork1977gm. I will bring something even cooler than what Iā€™ve provided by now, in about 10 days. Then, I will update the plugin right after. We need to keep track of devices, and be sure we donā€™t re-register an PID over an existing one, so replacing the old one from another device, OR not register it if itā€™s already there (from another device) e.g.: phone, tablet and computer/laptop.

1 Like

Yep, ok understood, all good!

1 Like

is giving this message on the Android studio console
Iā€™m trying to get the ID to send individual notification, Iā€™m using OneSignal Push Notification and with SuperView

Awesome @pork1977gm, thanks.

@mvandrei, are you still planning on adding these options into a the plugin for OneSignal Web Notifications?

(meaning: should i wait a week for that and just use the plugin?)