How to Enable OneSignal Web Push Notifications SendTag For Drupal (User Segmentation by Interests)

| Servers & Config | 40 seen

I spent a good amount of time, trying to learn how to implement a better user segmentation on OneSignal. The best I could get so far was the default OneSiganal's out of the box segmentation based on user country.

As my blog covers many mutually unrelated topics, I was not utilizing the power of push notifications at 100%. In fact, after getting more than 26,000 subscribers (over a year) I felt afraid every-time I sent out a web push notification, as user targeting was very poor.

At OneSignal official documentation, I learned about using Data Tags, especially SendTag and SendTags

Once you've integrated OneSignal in your app or website, implementing tags is very straightforward - simply use the sendTag or sendTags methods to tag your users with a key-value pair at any time. You may also get and delete tags with other methods. To learn more and to check out code examples, dive into the SDK reference for your particular app or website.

Here is the code example, you should call

OneSignal.push(function() {
  /* These examples are all valid */
  OneSignal.sendTag("key", "value");
               
  OneSignal.sendTag("key", "value", function(tagsSent) {
    // Callback called when tags have finished sending
  });
               
  OneSignal.sendTag("key", "value").then(function(tagsSent) {
    // Callback called when tags have finished sending
  });  
});

As it was hard to understand what to do next, I thought about following "workaround" using Drupal blocks, before diving in, here are the things you will need:

Now, create a new block and paste in (using php filter) following code:

<script>
OneSignal.push(function() {
  OneSignal.sendTag("category", "investments");         
});
</script>

Where category = key and investments = value

Make sure to enable check box to display this block on investments category only. Also, you should put this block somewhere in enabled block regions to make it work. As I'm using custom MailChimp subscribe forms for collecting e-mail at te the end of articles, I put this code inside MailChimp block.

How to add MailChimp Signup Form for Drupal

For tracking multiple categories create new block, with new key and value, for example


<script>
OneSignal.push(function() {
  OneSignal.sendTag("category1", "shopping");         
});
</script>

And so on. 

In case user has already subscribed at investment page, but after is visiting shopping page, both values will be recorded:

Collecting user tags on OneSignal

Collecting user tags on OneSignal

 

Latest articles

How to Trade the NVDA Wheel Strategy Using Covered Calls and Cash-Secured Puts

The Ultimate NVDA Options Strategy Guide: Cash-Secured Puts, Covered Calls & Credit SpreadsNVIDIA (NASDAQ: NVDA) has become one of the most actively traded stocks in the world. Between the AI boom, extreme volatility, institutional demand, and highly liquid options market, NVDA has evolved into a unique environment for systematic options…

Options trading |
Embedded thumbnail for Spring in Georgia: Morel Hunting, Gori Food Stop &amp; Stunning Gorijvari Views

Spring in Georgia: Morel Hunting, Gori Food Stop & Stunning Gorijvari Views

Shot at the end of April 2026, on a calm and lovely Sunday morning, this video started with a simple plan: go out and hunt for morels -  murķeļi. Spring, fresh air, perfect timing… everything looked right.But plans shifted quickly.After the first attempts turned up nothing, we didn’t push too hard — instead, we adapted. Rather than chasing…

Living in Georgia |