Onesignal push notification advanced targeting - push-notification

I'm using onesignal to handle pish notification for both my web and ionic app. My question is
Can I setup user segments using server rest api ?
I want to give my users ability to subscribe to specific events (channels) to limit push notifications they receive.
Example
user1 subscribed to group I'd (1,3,8)
user2 groups(5,8,11)
User3 groups(12,13)
When event happened on groups 8.
How can I send push notifications to all users subscribed to group 8 ? -in my example above notification should be sent to user1 & user2 but not 3.

(Update: This answer is now out of date because OneSignal now supports dynamically creating segments, as well as a large range of additional capabilities introduced over the years)
OneSignal doesn't currently support dynamically creating segments through the API, however there is a better way to do what you need.
You can use the tags feature to assign custom data to users, and then you can deliver notifications to users who match specific tags. Tags are typically set by calling the SetTags method in your app, but they can also be set through the OneSignal API.
In your case, for instance, you would assign the following tags to each user:
User1 Tags: group1=true,group3=true,group8=true
User2 Tags: group5=true,group8=true,group3=true
User3 Tags: group12=true,group13=true
Next, through the OneSignal API, you can use the "tags" field to only deliver your notifications to users who match one or more tags.
You could also create a segment for each tag on the dashboard, then through the API or through the dashboard you could specify which segments (and therefore tags) should receive your notification.

The problem with the approach outlined by #Gdeglin is that you will need to manage your group information on both your server and OneSignal's. When you have 2 sources of truth for something as complex and dynamic as groups you're bound to run into trouble.
For example, what happens if Group 8 is deleted? In addition to updating your own database, you'd need to use the API to update all the OneSignal users who belonged to Group 8. Imagine that group contains 1000 users. Yuck.
Instead of adding groupname tags, add a "userId" tag to each user (Player) registered with OneSignal. Now when a group changes there is nothing to update with OneSignal.
The tradeoff is that sending a message to everyone in the group requires N API calls to OneSignal instead of just one. It looks like it's possible to supply multiple tag matches in a single API call, but it's not clear how well that scales.

Related

Java Google Calendar API: Send email notification when creating event

I am using java google calendar API. Whenever I create a new event I would like to send an email notification to all attendees.
I guess/expect there are 2 ways how to achieve that:
Set it as the calendar property
Set it ad hoc as property on the created event
I don't care which of these options I use but I don't know how to do it programmatically and I am struggling to find any example of the code.
As you can read in the documentation, about the sendUpdates parameter:
Whether to send notifications about the creation of the new event.
Note that some emails might still be sent. The default is false.
Acceptable values are:
"all": Notifications are sent to all guests.
"externalOnly": Notifications are sent to non-Google Calendar guests
only.
"none": No notifications are sent. This value should only be
used for migration use cases (note that in most migration cases the
import method should be used).
You can follow the insert Example besides the Quickstart to set the previous configuration, but take into account that there is an outdated dependency that makes you use the deprecated sendNotifications instead of sendUpdates:
compile 'com.google.apis:google-api-services-calendar:v3-rev305-1.23.0'
should be
compile 'com.google.apis:google-api-services-calendar:v3-rev401-1.25.0'
I already reported the issue to Google.
Assuming that you already have the object created event, with the list of attendees, the API call should be:
service.events().insert(calendarId, event).setSendUpdates("all").execute();

Mobile push notifications setup and user targeting

I am trying to setup Push notifications in the mobile app. I have decided to use OneSignal for this. This topic is completely new for me and I would like to know the best practices regarding Push notifications setup in terms of user targeting. From what I got from the Google and OneSignal documentation I can target different user in two ways:
In the mobile app assign some data tags to users, e.g. 'hasItems: true', or 'isInterestedInProduct' and then create segments in OneSignal console with these user tags.
Save OneSignal PlayerId on my backend, match it with the userId and then selectively send messages to the users depending on the backend database data.
What is the preferred way to do this? Or it should be the combination of both depending on my use cases?
Is there any way to make it fully automatized? E.g. based on some analytics events, create messages in OneSignal without any changes from the mobile/backend side (only setup the mobile sdk )?
It all depends on your use case.
For sending messages to users as a group, tags are a great way to support this. For example, you could tag all users interested in a specific product, or who have visited a specific page in your app. Here is OneSignal's guide on tags.
For sending messages to a small list of specific users, storing their OneSignal player_id or using the external_id feature of OneSignal is the way to go. Here is OneSignal's guide on sending these types of notifications.

firebase https link to change realtime database

Does anyone know if Firebase has the functionality for me to email a user with a yes/no question which in turn offers two links, if one of those links are clicked it then changes a specific value on a node in the database?
In my mind I would use a firebase function to email the user when a certain trigger occurs, and the body of that email would be a template where upon the two links can be added as needed.
I have been searching online but either am using the wrong key words or the functionality does not exist..
Yes, you can do this with Cloud Functions for Firebase. Essentially you would want to have two functions: one that sends the email and one that handles the links in the email.
If I were building it, I'd probably generate a secret token when I sent the email and store it along-side the question's data. In the email template, I'd then have the yes/no buttons point to my function URL like:
https://us-central1-myproject.cloudfunctions.net/respond?answer=yes&token={the_generated_token}
I'd then parse the answer and token from the query string in my respond function, verify that the secret token matches, and if so record the response. Once the response was recorded, I'd invalidate the secret token somehow so it could only be used once.

