OneSignal Help & Documentation

Welcome to the OneSignal New IA developer hub. You'll find comprehensive guides and documentation to help you start working with OneSignal New IA as quickly as possible, as well as support if you get stuck. Let's jump right in!

Get Started    Discussions

Auto-Segment By Subscription Page

Web Push common setup feature for targeting users based on the page, author and/or site URL in which they subscribed.

To gain a lot of subscribers, you should prompt them and let them know why they should subscribe.

For example, if you’re a news publisher, add the prompt: “Subscribe to notifications to get more stories by this author.” If you’re an ecommerce site, add the prompt: “Subscribe to notifications to get special offers.”

With just a little bit of code, we can keep track of what page the user was on when they subscribed. This way, you can send them news stories and offers on products that are relevant to them.

Here’s how it works…

1. Engage and Prompt the User

Give the user time to decide that they want push notifications. It is recommended to prompt users after a delay of some sort, either time-based or number of visits. See our Slide Prompt Documentation on how to customize the prompt and add a delay.

2. Tag Them Based on Page Data

Once the user subscribes, now is the chance to tag them based on the page data. We provide the Subscription Change Event and Send Tags methods to accomplish this.

We recommend reading more on Adding Data Tags later since this is a very powerful feature that is super easy to use once you try them.

For now, when the Subscription Change event shows isSubscribed === true, that means the user subscribed on this page in which you can then tag them with the sendTags method

Here is an example of what you would add to your pages to do this:

let page_author = 'the author';
let page_topic = 'the topic';

OneSignal.push(function() {
    OneSignal.on('subscriptionChange', function(isSubscribed) {
        if (isSubscribed === true) {
            console.log('The user subscription state is now:', isSubscribed);
            OneSignal.sendTags({
                "page_url": window.location.href,
                "author": page_author,
                "topic": page_topic,
            }).then(function(tagsSent) {
                // Callback called when tags have finished sending
                console.log(tagsSent);
            });
        }
    });
});

In this example, "page_url", "author", and "topic" are all the tag keys while window.location.href, page_author and page_topic are the tag values.

The values here are variables that you would set based on the page's topic and author. Common topics would be "news", "entertainment", "politics", "finance", "tech", etc.

As soon as you add this data to your users, you can now target subscribers based on topics and authors they are interested in using Segments or Api Filters.

For example, whenever I publish new articles on "tech" I can now send notifications to all my tech subscribers.


Auto-Segment By Subscription Page


Web Push common setup feature for targeting users based on the page, author and/or site URL in which they subscribed.

Suggested Edits are limited on API Reference Pages

You can only suggest edits to Markdown body content, but not to the API spec.