Unity SDK basic integration guide
This guide walks you through integrating the Pushwoosh Unity SDK into your application.
Prerequisites
Anchor link toIntegration steps
Anchor link to1. Add Pushwoosh Unity SDK
Anchor link toAdd the following to your Packages/manifest.json:
{ "dependencies": { "com.pushwoosh.unity.core": "6.2.7", "com.pushwoosh.unity.android": "6.2.7", "com.pushwoosh.unity.ios": "6.2.7" }, "scopedRegistries": [ { "name": "npmjs", "url": "https://registry.npmjs.org", "scopes": ["com.pushwoosh"] } ]}Add only the platform packages you need. For example, omit com.pushwoosh.unity.android if you only target iOS.
In Unity, go to Window > Package Manager > + > Add package from git URL and add the following URLs one by one:
https://github.com/Pushwoosh/pushwoosh-unity.git?path=com.pushwoosh.unity.corehttps://github.com/Pushwoosh/pushwoosh-unity.git?path=com.pushwoosh.unity.androidhttps://github.com/Pushwoosh/pushwoosh-unity.git?path=com.pushwoosh.unity.iosDownload Pushwoosh.unitypackage from GitHub Releases and import via Assets > Import Package > Custom Package.
2. Install External Dependency Manager
Anchor link toThe SDK requires External Dependency Manager for Unity (EDM4U) to resolve native Android and iOS dependencies.
Add the following scoped registry to your Packages/manifest.json:
{ "scopedRegistries": [ { "name": "package.openupm.com", "url": "https://package.openupm.com", "scopes": ["com.google.external-dependency-manager"] } ]}Then add the package to your dependencies:
"com.google.external-dependency-manager": "1.2.183"3. Initialize the SDK
Anchor link toCreate a PushNotificator.cs script and attach it to any GameObject in the scene:
using UnityEngine;using System.Collections.Generic;
public class PushNotificator : MonoBehaviour{ void Start() { Pushwoosh.ApplicationCode = "XXXXX-XXXXX"; Pushwoosh.FcmProjectNumber = "XXXXXXXXXXXX";
Pushwoosh.Instance.OnRegisteredForPushNotifications += (token) => { Debug.Log("Push token: " + token); };
Pushwoosh.Instance.OnFailedToRegisteredForPushNotifications += (error) => { Debug.Log("Registration failed: " + error); };
Pushwoosh.Instance.RegisterForPushNotifications(); }}Replace:
XXXXX-XXXXXwith your Pushwoosh Application Code.XXXXXXXXXXXXwith your Firebase project number (Android only).
4. iOS native setup
Anchor link to4.1 Capabilities
Anchor link toAfter building the iOS project from Unity, open the generated Xcode project and add the following capabilities in Signing & Capabilities:
- Push Notifications
- Background Modes with Remote notifications checked
For Time Sensitive Notifications (iOS 15+), also add the Time Sensitive Notifications capability.
4.2 Info.plist
Anchor link toAdd the Pushwoosh Device API Token to your Info.plist:
<key>Pushwoosh_API_TOKEN</key><string>__PUSHWOOSH_DEVICE_API_TOKEN__</string>4.3 Message delivery tracking
Anchor link toAdd a Notification Service Extension target to your Xcode project. This is required for accurate delivery tracking and Rich Media on iOS.
Follow the native guide to add the extension target.
5. Android native setup
Anchor link to5.1 Add Firebase configuration file
Anchor link toPlace the google-services.json file into your Unity project’s Assets directory.
5.2 Add Pushwoosh metadata
Anchor link toAdd the Pushwoosh Device API Token to your Assets/Plugins/Android/AndroidManifest.xml inside the <application> tag:
<meta-data android:name="com.pushwoosh.apitoken" android:value="__YOUR_DEVICE_API_TOKEN__" />6. Run the project
Anchor link to- Build and run the project on your target platform.
- Grant permission for push notifications when prompted.
- Go to the Pushwoosh Control Panel and send a push notification.
Extended integration
Anchor link toAt this stage, you can send and receive push notifications. The sections below cover the core SDK functionality.
Push notification event listeners
Anchor link toThe SDK provides two event listeners for handling push notifications:
OnPushNotificationsReceived— triggered when a push notification arrivesOnPushNotificationsOpened— triggered when a user taps a notification
Set up these listeners during SDK initialization:
void Start(){ Pushwoosh.ApplicationCode = "XXXXX-XXXXX"; Pushwoosh.FcmProjectNumber = "XXXXXXXXXXXX";
Pushwoosh.Instance.OnPushNotificationsReceived += (payload) => { Debug.Log("Push received: " + payload); };
Pushwoosh.Instance.OnPushNotificationsOpened += (payload) => { Debug.Log("Push opened: " + payload); };
Pushwoosh.Instance.RegisterForPushNotifications();}User configuration
Anchor link toPersonalize push notifications by identifying users and setting their properties:
// Set user ID for cross-device trackingPushwoosh.Instance.SetUserId("user-123");
// Set user emailPushwoosh.Instance.SetEmail("user@example.com");
// Set user with both ID and emailPushwoosh.Instance.SetUser("user-123", new List<string> { "user@example.com" });
// Set preferred languagePushwoosh.Instance.SetLanguage("en");Tags
Anchor link toTags are key-value pairs assigned to devices, enabling user segmentation and targeted messaging:
// String tagPushwoosh.Instance.SetStringTag("favorite_category", "electronics");
// Integer tagPushwoosh.Instance.SetIntTag("purchase_count", 5);
// List tagPushwoosh.Instance.SetListTag("interests", new List<object> { "sports", "music", "tech" });
// Get all tagsPushwoosh.Instance.GetTags((tags, error) => { if (error != null) { Debug.Log("Error: " + error.Message); return; } foreach (var tag in tags) { Debug.Log(tag.Key + ": " + tag.Value); }});Events
Anchor link toTrack user actions to analyze behavior and trigger automated messages:
// Track a login eventPushwoosh.Instance.PostEvent("login", new Dictionary<string, object> { { "username", "user-123" }, { "login_type", "email" }});
// Track a purchase eventPushwoosh.Instance.PostEvent("purchase", new Dictionary<string, object> { { "product_id", "SKU-001" }, { "price", 29.99 }, { "currency", "USD" }});Communication preferences
Anchor link toAllow users to opt in or out of push notifications programmatically:
// Enable communicationPushwoosh.Instance.SetCommunicationEnabled(true);
// Disable communicationPushwoosh.Instance.SetCommunicationEnabled(false);
// Check current statebool isEnabled = Pushwoosh.Instance.IsCommunicationEnabled();Badge management
Anchor link toControl the app badge number on supported platforms:
// Set badge to a specific numberPushwoosh.Instance.SetBadgeNumber(3);
// Increment badgePushwoosh.Instance.AddBadgeNumber(1);
// Clear badgePushwoosh.Instance.SetBadgeNumber(0);Troubleshooting
Anchor link toIf you encounter any issues during the integration process, refer to the support and community section.