The API gives me identical resource-id for two different channels

I am using Google Calendar API and push notifications to add channels and watch those channels for new events that come in. However while tracking weird behavior with mixing calendar accounts and events I found out that the resource ID that the calendar API responded with is the same across two accounts.
I am not sure if this is the culprit yet but this is the definition of resource-ID from docs
X-Goog-Resource-ID - An opaque value that identifies the watched
resource. This ID is stable across API versions.
In my mind this means it should be unique. Resource-ID and channel-ID are a requirement for stopping channels after all.
Examples of identical resource-ID from google for two different accounts
Account 1
X-Goog-Resource-State: exists
X-Goog-Channel-Token: 56cab177e67348d9a17c7502a4bad513
X-Goog-Resource-ID: 8KXz6YKChAJDYMTUo0SoKqV8_7E
X-Goog-Channel-ID: ++7mlvx6pEIsTNeMpMwNLw==
Account 2
X-Goog-Resource-State: exists
X-Goog-Channel-Token: 4535832bc5cf47f7ae3403c404023bfd
X-Goog-Resource-ID: 8KXz6YKChAJDYMTUo0SoKqV8_7E
X-Goog-Channel-ID: mL+HzrG8/EYc7zRZdQ+6yw==
My question is, is this normal behaviour?
The push notifications channel does not provide updates on individual events. It only tells you when the calendar (collection of events) changed.
To find changes to events, you want to look up syncing.
With syncing, you send in a token you got from the last time you synced to the List API endpoint. Instead of listing all events, it will list only the ones that changed since your last since request, represented by the sync token.
You can POST to the List API any time you want to get changes to events, but the push notifications you described help tell you when there would be a meaningful change to call the sync.

Hierarchy of Google Analytics for Multiple Builds of Same App

I am setting up Google Analytics Accounts for a Product which have multiple builds as frontend for same user base.
So we have one Product called X and have:
Web Build
Mobile Web
Android App 1
iOS App 1
Android App 2
iOS App 2 6.
The main point is identical APIs and User base is used in all platforms and apps. So if we have a user John Doe he can login in any of the web or apps.
We want to extract following information from Google Analytics.
Under User ID feature want, sessions aggregations of that user around all build and apps, but identifiable. So I can know that user John login to web yesterday and used mobile app today.
Each user belong to a customer (company) in our system. So want to segregate all information based on companies.
I already have achieved point 2 by creating a custom dimension in Google Analytics and believe that's the best way to do it.
Now need suggestions from Gurus on how to acheive point 1 using Google Analytics.
Either use single account and single property for all builds and apps
If yes, then how to identify those apps and builds in sessions
If I use multiple properties/apps in GA account then how to aggregate user sessions among all?
Looking forward to hear how guys around hand or should have handled this scenario. Cheers!
This question is extremely broad, IMO any answer your going to get is going to be primarily opinion based. So here is my opinion and a little extra info to boot.
The first issue you are going to have is that there is a difference between Mobile google analytics accounts and web analytics accounts. The two do not mix. Mobile analytics accounts insert screen views with a screen name. While web accounts insert PageViews with a document location.
There is no way to analyze between two different Google analytics web properties. Unless you intend your android and ios apps to run as websites and send it like its a webpage its not going to work. You could potentially download the data into your own system or big query and analyze it there. Comparing your custom dimension to see what the users have done differently. I would wonder at the quality of the analysis you will get as there will be no real way for you to compare the data and match it up beyond using your custom dimensions user id and possibly date.
I am adding this because I am not sure what your saving in your custom dimension.
The second issue you are going to have is tracking. Google analytics TOS does not allow you to send any identifiable information to Google.
The Analytics terms of service, which all Analytics customers must adhere to, prohibits sending personally identifiable information (PII) to Analytics (such as names, social security numbers, email addresses, or any similar data), or data that permanently identifies a particular device (such as a mobile phone’s unique device identifier if such an identifier cannot be reset).
You could for example send your companies customer id for John as a user_id but user_id is an internal valuable used for internal processing this is not something you can extract out via the api.
The User ID enables the association of one or more sessions (and any
activity within those sessions) with a unique and persistent ID that
you send to Analytics.
To implement the User ID, you must be able to generate your own unique
IDs, consistently assign IDs to users, and include these IDs wherever
you send data to Analytics.
For example, you could send the unique IDs generated by your own
authentication system to Analytics as values for the User ID. Any
engagement, like link clicks and page or screen navigation, that
happen while a unique ID is assigned can be sent and connected in
Analytics via the User ID.
The best you could do would be to create a custom dimension and send that with every hit username=johnscustomerId. Which you appear to have already done. This is what I have done in the past and it works perfectly well.

Resources