Knack & OneSignal for push notifications

Does anyone have experience using OneSignal for push notifications in Knack?

I've got a basic setup using OneSignal to send web push notifications to subscribed users of my app. By default OneSignal assigns a UserID on it's own to new subscribers, independent of any Knack user account info, but apparently it's possible to send Knack info (user's email/name/KnackID, etc.) to OneSignal when a user subscribes to the push notifications.

Does anyone have a set up like this they'd be willing to share the code/insight on? Particularly assigning/paring Knack fields to OneSignal Tags.

Never mind, it works great. I had the alert symbol turned off if a person was already subscribed, which I was.

I couldn't get this code to work. I'm not a coder either. Are you still using this code in your JavaScript section of your app?

Code looks good to me (I'm no expert though) - there's always different ways to do things but if it works...

Thinking you could trigger a OneSignal message inside Knack using the knack-render-update event without needing Zapier - see https://www.knack.com/developer-documentation/#record-update-form

I did a bit more research and got it working for the most part thanks to Knack's getUserAttributes() function. Here's what I've got, although I'm not a coder by any stretch of the imagination so I'm sure it looks like a hot mess to anyone who knows what they're actually doing.

Once you go through the initial OneSignal setup, it populates a couple scripts that need to be appended/inserted into the header of your Knack app, which I've done with the first two code sections below. You can then use Knack's GetUserAttribues() function and assign the results to variables which get passed on to OneSignal when a user clicks on the Subscribe bell that OneSignal overlays on your app.

My use case is a 'Fly-In' meeting app, and I'll use the push notifications to notify attendees when there are last minute changes to their meeting times/locations on the day of the event. Next step is looking into creating a simple Zapier zap to send the push notification whenever a meeting record changes. Only hiccup so far is that as far as I can tell, getUserAttribues() doesn't pull any connected records that are part of a user's account. It's not a deal breaker for me at this time though.


var script = document.createElement("script");
script.src = "https://cdn.onesignal.com/sdks/OneSignalSDK.js";
document.getElementsByTagName('head')[0].append(script);

var script2 = document.createElement("script");
script2.text = "var OneSignal = window.OneSignal || []; OneSignal.push(function() {OneSignal.init({appId: \"YOUR APP ID HERE\",}); });";
document.getElementsByTagName('head')[0].append(script2);

var name = Knack.getUserAttributes().name;
var email = Knack.getUserAttributes().email;

OneSignal.push(["sendTags", {name: name}]);
OneSignal.setEmail(email);

In a word - No.

But I'm very intrigued and by posting your working code we might be able to work out how to match Knack fields to OneSignal tags etc.

Keen to hear what your using it for as well!