Genel Bakış
Bu kılavuz, OneSignal push bildirimlerinin bir Vue.js uygulamasına nasıl entegre edileceğini açıklar. Resmi OneSignal Vue eklentilerini kullanarak hem Vue 2 hem de Vue 3’ü kapsar ve service worker yapılandırması ve TypeScript desteği dahil olmak üzere temel kurulum hususlarını içerir.Gereksinimler
- Yapılandırılmış OneSignal uygulaması ve platformu. Başlamak için Web Push Kurulumu’na bakın.
Vue Uyumluluğu
Vue ortamınızla uyumlu bir eklenti sürümü yüklediğinizden emin olun.| Vue | OneSignal Plugin |
|---|---|
| 2 | onesignal-vue |
| 3 | onesignal-vue3 |
Kurulum
Tercih ettiğiniz paket yöneticisi aracılığıyla yükleyin:Başlatma
OneSignal hizmetini içe aktarın ve kök bileşeninizde başlatın.init fonksiyonu, OneSignal yüklendiğinde çözümlenen bir promise döndürür.
YOUR_APP_ID’yi Keys & IDs’de bulunan OneSignal uygulama ID’nizle değiştirin.
$OneSignal global özelliğini otomatik olarak açığa çıkarır.
Composition API
setup içinden çağrılabilen useOneSignal() hook’u aracılığıyla Vue’nun Composition API’sinden de yararlanabilirsiniz.
init seçeneklerini özelleştirme
Ekinit parametreleri ile başlatmanızı özelleştirebilirsiniz.
Service Worker Ayarları
Henüz yapmadıysanız, sitenize eklemek için OneSignal Service Worker dosyasını indirmeniz gerekecektir.OneSignalSDKWorker.js dosyası herkese açık olmalıdır. Bunu public dizininize, üst düzey root’a veya bir alt dizine koyabilirsiniz. Ancak, dosyayı bir alt dizine yerleştiriyorsanız ve/veya siteniz için başka bir service worker’ınız varsa, yolu belirttiğinizden emin olun. Ayrıntılar için OneSignal Service Worker’a bakın.
| Seçenek | Açıklama |
|---|---|
serviceWorkerParam | OneSignal worker tarafından kontrol edilen kapsam. Öneri: Özel bir alt yol kullanın (örneğin, "/onesignal/"). |
serviceWorkerPath | Barındırılan OneSignal service worker dosyanızın yolu (örneğin, "onesignal/OneSignalSDKWorker.js"). Herkese açık olmalıdır. |
Worker’ı barındırma
- Public root (varsayılan):
/OneSignalSDKWorker.js - Özel klasör (önerilen): örneğin, önceki adımda ayarlandığı gibi
/onesignal/OneSignalSDKWorker.js.
Service worker barındırmasını doğrulama
Erişilebilir olduğunu doğrulamak için tarayıcınızda yolu ziyaret edin. Root kullandıysanız:Önemli notlar
- Geliştirmede Yinelenen Başlatmadan Kaçının
- Bir geliştirme ortamında test ederken, OneSignal SDK’sının iki kez başlatıldığını görebilirsiniz ve bu konsol hatalarına neden olabilir.
- Bu,
<React.StrictMode>’un geliştirmede efektlerin iki kez çalışmasına neden olmasından kaynaklanır. Bunu çözmek için, geliştirme sırasında kök bileşeninizden<React.StrictMode>’u kaldırın.
Testing the OneSignal SDK integration
This guide helps you verify that your OneSignal SDK integration is working correctly by testing push notifications and subscription registration.Check web push subscriptions
Launch your site on a test device.
- Use Chrome, Firefox, Edge, or Safari while testing.
- Do not use Incognito or private browsing mode. Users cannot subscribe to push notifications in these modes.
- The prompts should appear based on your permission prompts configuration.
- Click Allow on the native prompt to subscribe to push notifications.

Check your OneSignal dashboard
- Go to Audience > Subscriptions.
- You should see a new entry with the status Subscribed.

You have successfully created a web push subscription.
Web push subscriptions are created when users first subscribe to push notifications on your site.
Set up test subscriptions
Test subscriptions are helpful for testing a push notification before sending a message.Add to Test Subscriptions.
In the dashboard, next to the subscription, click the Options (three dots) button and select Add to Test Subscriptions.

