- OneSignal Web SDK installed and initialized on your site
- Familiarity with Tags and Segments
Setup
1. Tag users with page-specific metadata
When a user subscribes to push notifications, use thePushSubscription.addEventListener listener to detect the opt-in and apply tags with contextual data about the page they were viewing.
- The
changeevent fires when the userโs push subscription state changes (opt-in, opt-out, token refresh). event.current.optedInistruewhen the user has an active subscription. Checking!event.previous.optedInensures tags are only applied on the initial opt-in, not on every state change.window.location.pathname.split('/')[1]captures the first path segment as the subscription context. For example, if the URL ishttps://example.com/gaming/article-123, thesubscription_pagetag is set togaming.pageTopicis extracted from a<meta>tag, falling back to'general'. Adjust this to match your siteโs metadata structure.
2. Segment users by tag
Once tags are applied, use Segments or API Filters to target users based on those tags. For example:- Send a campaign to users where
subscription_pageisgaming - Create dynamic segments based on tag values and timing (e.g., hours since first session)
3. Automate follow-up messaging
Build drip-style campaigns that trigger messages based on when the user subscribed and what content they subscribed under. Example: Drip campaign for gaming subscribers| Segment name | Filters | Description |
|---|---|---|
| Gaming 1 | subscription_page = gaming AND First Session > 2h AND < 24h | Reach out 2โ24 hours after subscription |
| Gaming 2 | subscription_page = gaming AND First Session > 24h AND < 48h | Follow up 1 day later |
| Gaming 3 | subscription_page = gaming AND First Session > 72h AND < 96h | Final check-in after 3 days |
Use upper time limits (
<) to prevent users from lingering in segments once the messaging window has passed.4. Combine segments with message templates
Once segments are created:- Build Templates for each stage in the campaign (e.g., intro, reminder, promo).
- Use Journeys to send these messages when users enter the appropriate segment.
- Invite to a gaming community or social group
- Recommend trending articles related to their topic
- Send an exclusive offer or discount code
Best practices
- Use meaningful tag names and values that reflect actual user intent.
- Extract tag values dynamically from page metadata when possible.
- Only tag on the initial opt-in โ the listener example above checks
!event.previous.optedInto avoid re-tagging on every state change.
FAQ
Do tags persist if the user clears browser data?
No. Clearing browser data creates a new Subscription. If the user re-subscribes (manually or via auto-resubscribe), thechange listener fires again and re-applies the tags based on the current page.
Can I update tags after the initial subscription?
Yes. You can callOneSignal.User.addTags() at any time to add or update tags. The subscription listener is useful for the initial context, but you can also tag users based on ongoing behavior.
Related pages
Tags
Set custom key-value pairs on users based on events or properties.
Web SDK reference
Full reference for the OneSignal Web SDK including subscription listeners and tagging methods.
Segments
Group users by properties, tags, and behavior for targeted messaging.
Journeys
Build multi-step messaging workflows triggered by segment entry or custom events.