Guides
GuidesLog In
Guides

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

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_statusUser 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

KeyDescription
ah_eventEvent Name
ah_status

Subscription Status. Possible Values:

trial, intro, regular, promo, refunded, expired, grace

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:

KeyDescription
ah_spentTotal amount of money that user has been charged, in USD
ah_paymentsNumber of transactions user has been charged
ah_countryUser's App Store Country
ah_autorenewSubscription auto-renew state. "1" or "0"
ah_billing_issueWhether subscription has billing issue. "1" or "0"
ah_productProduct 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:

// 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.