Name your subscription.
Name the subscription so you can easily identify your device later in the Test Subscriptions tab.
Name the segment.
Name the segment
Test Users (the name is important because it will be used later).Send test push via API
Get your App API Key and App ID.
In your OneSignal dashboard, go to Settings > Keys & IDs.
Update the provided code.
Replace
YOUR_APP_API_KEY and YOUR_APP_ID in the code below with your actual keys. This code uses the Test Users segment created earlier.Check images and confirmed delivery.
If all setup steps were completed successfully, the test subscriptions should receive a notification.

Check for confirmed delivery.
In your dashboard, go to Delivery > Sent Messages, then click the message to view stats. You should see the confirmed stat, meaning the device received the push.
Safari does not support Confirmed Delivery.
Push notification message reports
View delivery, click, and conversion stats for your push notifications.
You have successfully sent a notification via the API to a segment.
support@onesignal.com with the following:
- The API request and response (copy-paste into a
.txtfile) - Your Subscription ID
- Your website URL with the OneSignal code
User identification
The previous section covered creating web push Subscriptions. This section expands to identifying Users across all their subscriptions (including push, email, and SMS) using the OneSignal SDK. It covers External IDs, tags, multi-channel subscriptions, privacy, and event tracking to help you unify and engage users across platforms.Assign External ID
Use an External ID to identify users consistently across devices, email addresses, and phone numbers using your backend’s user identifier. This ensures your messaging stays unified across channels and 3rd party systems (especially important for Integrations). Set the External ID with the SDK’slogin method each time a user is identified by your app.
OneSignal generates unique read-only IDs for subscriptions (Subscription ID) and users (OneSignal ID).As users download your app on different devices, subscribe to your website, and/or provide you email addresses and phone numbers outside of your app, new subscriptions will be created.Setting the External ID via the SDK is highly recommended to identify users across all their subscriptions, regardless of how they are created.
Add data tags
Tags are key-value pairs of string data you can use to store user properties (likeusername, role, or preferences) and events (like purchase_date, game_level, or user interactions). Tags power advanced Message Personalization and Segmentation allowing for more advanced use cases.
Set tags with the SDK’s addTag and addTags methods as events occur in your app.
In this example, the user reached level 6 identifiable by the tag called current_level set to a value of 6.



Add email and/or SMS subscriptions
The OneSignal SDK creates web push subscriptions automatically when users opt in. You can also reach users through email and SMS channels by creating the corresponding subscriptions.- Use the
addEmailmethod to create email subscriptions. - Use the
addSmsmethod to create SMS subscriptions.

Best practices for multi-channel communication
- Obtain explicit consent before adding email or SMS subscriptions.
- Explain the benefits of each communication channel to users.
- Provide channel preferences so users can select which channels they prefer.
Privacy & user consent
To control when OneSignal collects user data, use the SDK’s consent gating methods:setConsentRequired(true): Prevents data collection until consent is given.setConsentGiven(true): Enables data collection once consent is granted.
Data collected by the SDK
Review what data the OneSignal SDK collects from users.
Handling personal data
Manage and protect user data in compliance with privacy regulations.
Listen to push, user, and in-app events
Use SDK listeners to react to user actions and state changes. The SDK provides several event listeners you can hook into. See the SDK reference guide for more details.Push notification events
- Click event listener: Detect when a notification is tapped.
- Foreground lifecycle listener: Control how notifications behave in foreground.
User state changes
- User state change event listener: Detect when the External ID is set.
- Permission observer: Track the user’s specific interaction with the native push permission prompt.
- Push subscription change observer: Track when the push subscription status changes.
Advanced setup & capabilities
Explore more capabilities to enhance your integration:Migrating to OneSignal
Move from another push provider to OneSignal.
Integrations
Connect OneSignal with third-party tools and platforms.
Action buttons
Add interactive buttons to push notifications.
Multi-language messaging
Send localized messages to users in their preferred language.
Identity Verification
Secure your SDK integration with server-side identity verification.
Custom Outcomes
Track custom conversion events tied to your messages.
Web SDK setup & reference
Web push setup
Enable all key web push features for your integration.
Web SDK reference
Full details on available methods and configuration options.
Congratulations! You’ve successfully completed the Web SDK setup guide.
Need help?Chat with our Support team or email
support@onesignal.comPlease include:- Details of the issue you’re experiencing and steps to reproduce if available
- Your OneSignal App ID
- The External ID or Subscription ID if applicable
- The URL to the message you tested in the OneSignal Dashboard if applicable
- Any relevant logs or error messages
