Skip to content
This repository has been archived by the owner on Mar 22, 2024. It is now read-only.

Add new reserved subscriber attribute $onesignalUserId and add deprecation note to $onesignalId #408

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
class AppDelegate: UIResponder, UIApplicationDelegate, OSSubscriptionObserver {

var window: UIWindow?

func application(_ application: UIApplication,
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {

Purchases.configure(withAPIKey: "<revenuecat_api_key>", appUserID: nil)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we try to not have this in quotes to force users to add the api key since that would fail to compile otherwise:

Suggested change
Purchases.configure(withAPIKey: "<revenuecat_api_key>", appUserID: nil)
Purchases.configure(withAPIKey: <revenuecat_api_key>, appUserID: nil)


OneSignal.initialize("<onesignal_app_id>", withLaunchOptions: launchOptions)
OneSignal.add(self as OSSubscriptionObserver)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this is required since AppDelegate conforms to OSSubscriptionObserver

Suggested change
OneSignal.add(self as OSSubscriptionObserver)
OneSignal.add(self)


// If you've already set up OneSignal, then users should already have
// a OneSignal Id. We can check if it's available and send it to RevenueCat
if let onesignalUserId = OneSignal.User.onesignal_id {
Purchases.shared.attribution.setOnesignalUserID(onesignalUserId)
}

return true
}

// Add this method to update the $onesignalUserId in RevenueCat whenever it changes
// This code should be sufficient to capture all new users if you're setting
// up OneSignal for the first time.
func onOSSubscriptionChanged(_ stateChanges: OSSubscriptionStateChanges!) {
if !stateChanges.from.subscribed && stateChanges.to.subscribed {
// The user is subscribed
// Either the user subscribed for the first time
Purchases.shared.attribution.setOnesignalUserID(stateChanges.to.userId)
}
}
}
70 changes: 36 additions & 34 deletions docs_source/Customers/subscriber-attributes.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,39 +78,40 @@ Attribute keys beginning with `$` are reserved for RevenueCat. The current list

### General

| Key | Description |
| :----------------------- | :----------------------------------------------------------- |
| `$displayName` | Name that should be used to reference the user |
| `$apnsTokens` | Apple push notification tokens for the user. |
| `$fcmTokens` | Google push notification tokens for the user. |
| `$attConsentStatus` | Apple App Tracking Transparency consent status for the user. |
| `$ipAddress` | Ip Address for the user. |
| `$clevertapId ` | Clever Tap ID for the user. |
| `$idfa` | iOS advertising identifier UUID. |
| `$idfv` | iOS vender identifier UUID. |
| `$gpsAdId` | The advertising ID that is provided by Google Play services. |
| `$androidId` | Android device identifier. |
| `$amazonAdId` | Amazon Advertising ID. |
| `$adjustId` | The unique Adjust identifier for the user. |
| `$amplitudeDeviceId` | The Amplitude Device ID. |
| `$amplitudeUserId` | The Amplitude User ID. |
| `$appsflyerId` | Appsflyer Id. The unique Appsflyer identifier for the user. |
| `$brazeAliasName` | The Braze 'alias_name' in User Alias Object. |
| `$brazeAliasLabel` | The Braze 'alias_label' in User Alias Object. |
| `$clevertapId` | The CleverTap ID for the user. |
| `$fbAnonId` | The Facebook Anonymous ID for the user. |
| `$attConsentStatus` | Apple App Tracking Transparency consent status for the user. |
| `$mparticleId` | The unique mParticle user identifier (mpid). |
| `$onesignalId` | The OneSignal Player Id for the user. |
| `$airshipChannelId` | The Airship channel ID for the user. |
| `$iterableUserId` | The Iterable ID for the user. |
| `$iterableCampaignId` | The Iterable campaign ID. |
| `$iterableTemplateId` | The Iterable template ID. |
| `$firebaseAppInstanceId` | The Firebase instance identifier. |
| `$mixpanelDistinctId` | The Mixpanel user identifier. |
| `$ip` | The IP address of the device. |
| `$email` | Email address for the user. |
| `$phoneNumber` | Phone number for the user. |
| Key | Description |
|:-------------------------|:-------------------------------------------------------------------------------|
| `$displayName` | Name that should be used to reference the user |
| `$apnsTokens` | Apple push notification tokens for the user. |
| `$fcmTokens` | Google push notification tokens for the user. |
| `$attConsentStatus` | Apple App Tracking Transparency consent status for the user. |
| `$ipAddress` | Ip Address for the user. |
| `$clevertapId ` | Clever Tap ID for the user. |
| `$idfa` | iOS advertising identifier UUID. |
| `$idfv` | iOS vender identifier UUID. |
| `$gpsAdId` | The advertising ID that is provided by Google Play services. |
| `$androidId` | Android device identifier. |
| `$amazonAdId` | Amazon Advertising ID. |
| `$adjustId` | The unique Adjust identifier for the user. |
| `$amplitudeDeviceId` | The Amplitude Device ID. |
| `$amplitudeUserId` | The Amplitude User ID. |
| `$appsflyerId` | Appsflyer Id. The unique Appsflyer identifier for the user. |
| `$brazeAliasName` | The Braze 'alias_name' in User Alias Object. |
| `$brazeAliasLabel` | The Braze 'alias_label' in User Alias Object. |
| `$clevertapId` | The CleverTap ID for the user. |
| `$fbAnonId` | The Facebook Anonymous ID for the user. |
| `$attConsentStatus` | Apple App Tracking Transparency consent status for the user. |
| `$mparticleId` | The unique mParticle user identifier (mpid). |
| `$onesignalId` | The OneSignal Player Id for the user. Deprecated for OneSignal versions >v9.0. |
| `$onesignalUserId` | The OneSignal User Id for the user. Required with OneSignal versions >=v11.0. |
| `$airshipChannelId` | The Airship channel ID for the user. |
| `$iterableUserId` | The Iterable ID for the user. |
| `$iterableCampaignId` | The Iterable campaign ID. |
| `$iterableTemplateId` | The Iterable template ID. |
| `$firebaseAppInstanceId` | The Firebase instance identifier. |
| `$mixpanelDistinctId` | The Mixpanel user identifier. |
| `$ip` | The IP address of the device. |
| `$email` | Email address for the user. |
| `$phoneNumber` | Phone number for the user. |

> 🚧 attConsentStatus is populated regardless of requesting any permission
>
Expand Down Expand Up @@ -142,7 +143,7 @@ Attribute keys beginning with `$` are reserved for RevenueCat. The current list
### Third-party Identifiers

| Key | Description |
| :----------------------- | :-------------------------------------------------------------------------------------------- |
|:-------------------------|:----------------------------------------------------------------------------------------------|
| `$adjustId` | [Adjust](https://www.adjust.com/) user identifier |
| `$amplitudeDeviceId` | [Amplitude](https://amplitude.com/) device identifier |
| `$amplitudeUserId` | [Amplitude](https://amplitude.com/) user identifier |
Expand All @@ -153,6 +154,7 @@ Attribute keys beginning with `$` are reserved for RevenueCat. The current list
| `$mixpanelDistinctId` | [Mixpanel](https://mixpanel.com) user identifier |
| `$mparticleId` | [mParticle](https://www.mparticle.com/) user identifier |
| `$onesignalId` | [OneSignal](https://onesignal.com/) player identifier |
| `$onesignalUserId` | [OneSignal](https://onesignal.com/) user identifier |
| `$clevertapId` | [CleverTap](https://clevertap.com/) user identifier |
| `$airshipChannelId` | [Airship](https://www.airship.com/) channel identifier |

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,8 @@ The OneSignal integration tracks the following events:

# 1. Send device data to RevenueCat

## OneSignal API versions v9.0 and below (deprecated)

The OneSignal integration requires some device-specific data. RevenueCat will only update users in OneSignal if the below data has been added as [Subscriber Attributes](doc:subscriber-attributes) for the user.

| Key | Description | Required |
Expand All @@ -214,6 +216,27 @@ You can listen for changes to the OneSignal Id through their SDK, and send the v
]
[/block]

## OneSignal API versions v11.0 and above

The OneSignal integration requires some user-specific data. RevenueCat will only update users in OneSignal if the below data has been added as [Subscriber Attributes](doc:subscriber-attributes) for the user.

| Key | Description | Required |
|:-------------------|:---------------------------------------------------------------------------------|:---------|
| `$onesignalUserId` | The [OneSignal ID](https://documentation.onesignal.com/docs/users) for the user. | ✅ |

This property can be set manually, like any other [Subscriber Attributes](doc:subscriber-attributes), or through the helper method `setOnesignalUserID()`.

You can listen for changes to the OneSignal User ID through their SDK, and send the value to RevenueCat. If you already have OneSignal set up, you should make sure that you're also sending the OneSignal ID for users that are updating to the latest version of your app.

[block:file]
[
{
"language": "swift",
"name": "",
"file": "code_blocks/🔌 Integrations & Events/third-party-integrations/onesignal_2.swift"
}
]
[/block]


# 2. Send RevenueCat events into OneSignal
Expand Down