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
Step 2
Step 3
Step 4
Step 5
At Apphud go to "Integrations" section and add OneSignal:
Enter Application ID and Sandbox Application ID (optional):
You can enter your custom event names or disable some:
Enable integration and click Save:

Match User IDs

You should set Apphud User ID property to OneSignal's externalUserID property:
Swift
Objective-C
Kotlin
Java
1
// assuming both Apphud and OneSignal SDKs are initialized:
2
OneSignal.setExternalUserId(Apphud.userID())
Copied!
1
// assuming both Apphud and OneSignal SDKs are initialized:
2
[OneSignal setExternalUserId:Apphud.userID];
Copied!
1
// assuming both Apphud and OneSignal SDKs are initialized:
2
OneSignal.setExternalUserId(Apphud.userID())
Copied!
1
// assuming both Apphud and OneSignal SDKs are initialized:
2
OneSignal.setExternalUserId(Apphud.userID());
Copied!

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:
trial, intro, regular, promo, refunded, expired, grace
JSON example of event with Default Tags:
1
{
2
"ah_event": "apphud_subscription_renewed",
3
"ah_product": "com.product.id"
4
}
Copied!

Advanced 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:
1
{
2
"ah_event": "apphud_subscription_renewed",
3
"ah_product": "com.product.id",
4
"ah_billing_issue": "0",
5
"ah_autorenew": "1",
6
"ah_country": "UK",
7
"ah_status": "regular",
8
"ah_spent": "9.99",
9
"ah_payments": "1"
10
}
Copied!

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:

1
OneSignal.setNotificationOpenedHandler { result in
2
if Apphud.handlePushNotification(apsInfo: result.notification.rawPayload) {
3
// Push Notification was handled by Apphud, probably do nothing
4
} else {
5
// Handle other types of push notifications
6
}
7
}
8
OneSignal.setNotificationWillShowInForegroundHandler { notif, completion in
9
if Apphud.handlePushNotification(apsInfo: notif.rawPayload) {
10
// Push Notification was handled by Apphud, probably do nothing
11
} else {
12
// Handle other types of push notifications
13
}
14
completion(notif)
15
}
Copied!

Modify OneSignal's UINotificationServiceExtension so that it will pass Apphud Notifications through:

// NotificationService.swift
1
override func didReceive(_ request: UNNotificationRequest, withContentHandler contentHandler: @escaping (UNNotificationContent) -> Void) {
2
self.receivedRequest = request;
3
self.contentHandler = contentHandler
4
bestAttemptContent = (request.content.mutableCopy() as? UNMutableNotificationContent)
5
6
// (!) --> add this line -->
7
bestAttemptContent?.userInfo.merge(["custom": ["i": NSUUID().uuidString]], uniquingKeysWith: {old, new in return old})
8
9
if let bestAttemptContent = bestAttemptContent {
10
OneSignal.didReceiveNotificationExtensionRequest(self.receivedRequest, with: self.bestAttemptContent)
11
contentHandler(bestAttemptContent)
12
}
13
}
Copied!
Last modified 6mo ago