OneSignal
This guide describes how to add and configure OneSignal integration.
About Integration
Apphud can update User Tags in OneSignal. Tags are key-value attributes that allow you to target specific users or groups using Segments and send personalized messages with Tag Substitution.
How to Add Integration?
Step 1
- Integrate Apphud SDK on iOS or Android.
- Integrate OneSignal.
- Match User IDs between OneSignal and Apphud.
Step 2
At Apphud go to "Integrations" section and add OneSignal:
Step 3
Enter Application ID , Sandbox Application ID (optional) and REST API Key (optional):
REST API Key is a new optional field which is required if you use latest OneSignal SDKs and enabled Identity Verification in the Keys & IDs in OneSignal app settings.
Step 4
Enable Advanced Data Tags only if your OneSignal plan allows that:
Step 4
You can enter your custom event names or disable some:
Step 5
Enable integration and click Save:
Match User IDs
You should set Apphud User ID property to OneSignal's externalUserID
property:
// assuming both Apphud and OneSignal SDKs are initialized:
OneSignal.login(Apphud.userID())
// assuming both Apphud and OneSignal SDKs are initialized:
[OneSignal login:Apphud.userID];
// assuming both Apphud and OneSignal SDKs are initialized:
OneSignal.login(Apphud.userID())
// assuming both Apphud and OneSignal SDKs are initialized:
OneSignal.login(Apphud.userID());
Segment Audience
Use Segment tab in OneSignal dashboard to create custom audience based on User Tags:
In the screenshot above, Premium Users audience is created based on ah_status
User Tag. These conditions describe premium users based on their subscription status.
You can also utilize additional tags, such as ah_spent
. By specifying a condition where ah_spent
is greater than zero, you can target paying users.
These custom audiences can be used in your Push campaigns.
Data Tags
Apphud sends the following payload in each event. Despite default tags, there are advanced tags, which are only being sent when Advanced Tags option is enabled in integration settings.
Default Tags
Key | Description |
---|---|
ah_event | Event Name |
ah_status | Subscription Status. Possible Values: |
JSON example of event with Default Tags:
{
"ah_event": "apphud_subscription_renewed",
"ah_product": "com.product.id"
}
Advanced Tags
Requires Paid OneSignal plan
You should only turn on this option if your OneSignal plan allows sending larger number of Tags.
If you enable Advanced Tags option in One Signal integration page, then additional tags will be sent:
Key | Description |
---|---|
ah_spent | Total amount of money that user has been charged, in USD |
ah_payments | Number of transactions user has been charged |
ah_country | User's App Store Country |
ah_autorenew | Subscription auto-renew state. "1" or "0" |
ah_billing_issue | Whether subscription has billing issue. "1" or "0" |
ah_product | Product ID of the subscription |
JSON example of event with Advanced Tags enabled:
{
"ah_event": "apphud_subscription_renewed",
"ah_product": "com.product.id",
"ah_billing_issue": "0",
"ah_autorenew": "1",
"ah_country": "UK",
"ah_status": "regular",
"ah_spent": "9.99",
"ah_payments": "1"
}
Using both OneSignal and Apphud Push Notifications on iOS
On iOS, if you are using Apphud Rules, you will need incoming push notifications to be handled by either Apphud or OneSignal. However, without necessary changes OneSignal doesn't let notifications go through.
Let Apphud to handle incoming push notifications in OneSignal callback:
OneSignal.setNotificationOpenedHandler { result in
if Apphud.handlePushNotification(apsInfo: result.notification.rawPayload) {
// Push Notification was handled by Apphud, probably do nothing
} else {
// Handle other types of push notifications
}
}
OneSignal.setNotificationWillShowInForegroundHandler { notif, completion in
if Apphud.handlePushNotification(apsInfo: notif.rawPayload) {
// Push Notification was handled by Apphud, probably do nothing
} else {
// Handle other types of push notifications
}
completion(notif)
}
Modify OneSignal's UINotificationServiceExtension
so that it will pass Apphud Notifications through:
UINotificationServiceExtension
so that it will pass Apphud Notifications through:// NotificationService.swift
override func didReceive(_ request: UNNotificationRequest, withContentHandler contentHandler: @escaping (UNNotificationContent) -> Void) {
self.receivedRequest = request;
self.contentHandler = contentHandler
bestAttemptContent = (request.content.mutableCopy() as? UNMutableNotificationContent)
// (!) --> add this line -->
bestAttemptContent?.userInfo.merge(["custom": ["i": NSUUID().uuidString]], uniquingKeysWith: {old, new in return old})
if let bestAttemptContent = bestAttemptContent {
OneSignal.didReceiveNotificationExtensionRequest(self.receivedRequest, with: self.bestAttemptContent)
contentHandler(bestAttemptContent)
}
}
Troubleshooting
I get error with code 401
Make sure you have provided REST API Key and enabled Identity Verification in OneSignal app settings.
I get error with code 404
Make sure you matched users by calling:
OneSignal.login(Apphud.userID())
If nothing helps
Try to update OneSignal SDK to the latest version and try sandbox purchase. If you still experience issues, contact our Support team.
Updated 3 months ago